A robust, enterprise-grade distributed system refactored from a monolithic architecture. This project demonstrates the Database-per-Service pattern, Polyglot Persistence (MongoDB + PostgreSQL), API Gateway implementation, and synchronous inter-service communication using Node.js, Express, and TypeScript.
The application is split into three distinct domain services, unified by a single entry point (API Gateway). This system uses Polyglot Persistence, meaning different services use different database technologies best suited for their data needs.
| Service | Port | Responsibility | Database |
|---|---|---|---|
| API Gateway | 8000 |
Unified Entry Point, Request Routing, Rate Limiting | N/A |
| Auth Service | 3001 |
Registration, Login, JWT Issuance, Security | micro-auth-db (MongoDB) |
| User Service | 3002 |
User Profiles, Admin Management, Sync Logic | micro-user-db (MongoDB) |
| Notes Service | 3003 |
Notes CRUD, Tagging, Full-text Search | PostgreSQL (via Prisma) |
- Runtime: Node.js
- Language: TypeScript
- Framework: Express.js
- Databases: * MongoDB: For flexible user profiles and auth logs (Auth & User Services).
- PostgreSQL: For structured relational data and efficient indexing (Notes Service).
- ORM/ODM: * Mongoose: Used in Auth/User services.
- Prisma (v7+): Used in Notes service with
pgdriver adapter for connection pooling.
- Prisma (v7+): Used in Notes service with
- Communication: Synchronous HTTP (
axios) for internal sync (e.g., Deactivation). - Gateway:
http-proxy-middleware. - Validation: Zod.
- Security: Helmet, HPP, CORS, JWT.
Demonstrates how to run a Hybrid Database system. The Notes Service was completely migrated to PostgreSQL to leverage relational arrays and indexing, while Auth & User services remain on MongoDB. The frontend/client remains unaware of these underlying differences.
We handle data consistency between Auth and User services using internal API routes:
- Soft Delete: When a user deletes their own account, the User Service marks the profile as inactive and calls the Auth Service to disable login access immediately.
- Hard Delete: When an Admin deletes a user, the User Service destroys the profile and commands the Auth Service to permanently remove the credentials.
The Notes Service verifies JWTs independently without needing to call the Auth Service database, ensuring horizontal scalability.
All requests are made to port 8000.
POST /api/auth/register- Register a new user (Syncs to User Service)POST /api/auth/login- Login & receive JWTPOST /api/auth/forgot-password- Request password reset emailPATCH /api/auth/reset-password/:token- Set new password using tokenPATCH /api/auth/update-password- Update password (requires login)
Current User
GET /api/users/me- Get current profilePATCH /api/users/update-me- Update bio, avatar, or usernameDELETE /api/users/delete-me- Soft Delete account (Syncs deactivation to Auth)
Admin Operations
GET /api/users- Get all usersGET /api/users/:id- Get specific user detailsPATCH /api/users/:id- Update a specific userDELETE /api/users/:id- Hard Delete user (Permanently removes from Auth DB)
GET /api/notes- Get all notes (Supports pagination, search, & tag filtering)POST /api/notes- Create a new noteGET /api/notes/:id- Get a single notePATCH /api/notes/:id- Update a noteDELETE /api/notes/:id- Delete a note