Skip to content

BrijeshVermaDev/document-management-system

Repository files navigation

Document Management System

A NestJS-based backend service for managing users and documents with ingestion capabilities.

Features

  • 🔐 Authentication and Authorization

    • JWT-based authentication
    • Role-based access control (Admin, Editor, Viewer)
    • Rate limiting and security measures
  • 📄 Document Management

    • CRUD operations for documents
    • File upload with validation
    • Role-based access control
    • File type validation
  • 🔄 Ingestion System

    • Document processing pipeline
    • Job management

Prerequisites

  • Node.js (v18 or higher)
  • PostgreSQL (v14 or higher)
  • Redis (v6 or higher)
  • npm or yarn

Environment Variables

Create a .env file in the root directory:

# App Configuration
NODE_ENV=development
PORT=3001

# Throttle
THROTTLE_TTL=60
THROTTLE_LIMIT=10

# Database Connection
DB_DIALECT=postgres
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=postgres

# JWT Configuration
JWT_SECRET=your-secret-key-change-in-production
JWT_EXPIRES_IN=1d

Installation

  1. Clone the repository:
git clone <repository-url>
cd document-management-system
  1. Install dependencies:
npm install
  1. Start the application:
# Development
npm run start:dev

# Production
npm run build

Docker Commands

Quick Start

# Start all services (app, database, redis)
docker-compose up -d

# View logs
docker-compose logs -f

# Stop all services
docker-compose down

Development

# Rebuild and start services
docker-compose up -d --build

# Run commands in the app container
docker-compose exec app npm run <command>

Database

# Run seeds
docker-compose exec app npm run seed:run

# Access database CLI
docker-compose exec db psql -U admin -d jk

API Documentation

Once the application is running, access the Swagger API documentation at:

http://localhost:3000/api/docs

API Endpoints

Authentication

  • POST /api/auth/register - Register a new user
  • POST /api/auth/login - Login user

Users

  • POST /api/users - Create a new users (Admin only)
  • GET /api/users - Get all users (Admin only)
  • GET /api/users/:id - Get user by ID (Admin only)
  • PATCH /api/users/:id - Update user (Admin only)
  • DELETE /api/users/:id - Delete user (Admin only)

Documents

  • POST /api/documents - Upload a new document
  • GET /api/documents - Get all documents
  • GET /api/documents/:id - Get document by ID
  • PATCH /api/documents/:id - Update document
  • DELETE /api/documents/:id - Delete document
  • GET /api/documents/:id/download - Download document

Ingestion

  • POST /api/ingestion - Create ingestion job
  • GET /api/ingestion - Get all ingestion jobs
  • GET /api/ingestion/:id - Get ingestion job by ID

Development

Code Style

# Format code
npm run format

# Lint code
npm run lint

Seed Data

# Seed development data
npm run seed:dev

Project Structure

src/
├── common/           # Common utilities, guards, and decorators
├── config/           # Application configuration
├── database/         # Database configuration and migrations
├── modules/          # Feature modules
│   ├── auth/        # Authentication module
│   ├── users/       # User management module
│   ├── documents/   # Document management module
│   └── ingestion/   # Document ingestion module
├── main.ts          # Application entry point
└── app.module.ts    # Root module

Security

  • JWT-based authentication
  • Role-based access control
  • Rate limiting
  • File type validation
  • Password hashing
  • CORS enabled
  • Helmet security headers

Performance

  • Redis caching
  • Database indexing
  • File streaming
  • Request throttling
  • Connection pooling

Error Handling

  • Centralized error handling
  • Structured logging
  • Request validation
  • Error monitoring

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

This project is licensed under the MIT License.

About

document-management-system

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published