Architecture
Application Architecture
┌─────────────────────────────────────────────────────────┐
│ Client Applications │
│ (Web, Mobile, Third-party APIs) │
└────────────────────┬────────────────────────────────────┘
│
├─── HTTP/REST APIs
├─── WebSocket (Socket.io)
│
┌────────────────────▼────────────────────────────────────┐
│ Express.js Server │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Middleware Layer │ │
│ │ • CORS, Helmet, Morgan │ │
│ │ • Authentication (Passport) │ │
│ │ • Request Validation (AJV, Express-Validator) │ │
│ │ • Error Handling │ │
│ └──────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Router Layer (Routes) │ │
│ │ • Store, Product, Cart, Transaction │ │
│ │ • Review, Chat, Affiliate, CMS │ │
│ └──────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Controller Layer (Business Logic) │ │
│ │ • Request handling & validation │ │
│ │ • Service orchestration │ │
│ └──────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Service Layer │ │
│ │ • Chat Services (WebSocket) │ │
│ │ • Payment Services (Xendit) │ │
│ │ • Shipping Services (GoSend) │ │
│ └──────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Model Layer (Data Access) │ │
│ │ • Sequelize Models (PostgreSQL) │ │
│ │ • Mongoose Models (MongoDB) │ │
│ └──────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ Utility Layer │ │
│ │ • Generators, Validators, Helpers │ │
│ └──────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────┘
│
┌────────────────┼────────────────┐
│ │ │
┌───▼────┐ ┌───────▼───────┐ ┌──▼──────┐
│PostgreSQL│ │ MongoDB │ │ Redis │
│ (Main) │ │ (Cache/Chat) │ │ (Cache) │
└──────────┘ └───────────────┘ └─────────┘
│
┌────────────────┼────────────────┐
│ │ │
┌───▼────┐ ┌───────▼───────┐ ┌──▼─────┐
│ Minio │ │ Xendit │ │ GoSend │
│(Storage)│ │ (Payment) │ │(Shipping)│
└─────────┘ └───────────────┘ └────────┘
Request Flow
-
Client Request → Express server receives HTTP/WebSocket request
-
Middleware → Authentication, validation, logging
-
Router → Route matching and handler selection
-
Controller → Business logic execution
-
Service/Model → Data persistence and external API calls
-
Response → JSON response or WebSocket event emission