# sametkayik/ecommerce-microservices architecture

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

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

## Overview

##### Main Components to be Represented
- API Gateway – This is the first point of entry and routes incoming requests (using Ocelot) to the appropriate microservices. It is represented under the directory "APIGateway" and includes its configuration file (ocelot.json).
- Product API – Managed in the Ecommerce.Services.ProductAPI folder. It handles product management (CRUD operations, mapping, migrations, etc.). Indicate its repository layer and DbContexts.
- Coupon API – Located in Ecommerce.Services.CouponAPI. This service manages discount/coupon operations, with dedicated controller, models, and repositories.
- Cart API – Found in Ecommerce.Services.CartAPI with its controllers, DbContexts, repositories, message bus integration (RabbitMQ via the RabbitMQSender), and mapping definitions.
- Identity Service – The Ecommerce.Services.Identity manages all user authentication and authorization tasks. It includes controllers and views for account management, identity initialization, and even configuration for issuing tokens.
- Chat Service – Offered by Ecommerce.Services.Chat, this uses SignalR (as mentioned in the README) to support real-time chat functionality.
- Web Service – This MVC-based frontend service (Ecommerce.Web) interacts with all backend services and provides the user interface for both admin and customer functionalities.
- Message Bus – The Ecommerce.MessageBus library encapsulates the messaging infrastructure that services like the Cart API use to publish events (and likely listen for responses).
- Databases – Although not explicitly shown as separate services, each microservice with a “DbContexts” folder or migrations (e.g., Product, Coupon, Identity, Cart) indicates its own persistence layer (MSSQL as per the README).

##### Relationships and Data Flow
- The external clients or the dedicated frontend send requests first to the API Gateway.
- API Gateway then communicates with various microservices based on defined routing rules.
- The Cart API publishes messages or interacts with the Message Bus to facilitate event-driven communication (e.g., for checkout processing).
- The Identity Service handles user login/registration and token issuance, likely interfaced with other services for secured resource access.
- The MVC Web Service calls the backend APIs (directly or via the gateway) to retrieve and display information.
- Each microservice interacts with its own MSSQL database for persistent storage.
- Real-time interactions may be represented specifically in the Chat Service through SignalR.

##### Architectural Patterns and Design Principles
- Microservices Architecture – Each service is decoupled and responsible for its own domain.
- API Gateway Pattern – A central API Gateway (using Ocelot) abstracts the microservice endpoints.
- Event-Driven Architecture – Communication via a message bus (RabbitMQ) facilitates asynchronous operations (e.g., within Cart API).
- MVC for the Web Service – The frontend separates concerns with Controllers, Views, and Models.

##### Technological and Deployment Details to Highlight
- .NET 8 is the foundation of all services.
- Dockerfiles in each service indicate containerized deployments, and the docker-compose.yml at the root orchestrates the containers.
- Use of Ocelot in the API Gateway is key to routing and centralized request management.
- SignalR is critical for the Chat Service’s real-time capabilities.
- MSSQL databases are used across services.
- RabbitMQ integration for service messaging (especially in the Cart API, as seen in the RabbitMQSender directory).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["Client (Browser/External)"]:::external

    %% Docker Compose Orchestration
    Docker["Docker Compose Orchestrated"]:::docker

    %% API Gateway
    APIGateway["API Gateway\n(Ocelot)"]:::gateway

    %% Microservices Subgraph
    subgraph "Backend Microservices"
        Product["Product API (.NET 8)"]:::service
        Coupon["Coupon API (.NET 8)"]:::service
        Cart["Cart API (.NET 8)"]:::service
        Identity["Identity Service (.NET 8)"]:::service
        Chat["Chat Service\n(SignalR)"]:::service
        Web["Web Service (MVC)"]:::frontend
    end

    %% Message Bus
    MessageBus["Message Bus\n(RabbitMQ)"]:::message

    %% Databases for Microservices
    ProductDB["Product Database\n(MSSQL)"]:::database
    CouponDB["Coupon Database\n(MSSQL)"]:::database
    CartDB["Cart Database\n(MSSQL)"]:::database
    IdentityDB["Identity Database\n(MSSQL)"]:::database

    %% Data Flow Arrows
    Client -->|"request"| APIGateway
    APIGateway -->|"routes"| Product
    APIGateway -->|"routes"| Coupon
    APIGateway -->|"routes"| Cart
    APIGateway -->|"routes"| Identity
    APIGateway -->|"routes"| Chat
    Web -->|"calls"| APIGateway

    %% Microservices Database Interactions
    Product -->|"CRUD"| ProductDB
    Coupon -->|"CRUD"| CouponDB
    Cart -->|"persist"| CartDB
    Identity -->|"manages"| IdentityDB

    %% Asynchronous Messaging for Cart API
    Cart <-->|"publishes"| MessageBus

    %% Docker Compose Orchestration to Services
    Docker --> APIGateway
    Docker --> Product
    Docker --> Coupon
    Docker --> Cart
    Docker --> Identity
    Docker --> Chat
    Docker --> Web

    %% Click Events
    click APIGateway "https://github.com/sametkayik/ecommerce-microservices/blob/main/APIGateway/ocelot.json"
    click Product "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.Services.ProductAPI"
    click Coupon "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.Services.CouponAPI"
    click Cart "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.Services.CartAPI"
    click Identity "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.Services.Identity"
    click Chat "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.Services.Chat"
    click Web "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.Web"
    click MessageBus "https://github.com/sametkayik/ecommerce-microservices/blob/main/Ecommerce.MessageBus"

    %% Classes and Styles
    classDef external fill:#FFCC00,stroke:#000,stroke-width:2px;
    classDef gateway fill:#66CCFF,stroke:#000,stroke-width:2px;
    classDef service fill:#99FF99,stroke:#000,stroke-width:2px;
    classDef frontend fill:#FF9999,stroke:#000,stroke-width:2px;
    classDef message fill:#CCCCFF,stroke:#000,stroke-width:2px;
    classDef database fill:#FFEEAD,stroke:#000,stroke-width:2px;
    classDef docker fill:#CCCCCC,stroke:#000,stroke-width:2px;
```
