# mittal-sudhanshu/ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/mittal-sudhanshu/ecommerce
- Repository: https://github.com/mittal-sudhanshu/ecommerce

## Overview

##### Project Type
- This project is a microservices-based e-commerce application with distinct services for users, products, orders, a GraphQL gateway for external API access, and a DLQ (Dead Letter Queue) service for handling failed messages.
- It also uses Kafka for event-driven communication and MongoDB (implied from the README) as the primary data storage.
- Each microservice is containerized with Docker (note the Dockerfiles and docker-compose.yml files) which indicates a deployment environment based on Docker Compose.

##### Main Components
- User Service – responsible for managing user registration, authentication, and profiles.
- Product Service – manages product catalog, inventory, and related operations.
- Order Service – handles order processing and related management.
- GraphQL Gateway – provides a unified GraphQL API that aggregates data from the various back-end services.
- DLQ Service – dedicated to handling messages that have failed processing.
- Kafka Messaging System – central event bus for inter-service communication.
- Database Component – MongoDB used by all microservices for persistent data storage.

##### Relationships and Interactions
- Each microservice (User, Product, Order) communicates with Kafka for publishing and subscribing events.
- The GraphQL Gateway acts as the façade for client applications. It interacts with the back-end services (via REST calls or Kafka events) to fetch and manipulate data.
- The DLQ Service is connected to Kafka, listening for messages that cannot be processed, ensuring resilience.
- MongoDB is shared across the services (or possibly each service might have its own database configuration but the README suggests a common database engine).

##### Highlighting Architectural Patterns and Technologies
- Microservices architecture – clearly separate components.
- Event-Driven Communication – using Kafka for decoupling services via asynchronous messages.
- API Gateway Pattern – implemented by the GraphQL Gateway to abstract and unify API calls.
- Containerization – Docker/Docker Compose files emphasize the containerized nature of the system.
- Technologies include Node.js (observed from the directory structure and file naming, e.g., index.js files), Kafka, MongoDB, and Docker.

- Clear labels for each component (User Service, Order Service, Product Service, GraphQL Gateway, DLQ Service, Kafka, MongoDB).
- Data flow from client applications to the GraphQL Gateway.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client and API Gateway
    Client("Client Application")
    GG["GraphQL Gateway (Docker) [Port:4000]"]:::gateway

    %% Microservices
    subgraph "Microservices Layer"
        User["User Service (Docker) [Port:5000]"]:::microservice
        Order["Order Service (Docker) [Port:5001]"]:::microservice
        Product["Product Service (Docker) [Port:5002]"]:::microservice
    end

    %% Infrastructure Services
    Kafka["Kafka Messaging System"]:::kafka
    DLQ["DLQ Service (Docker) [Port:8000]"]:::dlq
    Mongo["MongoDB"]:::database

    %% Client to Gateway
    Client -->|"calls"| GG

    %% Gateway calls microservices
    GG -->|"aggregates"| User
    GG -->|"aggregates"| Order
    GG -->|"aggregates"| Product

    %% Microservices interact with Kafka and MongoDB
    User -->|"publishes/subscribes"| Kafka
    Order -->|"publishes/subscribes"| Kafka
    Product -->|"publishes/subscribes"| Kafka

    User -->|"reads/writes"| Mongo
    Order -->|"reads/writes"| Mongo
    Product -->|"reads/writes"| Mongo

    %% Optional direct gateway interaction with Kafka
    GG -->|"queriesViaEvents"| Kafka
    
    %% Kafka to DLQ for failed messages
    Kafka -->|"failedMessage"| DLQ

    %% Legend
    subgraph "Legend"
        LG1["GraphQL Gateway: Yellow"]
        LG2["Microservices: Light Blue"]
        LG3["Kafka: Light Red"]
        LG4["MongoDB: Light Green"]
        LG5["DLQ: Gray"]
    end

    %% Click Events
    click User "https://github.com/mittal-sudhanshu/ecommerce/tree/main/user-service/"
    click Order "https://github.com/mittal-sudhanshu/ecommerce/tree/main/order-service/"
    click Product "https://github.com/mittal-sudhanshu/ecommerce/tree/main/product-service/"
    click GG "https://github.com/mittal-sudhanshu/ecommerce/tree/main/graphql-gateway/"
    click DLQ "https://github.com/mittal-sudhanshu/ecommerce/tree/main/dlq-service/"
    click Kafka "https://github.com/mittal-sudhanshu/ecommerce/blob/main/kafka/docker-compose.yml"
    click Mongo "https://github.com/mittal-sudhanshu/ecommerce/blob/main/docker-compose.yml"

    %% Styles
    classDef gateway fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef microservice fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef kafka fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef database fill:#99ff99,stroke:#333,stroke-width:2px;
    classDef dlq fill:#cccccc,stroke:#333,stroke-width:2px;
```
