Skip to content

A robust, high-performance Node.js API for seamless file management, powered by Fastify, Drizzle ORM, and Cloudflare R2.

Notifications You must be signed in to change notification settings

christopherldo/upload-widget-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

32 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ค Upload Widget Server

A robust, high-performance Node.js API for seamless file management, powered by Fastify, Drizzle ORM, and Cloudflare R2.

TypeScript Fastify PostgreSQL Docker Build Status License


๐Ÿ“– About The Project

Upload Widget Server is a backend solution designed to handle file uploads efficiently and securely. It solves the complexity of managing file storage, metadata, and retrieval by providing a clean API interface that integrates directly with Cloudflare R2 (S3-compatible storage) and PostgreSQL.

Whether you are building a dashboard, a social platform, or a content management system, this server provides the essential plumbing for your media assets.

โœจ Key Features

  • ๐Ÿš€ High-Performance Uploads: Optimized handling of multipart/form-data using Fastify.
  • โ˜๏ธ Cloud Storage Integration: Native support for Cloudflare R2 (via AWS SDK).
  • ๐Ÿ—„๏ธ Robust Data Management: PostgreSQL database with Drizzle ORM for type-safe queries.
  • ๐Ÿ” Advanced Search & Filtering: Built-in pagination, sorting, and text search capabilities.
  • ๐Ÿ“Š Data Export: Generate CSV reports of your uploaded assets on the fly.
  • ๐Ÿ›ก๏ธ Type Safety: End-to-end type validation with Zod and TypeScript.
  • ๐Ÿณ Docker Ready: Containerized environment for easy deployment and development.

๐Ÿ› ๏ธ Tech Stack

Core

  • NodeJS Node.js - Runtime environment
  • TypeScript TypeScript - Static typing
  • Fastify Fastify - Web framework

Data & Storage

  • PostgreSQL PostgreSQL - Relational database
  • Drizzle Drizzle ORM - TypeScript ORM
  • Cloudflare Cloudflare R2 - Object storage

Tools & DevOps

  • Docker Docker - Containerization
  • Zod Zod - Schema validation
  • Vitest Vitest - Testing framework
  • Biome Biome - Linting & Formatting

๐Ÿš€ Getting Started

Follow these steps to get your development environment running in less than 5 minutes.

Prerequisites

  • Node.js (v20+ recommended)
  • pnpm (Package Manager)
  • Docker & Docker Compose

Installation

  1. Clone the repository

    git clone https://github.com/christopherldo/upload-widget-server.git
    cd upload-widget-server
  2. Install dependencies

    pnpm install
  3. Configure Environment Variables Copy the example file and fill in your credentials (especially Cloudflare R2 details).

    cp .env.example .env
  4. Start Database (Docker) Run the PostgreSQL container in the background.

    docker-compose up -d
  5. Run Migrations Apply the database schema.

    pnpm db:migrate

๐ŸŽฎ Usage

Development Server

Start the server in watch mode:

pnpm dev

The server will start at http://localhost:3333.

API Documentation

Access the interactive Swagger/OpenAPI documentation at:

http://localhost:3333/docs

Key Commands

Command Description
pnpm dev Starts the development server with hot-reload
pnpm build Builds the project for production
pnpm test Runs the test suite with Vitest
pnpm db:generate Generates SQL migrations from Drizzle schema
pnpm db:studio Opens Drizzle Studio to view/edit data

Example Request

Upload an Image:

curl -X POST http://localhost:3333/uploads \
  -F "file=@/path/to/your/image.png"

Response (201 Created):

// No content (201)

๐Ÿ“‚ Project Structure

.
โ”œโ”€โ”€ ๐Ÿ“ docker/               # Docker configuration and init scripts
โ”œโ”€โ”€ ๐Ÿ“ src/
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ app/              # Business logic & Use Cases
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ functions/    # Core functionality (upload, get, export)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ infra/            # Infrastructure layer
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ db/           # Database setup (Drizzle schemas, migrations)
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“ http/         # HTTP server (Fastify routes, server setup)
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“ storage/      # Storage implementation (S3/R2 client)
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ shared/           # Shared utilities (Either pattern, types)
โ”‚   โ””โ”€โ”€ ๐Ÿ“„ env.ts            # Environment variable validation
โ”œโ”€โ”€ ๐Ÿ“„ .env.example          # Environment variables template
โ”œโ”€โ”€ ๐Ÿ“„ docker-compose.yml    # Docker services
โ”œโ”€โ”€ ๐Ÿ“„ package.json          # Project dependencies
โ””โ”€โ”€ ๐Ÿ“„ drizzle.config.ts     # Drizzle ORM config

๐Ÿ—บ๏ธ Roadmap

Based on the current codebase, here are some suggested improvements:

  • Authentication: Add JWT or API Key authentication to protect endpoints.
  • File Validation: Expand support for other file types (PDF, Docs) and add virus scanning.
  • CDN Integration: Directly expose public URLs via a configured CDN domain.

Built with โค๏ธ by ChristopherLDO

About

A robust, high-performance Node.js API for seamless file management, powered by Fastify, Drizzle ORM, and Cloudflare R2.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published