How ankit5641/vanco-backend works
1. This repo is an asynchronous document-processing backend, split into two runtime processes: an HTTP API and a background worker. The API accepts uploads and creates jobs; the worker consumes queued jobs and performs text extraction.
2. The main request path starts in src/server.js and src/app.js, then routes under src/routes/. Uploads go through upload.middleware.js before reaching upload.controller.js. Job lookup and deletion go through job.controller.js, with UUID validation in validate.middleware.js.
3. The API is intentionally thin. Controllers orchestrate higher-level flow, while persistence and cloud interactions are pushed into src/models/ and src/services/. That separation is important for the diagram: HTTP layer, application logic, data access, and AWS integrations are distinct boundaries.
4. Job state is stored in PostgreSQL via Prisma. src/prisma/schema.prisma and the migrations define the jobs table, while src/config/database.js provides the Prisma client and src/models/job.model.js centralizes database queries. This database is the source of truth for job status, extracted text, confidence score, and retry metadata.
5. File storage lives in S3. src/services/s3.service.js handles upload, download, and delete operations, so the file binary is not kept in the API or database. The job record stores metadata and the S3 object is the durable document copy.
6. Asynchronous decoupling is handled by SQS. src/jobs/jobQueue.js and src/services/sqs.service.js enqueue work after a successful upload. The API returns 202 Accepted with a jobId immediately, and the worker later polls the queue using long polling.
7. The worker is a separate process under src/worker/worker.js and src/worker/processor.js. It receives a queue message, downloads the file from S3, runs text extraction, updates PostgreSQL, and then acknowledges the SQS message. This is the core “background processing” boundary in the architecture.
8. Text extraction is local, not AWS Textract. Despite the service name src/services/textract.service.js, the README indicates it uses pdf-parse for text-based PDFs and Tesseract.js for images, with sharp preprocessing for better OCR quality. That means extraction happens inside the worker process, not through an external paid API.
9. Notifications and observability are handled by SNS and CloudWatch. src/services/sns.service.js publishes job-completed or failed events, and src/services/cloudwatch.service.js plus src/utils/logger.js provide structured logging. These are side effects of processing, not part of the primary user-facing flow.
10. Configuration is centralized. src/config/env.js validates environment variables, src/config/aws.js builds AWS clients, and src/services/ssm.service.js fetches runtime parameters from AWS SSM Parameter Store. This keeps secrets and deployment-specific values outside application code.
11. Cross-cutting safeguards live in src/utils/. circuitBreaker.js prevents repeated calls into failing dependencies, while helpers.js contains shared utilities like UUID generation and backoff logic. These are supporting concerns around reliability rather than standalone subsystems.
12. Deletion and retrieval are separate from ingestion. GET /api/result/:jobId reads job status and text from PostgreSQL, GET /api/jobs returns lightweight job listings, and DELETE /api/jobs/:jobId removes the S3 object before deleting the database record. That order matters because the file is treated as the durable asset and the database as the index of record.
13. Deployment is containerized with Docker and docker-compose.yml. The compose setup runs PostgreSQL, the API, migrations, and the worker as distinct services, which matches the architecture in code: a web-facing app process, a background consumer, and shared infrastructure services.
14. For an architecture diagram, the essential data flow is: Client → API upload → S3 + PostgreSQL job row → SQS queue → worker → S3 download → OCR/PDF parsing → PostgreSQL update → optional SNS notification → client polls result endpoint. The key boundary is that upload and processing are fully decoupled across two processes and a message queue.
Main entry points: processor.js Processor · aws.js AWS Config · upload.controller.js Upload Ctrl · job.model.js Job Model
Components 23
HTTP API
Request handling and job management
- Server · Process bootstrap for the API
src/server.js - App · Wires middleware, routes, and handlers
src/app.js - Routes · Top-level HTTP routing
src/routes/index.js - Upload MW · Handles request upload parsing
src/middleware/upload.middleware.js - Validate MW · Validates job identifiers and request inputs
src/middleware/validate.middleware.js - Upload Ctrl · Creates jobs from uploaded documents
src/controllers/upload.controller.js - Job Ctrl · Reads and deletes job records
src/controllers/job.controller.js
Worker
Background queue consumer and document processing
Data & Infra
Persistence, messaging, and cloud integrations
- Job Model · Centralized job queries and updates
src/models/job.model.js - Prisma Schema · Job table and relational model
src/prisma/schema.prisma - Database Client · Prisma-backed PostgreSQL connection
src/config/database.js - S3 Service · Uploads, downloads, and deletes document objects
src/services/s3.service.js - SQS Service · Enqueues and receives background work
src/services/sqs.service.js - Job Queue · Application-level enqueue boundary
src/jobs/jobQueue.js - SNS Service · Publishes job completion and failure events
src/services/sns.service.js
Shared Core
Configuration, logging, and cross-cutting utilities
- CloudWatch · Operational logging and metrics sink
src/services/cloudwatch.service.js - Logger · Structured application logging
src/utils/logger.js - Env Config · Validates runtime environment variables
src/config/env.js - AWS Config · Creates AWS clients and shared settings
src/config/aws.js - SSM Service · Loads runtime parameters from Parameter Store
src/services/ssm.service.js - Helpers · Shared utilities such as IDs and backoff
src/utils/helpers.js
Connections 28
- Server → App: starts · Bootstraps the HTTP application
- App → Routes: mounts · Registers route groups
- Routes → Upload MW: upload path · Prepares upload requests
- Routes → Validate MW: validation path · Checks job IDs and request data
- Upload MW → Upload Ctrl: forwards · Passes parsed upload data to controller
- Validate MW → Job Ctrl: guards · Protects job lookup and deletion endpoints
- Upload Ctrl → S3 Service: stores file · Writes document binary to durable object storage
- Upload Ctrl → Job Model: creates job · Persists initial job record
- Job Ctrl → Job Model: reads/writes · Loads status and removes job rows
- Job Model → Database Client: uses · Executes Prisma database operations
- Database Client → Prisma Schema: maps schema · Backed by the Prisma job model
- Upload Ctrl → Job Queue: enqueues · Schedules asynchronous processing
- Job Queue → SQS Service: sends · Pushes work to the queue service
- Worker → Processor: runs · Main background processing loop
- Processor → SQS Service: polls · Receives queued job messages
- Processor → S3 Service: downloads · Fetches source documents for processing
- Processor → Extractor: extracts text · Performs PDF parsing and OCR
- Processor → Job Model: updates status · Writes extracted text and retry metadata
- Processor → SNS Service: publishes event · Emits completion or failure notifications
- SNS Service → CloudWatch: observes · Side-effect telemetry and logging
- CloudWatch → Logger: uses · Structured log emission
- Env Config → AWS Config: feeds · Provides validated configuration
- AWS Config → S3 Service: builds clients · Configures AWS storage access
- AWS Config → SQS Service: builds clients · Configures queue access
- AWS Config → SNS Service: builds clients · Configures notification access
- AWS Config → SSM Service: supports · Shared AWS runtime access
- Helpers → Job Queue: helpers · Supports retry and ID generation
- Helpers → Processor: helpers · Supports backoff and shared logic