A production-ready Node.js backend service for AI-powered document extraction with multi-tenant support, real-time processing, and comprehensive monitoring.
- AI-Powered Extraction: OpenAI GPT-4 integration for intelligent document processing
- Multi-Tenant Architecture: Organization-based data isolation and user management
- Real-Time Processing: WebSocket-based live updates and Redis queue management
- Cloud Storage: AWS S3 integration for scalable file storage
- Authentication & Security: JWT-based auth with bcrypt password hashing
- Database Management: PostgreSQL with automated migrations
- Health Monitoring: Comprehensive health checks and metrics
- Production Ready: Docker containerization with CI/CD pipeline
- Node.js 18+ and npm 8+
- PostgreSQL 15+
- Redis 7+
- AWS S3 bucket
- OpenAI API key
- Docker (optional)
-
Clone the repository
git clone https://github.com/your-org/ai-extractor-backend.git cd ai-extractor-backend -
Install dependencies
npm install
-
Set up environment variables
cp env.example .env # Edit .env with your configuration -
Start dependencies
docker-compose up -d postgres redis
-
Run database migrations
npm run migrate
-
Start the application
# Start API server npm run dev # Start worker (in another terminal) npm run worker:dev
-
Build and run with Docker Compose
docker-compose -f docker-compose.production.yml up -d
-
Or build individual images
# Build API image docker build -t ai-extractor-backend . # Run container docker run -p 3000:3000 --env-file .env ai-extractor-backend
| Variable | Description | Default | Required |
|---|---|---|---|
NODE_ENV |
Environment mode | development |
No |
PORT |
Server port | 3000 |
No |
DB_HOST |
PostgreSQL host | localhost |
Yes |
DB_PORT |
PostgreSQL port | 5432 |
Yes |
DB_NAME |
Database name | ai_extractor |
Yes |
DB_USER |
Database user | postgres |
Yes |
DB_PASSWORD |
Database password | - | Yes |
REDIS_HOST |
Redis host | localhost |
Yes |
REDIS_PORT |
Redis port | 6379 |
Yes |
FLASK_URL |
Flask service URL | http://localhost:5001 |
Yes |
OPENAI_API_KEY |
OpenAI API key | - | Yes |
AWS_REGION |
AWS region | us-east-1 |
Yes |
AWS_ACCESS_KEY_ID |
AWS access key | - | Yes |
AWS_SECRET_ACCESS_KEY |
AWS secret key | - | Yes |
S3_BUCKET_NAME |
S3 bucket name | - | Yes |
JWT_SECRET |
JWT signing secret | - | Yes |
API_KEY |
API access key | - | Yes |
The application uses PostgreSQL with the following main tables:
users- User accounts and authenticationorganizations- Multi-tenant organization datauser_organization_memberships- User-organization relationshipsjobs- Document processing jobsjob_files- Individual files within jobsuser_sessions- Active user sessionsaudit_logs- Security and activity logging
POST /auth/register- User registrationPOST /auth/login- User loginPOST /auth/logout- User logoutPOST /auth/refresh- Token refresh
GET /organizations- List user organizationsPOST /organizations- Create organizationGET /organizations/:id/members- List organization members
GET /jobs- List user jobsPOST /jobs- Create new jobGET /jobs/:id- Get job detailsPOST /jobs/:id/files- Add files to job
GET /health- Health checkGET /ready- Readiness probeGET /live- Liveness probe
- File Upload: Users upload documents via API
- S3 Storage: Files stored in AWS S3 with unique keys
- Queue Processing: Files added to Redis queue for processing
- Text Extraction: Flask service extracts text using Google Document AI
- AI Processing: OpenAI processes extracted text with user schema
- Real-Time Updates: WebSocket events notify frontend of progress
- Result Storage: Structured data stored in PostgreSQL
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β API Server β β Worker β
β (Next.js) βββββΊβ (Express) βββββΊβ (Node.js) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β PostgreSQL β β Flask Service β
β Database β β (PDF Extract) β
βββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β Redis Queue β
β & Cache β
βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β AWS S3 β
β File Storage β
βββββββββββββββββββ
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage- Health:
GET /health- Comprehensive service health - Readiness:
GET /ready- Service readiness for traffic - Liveness:
GET /live- Service liveness check
- Structured JSON logging with Pino
- Log levels:
error,warn,info,debug - Request/response logging middleware
- Error tracking and alerting
- Request duration and count
- Database connection pool status
- Redis queue metrics
- Worker processing statistics
- Environment variables configured
- Database migrations applied
- SSL certificates installed
- Monitoring and alerting set up
- Backup strategy implemented
- Security scanning completed
- Load testing performed
- Horizontal Scaling: Multiple API server instances behind load balancer
- Worker Scaling: Multiple worker processes for queue processing
- Database: Read replicas for read-heavy operations
- Redis: Redis Cluster for high availability
- Storage: S3 with CloudFront CDN for global distribution
- JWT-based authentication with refresh tokens
- Password hashing with bcrypt
- Rate limiting and request validation
- CORS configuration for production domains
- Helmet.js security headers
- Input sanitization and validation
- SQL injection prevention
- XSS protection
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Wiki
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- PDF Extractor Service - Flask microservice for PDF processing
- Document Extractor Frontend - Next.js web application