# chandan7dec/mangomicroservice architecture

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

- Interactive diagram: https://gitdiagram.com/chandan7dec/mangomicroservice
- Repository: https://github.com/chandan7dec/mangomicroservice

## Overview

##### Main Components
- API Gateway: Represented by Mango.GatewaySolution, which uses Ocelot to route and aggregate requests.
- Microservices: Separate services for AuthAPI, CouponAPI, EmailAPI, OrderAPI, RewardAPI, ShoppingCartAPI, and ProductAPI. Each microservice has its own business logic, data access layer (with dedicated AppDbContext files and EF Core migrations), and associated communication components (like message senders).
- Message Bus: Illustrated by the Mango.MessageBus, along with message sender/consumer components in several services (see RabbitMQ in AuthAPI and Azure Service Bus in EmailAPI and RewardAPI).
- Frontend Application: The Mango.web project, which is an MVC Razor view based application that interacts with the backend through the API Gateway.
- Payment Gateway: Integration with Stripe (as seen in DTOs such as StripeRequestDto), used likely in the Order/ShoppingCart flow.

##### Relationships and Interactions
- The Frontend (Mango.web) sends HTTP requests to the API Gateway.
- The API Gateway routes incoming requests to the appropriate microservices.
- Microservices communicate with their own databases. They also link with each other indirectly through asynchronous message handling via the message bus (Azure Service Bus in EmailAPI/RewardAPI or RabbitMQ in AuthAPI).
- The payment process is handled by Stripe, so include an external connection from the Order or ShoppingCart service to the Stripe system.
- Some microservices might call external services or third-party APIs as needed (such as for sending emails, handling coupons, etc.), so represent those interfaces where applicable.

##### Architectural Patterns and Technologies
- Microservices Architecture: Each business capability (auth, orders, products, etc.) is encapsulated in a separate service.
- API Gateway Pattern: Ocelot is used to centralize request routing and centralized cross-cutting concerns (e.g., authentication, logging).
- Database per Service: Show each microservice connected to its own SQL Server instance (or logical database) via Entity Framework Core.
- External Payment Integration: Clearly mark where the Stripe payment gateway fits into the Order or ShoppingCart flow.
- MVC / Frontend: The mango.web project is a distinct component interacting with users through Razor views.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Mango.web"]
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        GW["API Gateway"]
    end

    %% Microservices Layer
    subgraph "Microservices Layer"
        AUTH["Auth Microservice"]
        COUPON["Coupon Microservice"]
        EMAIL["Email Microservice"]
        ORDER["Order Microservice"]
        REWARD["Reward Microservice"]
        SHOP["Shopping Cart Microservice"]
        PRODUCT["Product Microservice"]
    end

    %% External Systems
    subgraph "External Systems"
        RABBIT["RabbitMQ"]
        AZURE["Azure Service Bus"]
        STRIPE["Stripe Payment"]
        MESSAGEBUS["Message Bus"]
    end

    %% Databases
    subgraph "Databases"
        DB_AUTH["SQL DB (Auth)"]
        DB_COUPON["SQL DB (Coupon)"]
        DB_EMAIL["SQL DB (Email)"]
        DB_ORDER["SQL DB (Order)"]
        DB_REWARD["SQL DB (Reward)"]
        DB_SHOP["SQL DB (Shopping Cart)"]
        DB_PRODUCT["SQL DB (Product)"]
    end

    %% Connections between Frontend and API Gateway
    FE -->|"HTTP"| GW

    %% Connections from API Gateway to Microservices
    GW -->|"HTTP"| AUTH
    GW -->|"HTTP"| COUPON
    GW -->|"HTTP"| EMAIL
    GW -->|"HTTP"| ORDER
    GW -->|"HTTP"| REWARD
    GW -->|"HTTP"| SHOP
    GW -->|"HTTP"| PRODUCT

    %% Microservices to their own Databases (EF Core)
    AUTH -->|"EFCore"| DB_AUTH
    COUPON -->|"EFCore"| DB_COUPON
    EMAIL -->|"EFCore"| DB_EMAIL
    ORDER -->|"EFCore"| DB_ORDER
    REWARD -->|"EFCore"| DB_REWARD
    SHOP -->|"EFCore"| DB_SHOP
    PRODUCT -->|"EFCore"| DB_PRODUCT

    %% Asynchronous Messaging and External Integrations
    AUTH -->|"async"| RABBIT
    EMAIL -->|"async"| AZURE
    REWARD -->|"async"| AZURE
    SHOP -->|"async"| MESSAGEBUS

    ORDER -->|"payment"| STRIPE
    SHOP -->|"payment"| STRIPE

    %% Click Events
    click GW "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.GatewaySolution"
    click MESSAGEBUS "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.MessageBus"
    click AUTH "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.Sercices.AuthAPI"
    click COUPON "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.Services.CouponAPI"
    click EMAIL "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.Services.EmailAPI"
    click ORDER "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.Services.OrderAPI"
    click REWARD "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.Services.RewardAPI"
    click SHOP "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.Services.ShoppingCartAPI"
    click PRODUCT "https://github.com/chandan7dec/mangomicroservice/tree/master/MangoProductAPI"
    click FE "https://github.com/chandan7dec/mangomicroservice/blob/master/Mango.web"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef gateway fill:#F7DC6F,stroke:#B7950B,stroke-width:2px;
    classDef microservice fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
    classDef ext fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
    classDef database fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;

    class FE frontend;
    class GW gateway;
    class AUTH,COUPON,EMAIL,ORDER,REWARD,SHOP,PRODUCT microservice;
    class RABBIT,AZURE,STRIPE,MESSAGEBUS ext;
    class DB_AUTH,DB_COUPON,DB_EMAIL,DB_ORDER,DB_REWARD,DB_SHOP,DB_PRODUCT database;
```
