Skip to content

User-Document-Management System - Modular Nest Js Backend. This is a production-ready NestJS backend application for user and document management.

Notifications You must be signed in to change notification settings

Jayakrishnan-mk/User-Doc-Management-NEST-JS

Repository files navigation

User and Document Management - Nest Js.

Overview

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

Features

  • 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

Getting Started

Prerequisites

  • Docker and Docker Compose
  • Node.js (v18+ recommended)
  • PostgreSQL

Installation

npm install

Environment Setup

Create a .env file in the project root from the example:

cp .env.example .env

Edit .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

Running the App (Local Development)

npm run start:dev

Running the App (Docker)

  1. Build and run containers:
docker-compose up --build
  1. Access the application at http://localhost:3000

  2. To stop the containers:

docker-compose down

Running Tests

  • Unit tests:
    npm run test
  • e2e tests:
    npm run test:e2e

Database Migration

If using TypeORM migrations:

npm run typeorm migration:run

Docker Commands

  • 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

API Overview

Auth

  • POST /auth/register — Register user { username, password, role? }
  • POST /auth/login — Login { username, password }{ access_token }

Users

  • 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)

Documents

  • 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)

Ingestion

  • POST /ingestion/trigger — Trigger ingestion { documentId }
  • GET /ingestion/status/:id — Get ingestion status

Roles

  • admin: Full access, can manage users and roles
  • editor: Can manage own documents
  • viewer: Read-only access

File Uploads

Uploaded files are stored in /uploads. File URLs are returned in API responses.

Ingestion

  • Supports OCR (images) and PDF parsing
  • Status tracked per document
  • VirusTotal scan

Testing

  • All modules have unit and e2e tests
  • Run with npm run test and npm run test:e2e

Deployment

  • Dockerfile and docker-compose recommended for production
  • Ensure environment variables are set in production

Postman Collection


For more details, see code comments and tests.

About

User-Document-Management System - Modular Nest Js Backend. This is a production-ready NestJS backend application for user and document management.

Topics

Resources

Stars

Watchers

Forks