# grilled-swampert/ecommerce-microservices architecture

> Architecture diagram of the GitHub repository grilled-swampert/ecommerce-microservices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/grilled-swampert/ecommerce-microservices
- Repository: https://github.com/grilled-swampert/ecommerce-microservices

## Overview

##### Project Type and Purpose
- This is a container-based microservices application written in Node.js, comprising three core services (order, payment, user).
- It’s designed for deployment on Kubernetes (also supports Docker Compose), uses Kong as an API gateway/ingress controller, and Postgres as the backing datastore.
- The repo also contains load-testing scripts and chaos-engineering experiments to validate resilience and performance.

##### File Structure
- Top-level directories:
– order-service, payment-service, user-service: each contains a Dockerfile, Node.js code (index.js, logger.js, metrics.js, metricsMiddleware.js), package.json.
– k8s, services: Kubernetes Deployment and Service YAMLs for each microservice, Postgres, Kong rate limiting, and health-monitoring sidecars.
– experiments: chaos-injection manifests (CPU stress, IO chaos, network delay, pod kill).
– microservices-load-tests: JS load-test scripts, configuration, and results.
– ingress-setup.yaml / ingress_setup.txt: instructions for configuring the Kong ingress.
– docker-compose.yml & deploy-all.sh: local multi-container orchestration scripts.

##### (Minimal) README
- The README (“op”) is a placeholder; no architecture details are provided. All insights must come from the directory layout, file names, and YAMLs.

##### Main Components and Their Interactions
a. API Gateway (Kong)
– Receives all external HTTP traffic.
– Enforces rate limits (k8s/kong-rate-limiter.yaml).
– Routes requests to the appropriate microservice.
b. Microservices
– order-service, payment-service, user-service run as separate Kubernetes Deployments and Services.
– Each service exposes REST endpoints and a metrics endpoint.
– Services may call each other: e.g., order-service may validate user via user-service and process payment via payment-service.
c. Database
– A single Postgres instance (Deployment in k8s/postgres-deployment.yaml).
– All services connect to this shared database for persistence.
d. Monitoring & Metrics
– metricsMiddleware.js in each service exports application metrics.
– Kubernetes Service manifests (services/*-monitor.yaml) expose monitoring endpoints (for Prometheus).
– Logs captured via logger.js, assume a centralized logging system (e.g., Fluentd or ELK).
e. Load Testing and Chaos Engineering
– microservices-load-tests runs performance tests against the live cluster.
– experiments/*.yaml inject faults to validate resilience.
f. Deployment Orchestration
– docker-compose.yml & deploy-all.sh for local testing.
– Full production deployment via kubectl apply -f k8s/ and services/.

##### Architectural Patterns and Principles
- Microservices with API Gateway pattern.
- Sidecar pattern for monitoring (metrics scraping).
- Single shared relational database (monolithic datastore) – consider splitting if scale or CQRS needed.
- Chaos-engineering and automated load-testing integrated into CI/CD pipeline.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Clients & External"
        Client["Clients (Web/Mobile)"]:::external
        LoadTest["Load Test Harness"]:::testing
        Chaos["Chaos Experiment Controller"]:::testing
        LocalDeploy["Local Deployment Scripts"]:::testing
    end

    subgraph "Kubernetes Cluster"
        Kong["Kong API Gateway"]:::gateway
        subgraph "Microservices"
            OrderService["Order Service\n(Node.js)"]:::service
            PaymentService["Payment Service\n(Node.js)"]:::service
            UserService["User Service\n(Node.js)"]:::service
        end
        Postgres["Postgres DB"]:::database
        subgraph "Monitoring Stack"
            Prometheus["Prometheus"]:::monitoring
        end
    end

    Client -->|"HTTP/REST"| Kong
    LoadTest -->|"Test Traffic"| Kong
    Chaos -->|"Inject Faults"| OrderService
    Chaos -->|"Inject Faults"| PaymentService
    Chaos -->|"Inject Faults"| UserService
    LocalDeploy -->|"Local Orchestration"| Kong

    Kong -->|"Route HTTP/REST"| OrderService
    Kong -->|"Route HTTP/REST"| PaymentService
    Kong -->|"Route HTTP/REST"| UserService

    OrderService -->|"HTTP/REST"| UserService
    OrderService -->|"HTTP/REST"| PaymentService

    OrderService -->|"TCP (SQL)"| Postgres
    PaymentService -->|"TCP (SQL)"| Postgres
    UserService -->|"TCP (SQL)"| Postgres

    OrderService -->|"Metrics Scrape"| Prometheus
    PaymentService -->|"Metrics Scrape"| Prometheus
    UserService -->|"Metrics Scrape"| Prometheus

    classDef gateway fill:#D0EFFF,stroke:#006BBD,stroke-width:2px;
    classDef service fill:#E8F0FF,stroke:#1A3A8A,stroke-width:2px;
    classDef database fill:#E6F4EA,stroke:#237A52,stroke-width:2px;
    classDef monitoring fill:#FFF4D6,stroke:#D69E2E,stroke-width:2px;
    classDef testing fill:#FFE8D6,stroke:#D95B00,stroke-width:2px;
    classDef external fill:#F0F0F0,stroke:#999999,stroke-width:1px;

    click Kong "https://github.com/grilled-swampert/ecommerce-microservices/blob/main/k8s/kong-rate-limiter.yaml"
    click Kong "https://github.com/grilled-swampert/ecommerce-microservices/blob/main/ingress-setup.yaml"
    click Kong "https://github.com/grilled-swampert/ecommerce-microservices/blob/main/ingress_setup.txt"
    click OrderService "https://github.com/grilled-swampert/ecommerce-microservices/tree/main/order-service"
    click PaymentService "https://github.com/grilled-swampert/ecommerce-microservices/tree/main/payment-service"
    click UserService "https://github.com/grilled-swampert/ecommerce-microservices/tree/main/user-service"
    click Postgres "https://github.com/grilled-swampert/ecommerce-microservices/blob/main/k8s/postgres-deployment.yaml"
    click LoadTest "https://github.com/grilled-swampert/ecommerce-microservices/tree/main/microservices-load-tests"
    click Chaos "https://github.com/grilled-swampert/ecommerce-microservices/tree/main/experiments"
    click LocalDeploy "https://github.com/grilled-swampert/ecommerce-microservices/blob/main/docker-compose.yml"
    click LocalDeploy "https://github.com/grilled-swampert/ecommerce-microservices/blob/main/deploy-all.sh"
```
