# sarangchoudhary96/ecommerce_microservice architecture

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

- Interactive diagram: https://gitdiagram.com/sarangchoudhary96/ecommerce_microservice
- Repository: https://github.com/sarangchoudhary96/ecommerce_microservice

## Overview

##### Main Components
- API Gateway: Acts as the entry point for all client requests. It handles routing, request preprocessing, token validation, and passing calls to the appropriate backend microservice.
- Auth Service: Responsible for user login, registration, token validation, and various related validations.
- Order Service: Manages order placement, cancellation, and order flow through dedicated resolvers.
- Notification Service: Handles the sending of notifications (emails and SMS) using different handlers. It also makes use of AMQP for messaging.
- Product Service: Although minimal in structure, it likely handles product-related data and operations.
- Database Service: Manages interactions with the persistent storage, including models for users, contacts, sessions, etc. It also contains resolvers for fetching or manipulating data.
- ES Service: Likely provides either event-sourcing or search capabilities for the ecommerce system.
- (Optional) Messaging/AMQP Connector: Since several services (auth, order, notification) contain connectors and publishers for AMQP, it’s helpful to indicate a message broker (for example, a RabbitMQ or similar) that mediates asynchronous communications.

##### Relationships and Interactions
- The API Gateway sits at the front and routes requests to the appropriate backend microservices based on URL paths or request context.
- Each microservice (auth, order, database, etc.) exposes its own endpoints (or message consumers) and follows internal routing. For example, the auth service’s versioned routes ("/v1", "/v2") indicate different API versions.
- Asynchronous communication occurs between services (e.g., order service may publish order-related events that notification service consumes, and both use AMQP-based connectors).
- The database service underpins storage for user data and possibly other entities, and services interact with it either directly or via defined resolvers.

##### Architectural Patterns and Key Principles
- Microservices-based Architecture: Each service is separately structured, maintaining its own code (with independent .babelrc, .eslintrc.json, package.json files) and responsibilities.
- API Gateway Pattern: Centralized entry point that abstracts internal microservices from external clients.
- Asynchronous Messaging: Use of AMQP (as seen in the auth-service, notification-service and order-service utility files) to decouple communication and improve scalability.
- Separation of Concerns: Clear division into services such as authentication, order management, and notifications allows easier scaling and maintainability.

##### Additional Elements for Clarity
- External dependencies (such as third-party services, external authentication sources, email/SMS providers, etc.) if known or required.

This detailed approach should give you, as a principal software engineer, a complete picture of the architecture tailored precisely to this ecommerce microservices project.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Components
    API_Gateway["API Gateway"]:::gateway

    subgraph "Microservices"
        Auth["Auth Service"]:::service
        Order["Order Service"]:::service
        Product["Product Service"]:::service
        Notification["Notification Service"]:::service
        Database["Database Service"]:::database
        ES["ES Service"]:::service
    end

    MsgBroker(("Message Broker/AMQP")):::messaging

    subgraph "AMQP Utilities"
        Auth_AMQP_Conn["Auth AMQP Connection"]:::utility
        Auth_AMQP_Pub["Auth AMQP Publisher"]:::utility
        Order_AMQP_Conn["Order AMQP Connection"]:::utility
        Order_Consume["Order Consume Order"]:::utility
        Notification_AMQP_Conn["Notification AMQP Connection"]:::utility
    end

    %% API Gateway routing to Microservices via HTTP Requests
    API_Gateway -->|"HTTPRequest"| Auth
    API_Gateway -->|"HTTPRequest"| Order
    API_Gateway -->|"HTTPRequest"| Product
    API_Gateway -->|"HTTPRequest"| Notification
    API_Gateway -->|"HTTPRequest"| Database
    API_Gateway -->|"HTTPRequest"| ES

    %% Microservices communication with Message Broker using AMQP
    Auth -->|"AMQP"| MsgBroker
    Order -->|"AMQPPublish"| MsgBroker
    MsgBroker -->|"AMQPDeliver"| Notification

    %% Internal AMQP Utility Connections (for implementation details)
    Auth --> Auth_AMQP_Conn
    Auth --> Auth_AMQP_Pub
    Auth_AMQP_Pub -->|"Publish"| MsgBroker

    Order --> Order_AMQP_Conn
    Order --> Order_Consume
    MsgBroker -->|"Consume"| Order_Consume

    Notification --> Notification_AMQP_Conn
    Notification_AMQP_Conn -->|"Connect"| MsgBroker

    %% Click Events - Main Components
    click API_Gateway "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/api-gateway/"
    click Auth "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/auth-service/"
    click Order "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/order-service/"
    click Product "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/product-service/"
    click Notification "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/notification-service/"
    click Database "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/database-service/"
    click ES "https://github.com/sarangchoudhary96/ecommerce_microservice/tree/master/es-service/"

    %% Click Events - AMQP Utility Files
    click Auth_AMQP_Conn "https://github.com/sarangchoudhary96/ecommerce_microservice/blob/master/auth-service/src/utils/amqpConnection.js"
    click Auth_AMQP_Pub "https://github.com/sarangchoudhary96/ecommerce_microservice/blob/master/auth-service/src/utils/amqpPublisher.js"
    click Order_AMQP_Conn "https://github.com/sarangchoudhary96/ecommerce_microservice/blob/master/order-service/src/utils/amqpConnection.js"
    click Order_Consume "https://github.com/sarangchoudhary96/ecommerce_microservice/blob/master/order-service/src/utils/consumeOrder.js"
    click Notification_AMQP_Conn "https://github.com/sarangchoudhary96/ecommerce_microservice/blob/master/notification-service/src/utils/amqpConnection.js"

    %% Styles
    classDef gateway fill:#FAD7A0,stroke:#333,stroke-width:2px
    classDef service fill:#AED6F1,stroke:#333,stroke-width:2px
    classDef database fill:#A9DFBF,stroke:#333,stroke-width:2px
    classDef messaging fill:#F9E79F,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
    classDef utility fill:#F5B7B1,stroke:#333,stroke-width:2px
```
