Architecture overview
QeetMart implements a microservices architecture with an API Gateway pattern, polyglot service runtime, and contract-first API design.System architecture
Core principles
Service isolation
Each service has its own database, codebase, and deployment lifecycle. No shared databases.
Contract-first APIs
OpenAPI 3.0 specs define all service interfaces. Breaking changes are detected in CI.
Technology flexibility
Services use the best tool for the job: Node.js for routing, Java for business logic, Go for performance.
Centralized gateway
Single entry point handles auth, rate limiting, routing, and cross-cutting concerns.
API Gateway
The API Gateway (micros/api-gateway/src/index.ts:1) is built with Node.js and Express, providing:Routing and proxying
Requests are routed to backend services based on path patterns:http-proxy-middleware to forward requests (micros/api-gateway/src/routes/gateway.routes.ts:39):
Security middleware
Multiple security layers protect the gateway (micros/api-gateway/src/index.ts:22):Health monitoring
The gateway provides health check endpoints (micros/api-gateway/src/index.ts:56):Microservices
Auth Service (Spring Boot)
Port: 4001Runtime: Java 17 + Spring Boot
Database: PostgreSQL (auth_db)
Purpose: JWT authentication and authorization Key responsibilities:
- User registration and login
- JWT token issuance and validation
- Password hashing and security
- Session management
User Service (Spring Boot)
Port: 8082Runtime: Java 17 + Spring Boot
Database: PostgreSQL (user_db)
Purpose: User profile and preferences management Key responsibilities:
- User profile CRUD operations
- Address management
- User preferences and settings
- Profile validation
Product Service (Spring Boot)
Port: 8083Runtime: Java 17 + Spring Boot
Database: PostgreSQL (product_db)
Purpose: Product catalog management Key responsibilities:
- Product catalog CRUD
- Category management
- Product search and filtering
- Pricing and metadata
Inventory Service (Go)
Port: 8080Runtime: Go 1.23+ + Gin framework
Database: PostgreSQL + Redis
Purpose: Real-time inventory tracking with caching Key responsibilities:
- Stock level tracking
- Inventory reservations with TTL
- Redis caching for high-performance reads
- Expiration worker for reservation cleanup
The inventory service uses Go for its exceptional concurrency model, low latency, and efficient memory usage - critical for real-time stock updates and reservation handling.
Data architecture
Database per service pattern
Each service owns its database schema:| Service | Database | Purpose |
|---|---|---|
| Auth Service | auth_db | User credentials, tokens, sessions |
| User Service | user_db | User profiles, addresses, preferences |
| Product Service | product_db | Products, categories, pricing |
| Inventory Service | inventory | Stock levels, reservations |
Caching strategy
The inventory service uses Redis for caching (docker-compose.dev.yml:152):- Product stock levels (high read volume)
- Reservation state (TTL-based expiration)
- Frequent inventory queries
Database migrations
Each service manages its own schema migrations:- Spring Boot services: Use JPA with
JPA_DDL_AUTO=updatefor development - Go inventory service: SQL migration files in
micros/inventory-service/migrations/
Communication patterns
Request flow
- Client request → API Gateway (port 4000)
- Gateway auth middleware validates JWT token
- Gateway rate limiter checks request quota
- Proxy middleware routes to appropriate service
- Service processes request and queries its database
- Response flows back through gateway to client
Service discovery
Services are discovered via environment variables (micros/api-gateway/.env.example:29):Error handling
The gateway handles service failures gracefully (micros/api-gateway/src/routes/gateway.routes.ts:47):Contract governance
QeetMart uses OpenAPI 3.0 specifications as the source of truth for all service APIs.OpenAPI specs location
All contracts live incontracts/openapi/*.openapi.json:
auth-service.openapi.jsonuser-service.openapi.jsonproduct-service.openapi.jsoninventory-service.openapi.json
Contract validation
CI enforces contract rules:- Removing API paths or operations
- Adding required request parameters
- Removing response fields
- Changing response status codes
- Deleting contract files
TypeScript client generation
Type-safe clients are generated from OpenAPI specs:packages/openapi-clients/ with full TypeScript definitions.
Deployment architecture
Local development
Docker Compose provides the full stack:Kubernetes deployment
Kustomize overlays for each environment:Helm deployment
Alternatively, use the Helm chart:Scalability considerations
Horizontal scaling
Each service can scale independently based on load. API Gateway and services are stateless.
Database isolation
Service-specific databases prevent bottlenecks and allow independent schema evolution.
Redis caching
Inventory service caches frequently accessed data, reducing database load significantly.
Async processing
Inventory reservations use TTL-based expiration with background workers.
Monitoring and observability
Health checks
Each service exposes health endpoints:- Spring Boot services:
/actuator/health - Node.js Gateway:
/health - Go Inventory:
/health
/health/services.
Logging
All services use structured logging:- Node.js: Console with request correlation IDs
- Spring Boot: Logback with JSON formatting
- Go:
slogwith JSON handler
Request tracing
The gateway adds correlation IDs to all requests (micros/api-gateway/src/routes/gateway.routes.ts:69):Security architecture
Authentication flow
- Client authenticates with Auth Service via Gateway
- Auth Service validates credentials and issues JWT
- Client includes JWT in
Authorization: Bearer <token>header - Gateway validates JWT on every request
- Gateway forwards valid token to downstream services
JWT validation
The gateway validates JWTs before proxying (micros/api-gateway/.env.example:19):Network security
In Kubernetes:- Services communicate via internal cluster DNS
- Only the API Gateway is exposed via Ingress
- Network policies restrict inter-service communication
- TLS terminates at the Ingress controller
Next steps
API reference
Explore the OpenAPI documentation for each service
Deployment guide
Learn how to deploy QeetMart to Kubernetes
Configuration reference
Detailed guide to all environment variables and configuration options
Development guide
Best practices for adding new features and services