A comprehensive NestJS-based backend application for managing passport applications, renewals, appointments, and document processing with advanced OCR capabilities.
- JWT-based Authentication with role-based access control
- Multi-role Support: Admin, Manager, Applicant roles
- Secure Password Hashing using bcrypt
- Protected Routes with guards and decorators
- New Passport Applications with complete form handling
- Application Status Tracking (Pending, Approved, Rejected, etc.)
- Document Upload & Verification with S3 integration
- Application Analytics and reporting dashboards
- Bulk Application Processing for administrators
- Renewal Request Processing for existing passport holders
- Document Validation and verification workflows
- Status Management with automated notifications
- Renewal History tracking and audit trails
- Smart Appointment Scheduling with availability checking
- Location-based Booking for multiple passport offices
- Time Slot Management with conflict prevention
- Appointment Modifications and cancellations
- Calendar Integration with date/time validation
- Advanced OCR Processing for document text extraction
- Multi-format Support (PDF, JPEG, PNG)
- Confidence Scoring for extracted text
- Bounding Box Detection for precise text location
- Automated Data Validation from scanned documents
- Secure File Upload with presigned URLs
- Document Storage with organized folder structure
- File Type Validation and size restrictions
- Automatic Cleanup for failed uploads
- Download URL Generation with expiration
- Application Statistics and trends
- Appointment Analytics and utilization rates
- District-wise Distribution reports
- Daily Application Tracking
- Passport Type Analytics
- Rate Limiting with Throttler guards
- Input Validation with class-validator
- File Upload Security with type and size validation
- CORS Configuration for cross-origin requests
- Error Handling with custom interceptors
- Framework: NestJS (Node.js)
- Database: MongoDB with Mongoose ODM
- Authentication: JWT with Passport.js
- File Storage: AWS S3
- OCR: Google Cloud Document AI
- Validation: class-validator & class-transformer
- Documentation: Swagger/OpenAPI
src/
βββ auth/ # Authentication & authorization
βββ user/ # User management
βββ application/ # Passport applications
βββ appointments/ # Appointment booking
βββ renew-passport/ # Passport renewals
βββ document-ai/ # Google Document AI OCR
βββ s3/ # AWS S3 file management
βββ upload/ # File upload handling
βββ config/ # Configuration management
βββ guards/ # Security guards
βββ interceptors/ # Request/response interceptors
βββ middleware/ # Custom middleware
βββ types/ # TypeScript type definitions
βββ enums/ # Application enums
- Node.js (v18 or higher)
- pnpm package manager
- MongoDB database
- AWS S3 bucket
- Google Cloud Project with Document AI API
git clone <repository-url>
cd passgo-bepnpm installCreate a .env file in the root directory:
# Database Configuration
MONGO_URI=mongodb://localhost:27017/passgo
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-here-make-it-long-and-complex
# Server Configuration
PORT=8080
NODE_ENV=development
# AWS S3 Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your-aws-access-key-id
AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
AWS_S3_BUCKET_NAME=your-s3-bucket-name
# Google Cloud Document AI Configuration
GOOGLE_CLOUD_PROJECT_ID=your-google-cloud-project-id
GOOGLE_CLOUD_LOCATION=us
GOOGLE_CLOUD_PROCESSOR_ID=your-document-ai-processor-id
# Option 1: Using Service Account Key File
GOOGLE_APPLICATION_CREDENTIALS=./google-credentials.json
# Option 2: Using Environment Variables (Alternative to key file)
GOOGLE_CLOUD_CLIENT_EMAIL=your-service-account@project.iam.gserviceaccount.com
GOOGLE_CLOUD_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour-Private-Key-Here\n-----END PRIVATE KEY-----"
# File Upload Configuration
MAX_FILE_SIZE=5242880
ALLOWED_FILE_TYPES=image/jpeg,image/png,image/jpg,application/pdf- Go to Google Cloud Console
- Create a new project or select existing one
- Note your Project ID
# Using gcloud CLI
gcloud services enable documentai.googleapis.com
# Or enable via Console:
# Navigation Menu > APIs & Services > Library > Search "Document AI API" > Enable- Go to Document AI in Google Cloud Console
- Click Create Processor
- Select Document OCR processor type
- Choose your region (e.g.,
us,eu) - Name your processor (e.g., "PassGo OCR Processor")
- Copy the Processor ID from the processor details
# Create service account
gcloud iam service-accounts create passgo-document-ai \
--display-name="PassGo Document AI Service Account"
# Grant necessary permissions
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \
--member="serviceAccount:passgo-document-ai@YOUR_PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/documentai.apiUser"
# Create and download key file
gcloud iam service-accounts keys create google-credentials.json \
--iam-account=passgo-document-ai@YOUR_PROJECT_ID.iam.gserviceaccount.comOption A: Using Key File (Recommended)
- Place
google-credentials.jsonin your project root - Set environment variable:
GOOGLE_APPLICATION_CREDENTIALS=./google-credentials.jsonOption B: Using Environment Variables
- Extract credentials from the JSON file:
GOOGLE_CLOUD_CLIENT_EMAIL=passgo-document-ai@your-project.iam.gserviceaccount.com
GOOGLE_CLOUD_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour-Private-Key-Content\n-----END PRIVATE KEY-----"# Start the application
pnpm run start:dev
# Test OCR endpoint (requires authentication)
curl -X POST http://localhost:8080/document-ai/process \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-F "file=@test-document.pdf"The application supports various document types:
- Identity Documents: NIC, Birth Certificates
- Passport Documents: Current passports, photos
- Supporting Documents: Additional verification docs
pnpm run start:devpnpm run build
pnpm run start:prod- Docker installed on your system
.envfile configured with all required environment variables
# Build the Docker image
docker build -t passgo-be .# Run container with .env file
docker run --rm -p 8080:8080 --env-file .env passgo-be# Run with individual environment variables
docker run --rm -p 8080:8080 \
-e JWT_SECRET=your_jwt_secret \
-e MONGO_URI=mongodb://host.docker.internal:27017/passgo \
-e AWS_REGION=us-east-1 \
-e AWS_ACCESS_KEY_ID=your_access_key \
-e AWS_SECRET_ACCESS_KEY=your_secret_key \
-e AWS_S3_BUCKET_NAME=your_bucket_name \
passgo-beCreate a docker-compose.yml file:
version: '3.8'
services:
passgo-be:
build: .
ports:
- "8080:8080"
env_file:
- .env
depends_on:
- mongodb
restart: unless-stopped
mongodb:
image: mongo:6-alpine
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
environment:
MONGO_INITDB_DATABASE: passgo
restart: unless-stopped
volumes:
mongodb_data:Then run:
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f passgo-be
# Stop services
docker-compose downEnsure your .env file contains:
# Required for Docker deployment
JWT_SECRET=your-super-secret-jwt-key
MONGO_URI=mongodb://mongodb:27017/passgo # Use service name for docker-compose
PORT=8080
# AWS Configuration
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_S3_BUCKET_NAME=your_bucket_name
# Google Cloud Document AI
GOOGLE_CLOUD_PROJECT_ID=your_project_id
GOOGLE_CLOUD_LOCATION=us
GOOGLE_CLOUD_PROCESSOR_ID=your_processor_id
GOOGLE_APPLICATION_CREDENTIALS=./google-credentials.jsonThe container includes a health check endpoint. Check container health:
# Check container status
docker ps
# View health check logs
docker inspect --format='{{.State.Health.Status}}' <container_id>For production deployment:
# Build production image
docker build -t passgo-be:latest .
# Run with restart policy
docker run -d \
--name passgo-backend \
--restart unless-stopped \
-p 8080:8080 \
--env-file .env \
passgo-be:latestPOST /auth/signup # User registration
POST /auth/login # User login
POST /auth/test # Test authentication
POST /application # Create new application
GET /application # Get all applications (Admin)
GET /application/my-applications # Get user's applications
GET /application/:id # Get specific application
PATCH /application/:id # Update application
PATCH /application/:id/status # Update application status
DELETE /application/:id # Delete application
POST /application/upload-document/:type # Upload documents
POST /appointments # Book new appointment
GET /appointments # Get all appointments (Admin)
GET /appointments/my-appointments # Get user's appointments
GET /appointments/available-slots # Check available time slots
PATCH /appointments/:id # Update appointment
DELETE /appointments/:id # Cancel appointment
POST /renew-passport # Create renewal request
GET /renew-passport # Get all renewals (Admin)
GET /renew-passport/my-requests # Get user's renewals
POST /renew-passport/:id/documents # Upload renewal documents
GET /renew-passport/:id/documents # Get document URLs
GET /user/allUsers # Get all users (Admin)
GET /user/find/:id # Find user by ID
DELETE /user/remove/:id # Delete user (Admin)
- JWT Token Expiration and validation
- Role-based Access Control (RBAC)
- Input Validation on all endpoints
- File Upload Restrictions (type, size)
- Rate Limiting on sensitive endpoints
- CORS Configuration for cross-origin requests
- API Rate Limiting with Redis
- Request Logging and monitoring
- Database Connection Encryption
- Environment Variable Encryption
- Regular Security Audits
# Unit tests
pnpm run test
# E2E tests
pnpm run test:e2e
# Test coverage
pnpm run test:covThe application provides comprehensive analytics:
- Application Metrics: Total applications, approval rates
- Appointment Analytics: Booking patterns, utilization
- Geographic Distribution: District-wise statistics
- Performance Metrics: Processing times, success rates
MongoDB Connection Issues
# Check MongoDB status
sudo systemctl status mongod
# Start MongoDB
sudo systemctl start mongodGoogle Document AI Authentication
# Verify credentials
gcloud auth application-default print-access-token
# Test API access
gcloud ai document-processors list --location=usAWS S3 Permission Issues
- Ensure IAM user has
s3:PutObject,s3:GetObject,s3:DeleteObjectpermissions - Verify bucket CORS configuration for web uploads
-
MONGO_URI- MongoDB connection string -
JWT_SECRET- Strong JWT secret key -
AWS_ACCESS_KEY_ID&AWS_SECRET_ACCESS_KEY- AWS credentials -
AWS_S3_BUCKET_NAME- S3 bucket name -
GOOGLE_CLOUD_PROJECT_ID- Google Cloud project -
GOOGLE_CLOUD_PROCESSOR_ID- Document AI processor -
GOOGLE_APPLICATION_CREDENTIALS- Service account key path
For additional support, please create an issue in the repository or contact the development team.