Skip to main content

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

  1. Client Request → Express server receives HTTP/WebSocket request
  2. Middleware → Authentication, validation, logging
  3. Router → Route matching and handler selection
  4. Controller → Business logic execution
  5. Service/Model → Data persistence and external API calls
  6. Response → JSON response or WebSocket event emission