Warning
PROJECT IS IN DEVELOPMENT, SOME FEAUTRES ARE INCOMPLETE AND ARE NOT YET TESTED.
A simple NestJS backend API for uploading, processing, and organizing files with background jobs and PostgreSQL.
Client ──> NestJS API (Auth / Routes) ──> PostgreSQL (Data & Users)
│
└──> BullMQ + Redis ──> Background Processing (SHA-256 / Metadata)
- Framework: NestJS (TypeScript)
- Database & ORM: PostgreSQL (temporarily SQLite) + Drizzle
- Queue & Cache: BullMQ + Redis
- Auth: Passport.js + JWT
Requirements: Node.js 20+, npm, and Redis (or Docker).
- Clone & install:
git clone https://github.com/jyn626/file-processing-api.git
cd file-processing-api
npm install- Start Redis (BullMQ connects to
localhost:6379):
docker run -d --name redis -p 6379:6379 redis- Start the server:
npm run start:devThe API runs on http://localhost:3000 (override with the PORT env var). The SQLite database (sqlite.db) is created and migrated automatically on startup, and uploads are saved to ./uploads.
- Try it out:
# register (returns an access_token)
curl -X POST http://localhost:3000/auth/sign-up \
-H "Content-Type: application/json" \
-d '{"username":"demo","password":"secret"}'
# upload a file (use the access_token from above)
curl -X POST http://localhost:3000/files \
-H "Authorization: Bearer <access_token>" \
-F "file=@./test-files/fIeYumGSYp4MQlIlU.gif"
# check the processing job, then list your files
curl http://localhost:3000/jobs/<jobId>
curl http://localhost:3000/files -H "Authorization: Bearer <access_token>"Other scripts
| Command | Description |
|---|---|
npm run build |
Compile to dist/ |
npm run start:prod |
Run the compiled build |
npm test |
Unit tests (Jest) |
npm run test:e2e |
End-to-end tests |
npx drizzle-kit generate |
Generate a migration after editing src/db/schema.ts |
Note
The JWT secret is currently hardcoded in src/auth/constants.ts and the Redis host/port in src/app.module.ts. Move both to config before deploying.
All responses are wrapped by a global interceptor as { "success": true, "data": ... }.
Protected routes need an Authorization: Bearer <access_token> header (tokens expire after 1 hour).
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/auth/sign-up |
Register. Body: { username, password }. Returns access_token (409 if the username exists) |
No |
POST |
/auth/sign-in |
Log in. Body: { username, password }. Returns access_token |
No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
GET |
/users/me |
Current user (id, username) |
Yes |
GET |
/users |
List all users | No (temporary) |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
POST |
/files |
Upload a file (multipart/form-data, field file). Returns 202 with { message, jobId, fileId, status } and queues hashing, metadata extraction, and categorization |
Yes |
GET |
/files |
List your files with metadata, newest first. See query params below | Yes |
GET |
/files/:id |
Get one file | Yes (owner) |
DELETE |
/files/:id |
Delete a file record. Returns 204 |
Yes |
GET |
/files/:id/analyze |
Read the file's metadata (size, MIME, etc.) | Yes (owner) |
POST |
/files/:id/hash |
Compute and store the file's SHA-256 | Yes (owner) |
POST |
/files/:id/category/override |
Set the category manually. Body: { category } |
Yes |
GET |
/files/jobs |
List all processing jobs (temporary, for testing) | Yes |
GET |
/files/test |
Test route, returns hello |
No |
GET /files query params
| Param | Description |
|---|---|
filename |
Exact filename match (returns a single file, other params ignored) |
category |
Document, Image, Video, Audio, or Others |
extension |
File extension, including the dot (e.g. .png) |
limit, offset |
Offset pagination (applied only when limit is below 20; offset requires limit) |
minSize, maxSize |
Size filters (WIP) |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
GET |
/jobs/:id |
Processing status: QUEUED, PROCESSING, COMPLETED, or FAILED |
No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
GET |
/ |
Returns Hello World! |
No |
- Phase 1: Setup — Project creation & basic
/healthroute - Phase 2: Controllers & Services — In-memory files CRUD & DTO validation
- Phase 3: Metadata — File size, MIME, and path extraction service
- Phase 4: Database — PostgreSQL & Drizzle setup with real CRUD
- Phase 5: Uploads — Multer disk storage integration & validation
- Phase 6: Hashing — SHA-256 streaming & duplicate detection
- Phase 7: Categories — Domain rules for file classification
- Phase 8: Search & Filter — Pagination, sorting, and search params
- Phase 9: Auth — JWT authentication & resource ownership
- Phase 10: Pipes & Guards — Global filters, custom decorators, ownership guards
- Phase 11: Queue & Jobs — BullMQ + Redis background processing
- Phase 12: Optimization — Stream performance & memory safety
- Phase 13: Testing — Unit & E2E tests with Jest
- Phase 14: Error Handling — Standardized error responses & retries
- Phase 15: Architecture — Clean module refactoring & Config validation
- Phase 16: Docker — Docker Compose for API, DB, and Redis
- Phase 17: Completion — Swagger docs & final system Polish