Microservices Overview
ShopStack Platform implements a polyglot microservices architecture where two independent services handle different business domains while sharing a common data layer.Service Responsibilities
Python Service
Domain Focus: Transactional operations
- User authentication & JWT issuing
- Product catalog management
- Order creation & tracking
- Payment processing & calculations
- Tax & discount logic
Node.js Service
Domain Focus: User operations & analytics
- User profile management
- Product search & discovery
- Sales reporting
- Analytics & metrics
- Health monitoring
Technology Stack
Python Service Stack
Web Framework
Web Framework
Flask 2.3.0+Lightweight WSGI web framework with:
- Blueprint-based route organization
- Custom JSON encoder for datetime and Decimal types
- Application factory pattern for testing
app/__init__.py
ORM & Database
ORM & Database
Flask-SQLAlchemy 3.1.1Database abstraction with support for:
- PostgreSQL (production) via psycopg2-binary
- SQLite (testing) for isolated test runs
- Automatic table creation
- Model relationships and lazy loading
- Development: SQLite in-memory database
- Production: PostgreSQL with connection pooling
- Test: SQLite in-memory with fixtures
Authentication
Authentication
Flask-JWT-Extended 4.6.0JWT token management with:
- Access token generation
- Token verification middleware
- User identity resolution
- bcrypt password hashing (4.1.2)
Node.js Service Stack
Web Framework
Web Framework
Express 4.18.2Minimal and flexible Node.js framework with:
- Route-based organization
- Middleware chain for auth and validation
- Global error handling
src/index.js
ORM & Database
ORM & Database
Sequelize 6.35.0Promise-based ORM with:
- Model definition and associations
- Automatic migrations
- PostgreSQL support via pg driver
- SQLite for testing
src/models/index.js
Authentication
Authentication
jsonwebtoken 9.0.2JWT implementation with:
- Token signing and verification
- Expiration handling
- bcryptjs for password hashing
- express-validator for input validation
Database Schema
Both services share a unified PostgreSQL database with the following core tables:Users Table
The
profile field is a JSON column used by the Node.js service for storing extended user metadata.Products Table
Orders Table
Order Items Table
Service Communication
Shared Database Pattern
Both services communicate primarily through the shared database:Write Operations
Each service writes to tables within its domain:
- Python service creates/updates: products, orders, order_items
- Node.js service creates/updates: users, user profiles
Read Operations
Both services can read from all tables:
- Python service reads user data for authentication
- Node.js service reads products and orders for reporting
Redis for Cross-Service Communication
Redis is used for:Session Storage
JWT tokens and session data with TTL expiration
Caching
Frequently accessed data like product catalogs
Pub/Sub
Event notifications between services (future enhancement)
Rate Limiting
API rate limiting and throttling
docker-compose.yml
API Endpoints Overview
Python Service Endpoints (Port 5000)
Authentication
Authentication
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/register | No | Register new user |
| POST | /api/auth/login | No | Login and get JWT |
| GET | /api/auth/me | JWT | Get current user |
Products
Products
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/products/ | No | List products (paginated) |
| GET | /api/products/<id> | No | Get product by ID |
| GET | /api/products/search?q= | No | Search products |
| POST | /api/products/ | JWT | Create product |
Orders
Orders
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/orders/ | JWT | List user’s orders |
| GET | /api/orders/<id> | JWT | Get order by ID |
| POST | /api/orders/ | JWT | Create new order |
Payments
Payments
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/payments/calculate | JWT | Calculate total with tax/discount |
| POST | /api/payments/checkout | JWT | Process payment for order |
Node.js Service Endpoints (Port 3000)
Authentication
Authentication
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/register | No | Register new user |
| POST | /api/auth/login | No | Login and get JWT |
Users
Users
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/users/:id | JWT | Get user by ID |
| GET | /api/users/me/profile | JWT | Get current user profile |
| PUT | /api/users/me/profile | JWT | Update user profile |
Products
Products
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/products | No | List products (paginated) |
| GET | /api/products/search?q= | No | Search products |
| GET | /api/products/:id | No | Get product by ID |
| POST | /api/products | JWT | Create product |
Reports
Reports
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/reports/sales | JWT | Generate sales report |
Health
Health
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/health | No | Service health check |
Deployment Architecture
Docker Compose Setup
The platform uses Docker Compose for orchestration with health checks and dependency management:docker-compose.yml
Services use different Redis database indices (0 and 1) to isolate their cached data.
Testing Architecture
Both services use in-memory SQLite databases for testing to ensure:Isolation
Each test run has a fresh database with no shared state
Speed
In-memory databases are significantly faster than PostgreSQL
Portability
No external dependencies required to run tests
Fixtures
Test data is loaded from fixtures in conftest.py/test setup
tests/conftest.py
jest.config.js
Scalability Considerations
Horizontal Scaling
Horizontal Scaling
Both services are stateless and can be scaled horizontally:
- Deploy multiple instances behind a load balancer
- Use Redis for shared session state
- Database connection pooling prevents resource exhaustion
- JWT tokens eliminate session affinity requirements
Database Optimization
Database Optimization
- Indexes on frequently queried columns (email, category, user_id)
- Connection pooling with configurable pool size
- Read replicas for report generation (Node.js service)
- Prepared statements prevent SQL injection and improve performance
Caching Strategy
Caching Strategy
- Redis caching for product catalogs and user sessions
- TTL-based cache invalidation
- Cache-aside pattern for frequently accessed data
- Separate Redis databases per service for isolation
Monitoring & Health
Monitoring & Health
- Health check endpoints for container orchestration
- Database connection health verification
- Error logging with context for debugging
- Request/response logging in development mode
Security Architecture
Authentication
- bcrypt password hashing with salt rounds
- JWT tokens with expiration
- Secure secret key storage via environment variables
Authorization
- Role-based access control (customer, admin)
- JWT middleware validates tokens on protected routes
- User-scoped operations (users can only access their orders)
Input Validation
- express-validator for Node.js request validation
- Marshmallow schemas for Python data validation
- SQL injection prevention via ORM parameterization
CORS
- Configurable CORS policies
- Credential support for authenticated requests
- Origin whitelisting in production
Repository Structure
The
incidents/ directory contains structured JSON tickets for issue tracking and resolution workflows.