How fernandobrandan/ecommerce-ms works
Project Type and Purpose
• This is a full-stack, microservices-based e-commerce platform.
• The “front” folder contains the user-facing Node/Express/EJS application.
• The s0-Gateway folder holds the API Gateway (NGINX + Express).
• s1 through s6 are independent services: User, Product, Cart, Order, Payment, Notification.
• Each service exposes HTTP REST endpoints, has its own Dockerfile, TypeScript code, and connects to its own PostgreSQL database.
High-Level Architecture
• API Gateway (Nginx + Express) sits at the edge, load-balances and routes incoming HTTP/HTTPS requests.
• The Frontend Node/EJS app either calls the Gateway directly or is itself proxied behind Nginx.
• Six microservices perform domain-specific business logic:
• User Service
• Product Service
• Cart Service
• Order Service
• Payment Service (integrates MercadoPago via ngrok in development)
• Notification Service (sends emails via Nodemailer and SMS via Twilio)
• Each service uses its own PostgreSQL instance (DB per service pattern).
• Services can call each other synchronously over HTTP for cross-service workflows (e.g., Order Service calls Cart Service to fetch cart items).
Key Components
• External Clients (Browser or Mobile App)
• Nginx/API Gateway
• Frontend Service (Node/EJS)
• User Service + User_DB
• Product Service + Product_DB
• Cart Service + Cart_DB
• Order Service + Order_DB
• Payment Service + Payment_DB
• Notification Service (stateless, integrates SMTP & Twilio)
• External APIs: MercadoPago, Email SMTP server, Twilio SMS API
• Docker Network (each service runs in its own container)
Relationships and Data Flow
• Clients → Nginx/API Gateway (incoming HTTP)
• Gateway → Respective Service endpoints (userRoute, productRoute, etc.)
• Frontend → Gateway → Services (for dynamic data)
• Order Service → Cart Service (HTTP call)
• Order Service → User Service (to validate user)
• Payment Service → MercadoPago API (HTTPS)
• Notification Service → SMTP/Twilio (outgoing calls)
• Each Service → Its own PostgreSQL instance (via Sequelize ORM)
Architectural Patterns & Design Principles
• Microservices: independent deployable services, own codebase and database.
• API Gateway: unified entrypoint, request routing, load balancing.
• Database per Service: ensures loose coupling, service autonomy.
• Synchronous HTTP Communication: for simplicity, services call each other directly.
• Containerization with Docker: each service and gateway run in isolated containers.
• Future-proof: Kubernetes for orchestration, GitHub Actions for CI/CD.
d. To the right, arrange the six microservice containers horizontally.
f. Off to the side, add external APIs (MercadoPago, SMTP, Twilio).
• Client → Gateway → Frontend/Services.
• Service → Its DB.
• Payment Service → MercadoPago.
• Notification Service → SMTP/Twilio.