A production-ready, modular NestJS backend for user and document management, featuring:
- Modular architecture (SOLID, best practices)
- DTO validation, error handling, and clear separation of concerns
- JWT authentication and role-based access (admin/editor/viewer)
- PostgreSQL integration via TypeORM
- File upload, document ingestion (OCR/PDF parsing), and status tracking
- VirusTotal integration
- Comprehensive unit and e2e tests
- User Management: Registration, login, CRUD, role management
- Auth: JWT-based, role-based guards, secure endpoints
- Document Management: CRUD, ownership checks, file upload
- Ingestion: Trigger OCR/PDF parsing, status tracking, error handling
- Testing: Unit and e2e tests for all modules
- Docker and Docker Compose
- Node.js (v18+ recommended)
- PostgreSQL
npm installCreate a .env file in the project root from the example:
cp .env.example .envEdit .env and update the following values: PORT=3000
- DB_HOST
- DB_PORT
- DB_USERNAME
- DB_PASSWORD
- DB_DATABASE
- JWT_SECRET
- OCR_SPACE_API_KEY
- VIRUSTOTAL_API_KEY
npm run start:dev- Build and run containers:
docker-compose up --build-
Access the application at http://localhost:3000
-
To stop the containers:
docker-compose down- Unit tests:
npm run test - e2e tests:
npm run test:e2e
If using TypeORM migrations:
npm run typeorm migration:run- Build and run containers:
docker-compose up --build
- Run in detached mode:
docker-compose up -d
- Stop containers:
docker-compose down
- View logs:
docker-compose logs -f
- Run migrations in Docker:
docker-compose exec app npm run typeorm migration:run - Run tests in Docker:
docker-compose exec app npm run test
POST /auth/register— Register user{ username, password, role? }POST /auth/login— Login{ username, password }→{ access_token }
GET /users/:id— Get user profile (auth required)GET /users— List users (auth required)PUT /users/:id— Update user (self or admin)PATCH /users/:id/role— Update user role (admin only)DELETE /users/:id— Delete user (admin only)
POST /documents— Create document (auth required)GET /documents— List documents (auth required)GET /documents/:id— Get document by ID (auth required)PUT /documents/:id— Update document (owner only)DELETE /documents/:id— Delete document (owner only)POST /documents/upload— Upload file (auth required)
POST /ingestion/trigger— Trigger ingestion{ documentId }GET /ingestion/status/:id— Get ingestion status
admin: Full access, can manage users and roleseditor: Can manage own documentsviewer: Read-only access
Uploaded files are stored in /uploads. File URLs are returned in API responses.
- Supports OCR (images) and PDF parsing
- Status tracked per document
- VirusTotal scan
- All modules have unit and e2e tests
- Run with
npm run testandnpm run test:e2e
- Dockerfile and docker-compose recommended for production
- Ensure environment variables are set in production
For more details, see code comments and tests.