How harshitclub/node_scalable_backend works
Project Type & Purpose
• This is a Node.js/TypeScript backend service exposing REST endpoints for user authentication (signup, login, profile) and email verification.
• It uses Prisma for database access/migrations, Redis for caching & job queuing (Bull), and a worker process to send emails asynchronously.
Core Components to Model
a. Clients
– Web/mobile front end or API consumer.
b. API Service (Express.js)
– src/index.ts
– src/routes/auth.routes.ts → src/controllers/auth.controller.ts
– src/middlewares (auth, errorHandler, morgan)
– src/configs (logger, config, mailer, Prisma, RedisBull, RedisCache)
c. Database
– PostgreSQL/MySQL (as defined in prisma/schema.prisma & docker-compose.yml)
– Accessed via Prisma Client
d. Redis
– RedisCache (caching layer)
– RedisBull (job queue for emails)
e. Worker Process
– src/workers/email.worker.ts
– Subscribes to email.queue (src/queues/email.queue.ts)
– Uses src/utils/sendMail.ts & src/templates/verifyEmail.ts
f. External Services
– SMTP/Email provider (via mailer.ts)
Relationships & Data Flow
1) Client → HTTP Request → Express API
2) API Layer
– Authentication routes invoke controllers → business logic
– Controllers use Prisma client → Database
– Controllers push email jobs → RedisBull queue
– Optionally read/write cache → RedisCache
3) Worker
– Polls the RedisBull queue
– Processes jobs (render templates + sendMail) → External SMTP
4) API Response → Client
Key Architectural Patterns
• Monolith + Sidecar Worker: single codebase for API and a separate worker process managed by PM2 (ecosystem.config.js).
• Layered (Router → Controller → Utility/Config → DB/Cache/Queue)
• Asynchronous Queue for non-blocking email dispatch (Bull + Redis).
• Centralized error handling & logging (morgan, custom appError).
• Infrastructure as Code: Dockerfile + docker-compose.yml spin up API, Worker, Redis, Database.
Technologies & Frameworks
• Runtime: Node.js, TypeScript
• Web Framework: Express.js
• ORM: Prisma
• Caching/Queue: Redis, Bull
• Worker Manager: PM2 (ecosystem.config.js)
• Email: nodemailer (mailer.ts)
• Testing: YAML-based tests (tests/*.yml)
• CI/Reporting: report.json (likely code coverage/report)
Final Checklist
[ ] Grouping/containers for Docker services
[ ] Callouts for key modules (Prisma, RedisBull, Nodemailer)