Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“„ Document Summarizer API

An AI-powered document processing API that automatically extracts and summarizes content from PDF and Word documents using advanced language models.

Node.js Express MongoDB MinIO


🎯 Overview

This API provides intelligent document management with automatic text extraction from PDFs and AI-powered summarization. Users can upload documents, extract text content, and generate comprehensive summaries highlighting key points, main arguments, and actionable insights.

Key Features

  • Document Upload & Processing - Support for PDF, DOC, and DOCX files (up to 5MB)
  • AI-Powered Summarization - Structured summaries using OpenRouter AI (Mistral DevStral model)
  • Secure Storage - Documents stored in MinIO, metadata in MongoDB
  • User Authentication - JWT-based authentication with bcrypt password hashing
  • Batch Operations - Bulk document deletion support

πŸ› οΈ Tech Stack

  • Backend: Node.js, Express.js
  • Database: MongoDB with Mongoose ODM
  • Storage: MinIO object storage
  • AI: OpenRouter API (Mistral DevStral)
  • File Processing: pdf2json, multer
  • Auth: JWT, bcrypt
  • Other: Axios, UUID

πŸš€ Getting Started

Prerequisites

Node.js 16+
MongoDB 9+
MinIO Server
OpenRouter API Key

Installation

  1. Clone and install dependencies
git clone <repository-url>
cd document-summarizer
npm install
  1. Configure environment

Create .env.development.local:

PORT=3000
DB_URI=mongodb://localhost:27017/document-summarizer
JWT_SECRET=your-super-secure-secret-minimum-32-chars
JWT_EXPIRES_IN=7d

MINIO_ENDPOINT=localhost
MINIO_PORT=9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin

OPENROUTER_API_KEY=your-openrouter-api-key
  1. Setup MinIO
  1. Run the application
npm run start:dev  # Development mode
npm start          # Production mode

πŸ“š API Documentation

Base URL: http://localhost:3000/api/v1

Authentication: Include JWT token in header: Authorization: Bearer <token>

Authentication

Register User

POST /auth/signup
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

Login

POST /auth/signin
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "password123"
}

Response includes token for authenticated requests.

Document Management

Upload Document

POST /document/upload
Authorization: Bearer <token>
Content-Type: multipart/form-data

document: <file>

Supports: PDF, DOC, DOCX (max 5MB)

Get All Documents

GET /document/all
Authorization: Bearer <token>

Get Document by ID

GET /document/:id
Authorization: Bearer <token>

Analyze Document (Generate Summary)

POST /document/:id/analyse
Authorization: Bearer <token>

Sends extracted text to AI and returns structured summary.

Delete Document

DELETE /document/:id
Authorization: Bearer <token>

Delete Multiple Documents

POST /document/delete-multiple
Authorization: Bearer <token>
Content-Type: application/json

{
  "documentIds": ["id1", "id2", "id3"]
}

πŸ’Ύ Database Schema

User

{
  _id: UUID,
  email: String (unique, validated),
  password: String (bcrypt hashed),
  createdAt: Date,
  updatedAt: Date
}

Document

{
  _id: ObjectId,
  user: UUID (ref: User),
  filename: String,
  file_type: String ('.pdf', '.doc', '.docx'),
  file_size: Number (MB),
  status: String ('uploaded', 'processing', 'completed', 'failed'),
  raw_text: String,
  summary: String,
  document_type: String ('invoice', 'cv', 'report', 'letter', 'unknown'),
  metadata: Mixed,
  createdAt: Date,
  updatedAt: Date
}

πŸ”’ Security

  • Password Hashing: bcrypt with 10 salt rounds
  • JWT Authentication: Secure token-based auth with configurable expiration
  • File Validation: Type, size, and MIME type checking
  • Ownership Checks: Users can only access their own documents
  • Environment Variables: Sensitive data stored in .env files

πŸ“ Project Structure

document-summarizer/
β”œβ”€β”€ app.js                          # Main application entry
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ env.js                      # Environment configuration
β”‚   β”œβ”€β”€ model.js                    # AI integration (OpenRouter)
β”‚   └── multer.js                   # File upload configuration
β”œβ”€β”€ controller/
β”‚   β”œβ”€β”€ auth.controller.js          # Authentication logic
β”‚   └── document.controller.js      # Document CRUD & processing
β”œβ”€β”€ database/
β”‚   └── db.js                       # MongoDB connection
β”œβ”€β”€ middlewares/
β”‚   β”œβ”€β”€ auth.middleware.js          # JWT authentication
β”‚   └── fileValidation.middleware.js # File validation
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ user.model.js               # User schema
β”‚   └── document.model.js           # Document schema
β”œβ”€β”€ router/
β”‚   β”œβ”€β”€ auth.router.js              # Auth routes
β”‚   └── document.router.js          # Document routes
└── package.json

πŸ§ͺ Testing

Using cURL

Register:

curl -X POST http://localhost:3000/api/v1/auth/signup \
  -H "Content-Type: application/json" \
  -d '{"email":"test@test.com","password":"test123"}'

Login:

curl -X POST http://localhost:3000/api/v1/auth/signin \
  -H "Content-Type: application/json" \
  -d '{"email":"test@test.com","password":"test123"}'

Upload Document:

curl -X POST http://localhost:3000/api/v1/document/upload \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "document=@/path/to/file.pdf"

Analyze Document:

curl -X POST http://localhost:3000/api/v1/document/DOCUMENT_ID/analyse \
  -H "Authorization: Bearer YOUR_TOKEN"

🚒 Deployment

Environment Setup

Update .env.production.local:

PORT=3000
DB_URI=mongodb+srv://user:pass@cluster.mongodb.net/db
JWT_SECRET=production-secret-min-32-chars
MINIO_ENDPOINT=your-minio-server.com
OPENROUTER_API_KEY=your-api-key

Deployment Platforms

  • Heroku: Set config vars, deploy via Git
  • Railway: Connect GitHub, configure env vars
  • DigitalOcean: Use App Platform with environment variables
  • AWS/GCP: Deploy with Docker or directly on compute instances

Security Checklist

  • Strong JWT_SECRET in production
  • HTTPS/TLS enabled
  • MongoDB authentication enabled
  • MinIO access properly secured
  • CORS configured appropriately
  • Rate limiting implemented
  • Regular security updates

🀝 Contributing

Contributions welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is open source and available under the MIT License.


πŸ—ΊοΈ Roadmap

  • Add support for more file formats (TXT, RTF, etc.)
  • Implement DOC/DOCX text extraction
  • Add document classification (invoice, CV, report, etc.)
  • Email notifications for completed analyses
  • Batch upload support
  • Search functionality across documents
  • Export summaries to PDF/DOCX
  • Multi-language support
  • Real-time processing status via WebSockets

πŸ“ž Contact

For questions or support, please open an issue in the repository.


Built with ❀️ using Node.js, Express, MongoDB, MinIO, and AI

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages