# vietnam-devs/coolstore-microservices architecture

> Architecture diagram of the GitHub repository vietnam-devs/coolstore-microservices, 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/vietnam-devs/coolstore-microservices
- Repository: https://github.com/vietnam-devs/coolstore-microservices

## Overview

##### Main Components
- API Gateway: Show the API gateway component (in src/dotnet/api-gateway) which routes incoming HTTP requests and uses reverse proxying (YARP) to forward requests to respective backend services.
- Identity Service: Represent the identity service (in src/dotnet/identity-server) based on IdentityServer4 that handles authentication and access control.
- Product Catalog Service (src/dotnet/…/ProductCatalogService.Api),
- Inventory Service (src/dotnet/…/InventoryService.Api),
- Shopping Cart Service (src/dotnet/…/ShoppingCartService.Api),
- Sale Service (referenced by Go and possibly through additional language-specific directories).
- Supporting Services & Libraries: Include building blocks such as the “N8T.Core” and “N8T.Infrastructure” libraries which encapsulate cross-cutting concerns like logging, caching (using Redis), data access (EF Core), and messaging.
- Dapr Runtime: Highlight the Dapr components (in the components directory with appconfig.yaml, pubsub.yaml, statestore.yaml) that provide the foundational building blocks (service invocation, state management, pub/sub, resource bindings, etc.) across all microservices.
- Infrastructure & Deployment: Represent the deployment units through Docker (Dockerfiles in various parts), Tye configuration (tye.yaml), and Kubernetes/Helm charts (deploys/charts, deploys/bicep) that are used to containerize and orchestrate the services.

##### Relationships & Data Flow
- API Gateway routing requests to the appropriate microservices. Mark how these services interact using Dapr’s service invocation pattern.
- Pub/Sub messaging: For example, when a user clicks the checkout button in the shopping cart, an event flows through a pub/sub channel (supported by Dapr) across services (shopping cart, sale, identity).
- External communications from backend services to databases or external caches (like Redis for caching and possibly a messaging layer like Kafka as suggested in the building blocks).

##### Architectural Patterns & Design Principles
- Microservices architecture: each service is independently deployable within a container.
- Separation between front-end and back-end services, and how the API gateway centralizes routing and cross-cutting concerns like authentication.
- How Dapr abstracts inter-service communication, allowing the microservices to communicate in a loosely coupled fashion.
- If space allows, annotate that the project leverages Domain-Driven Design patterns (as mentioned in the README and related links) with building blocks for domain logic, repository patterns, and application services.

##### Relevant Technologies & Frameworks
- .NET Core for backend microservices (with EF Core, MediatR, FluentValidation, Serilog).
- React and TypeScript for the front-end.
- Dapr for service-to-service invocation, state management, pub/sub, etc.
- Tye for local development orchestration.
- Docker and Kubernetes/Helm for containerization and production deployment.
- Azure pipelines, Travis, and CI/CD scripts for continuous integration and deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    U("External User"):::external

    %% Front-end Layer
    subgraph "Front-end"
        FE1("CoolStore Web Application Primary"):::frontend
        FE2("CoolStore Web Application Backup"):::frontend
    end

    %% Backend Microservices Layer
    subgraph "Backend Microservices"
        AG("API Gateway"):::gateway
        ID("Identity Service"):::backend
        PC("Product Catalog Service"):::backend
        INV("Inventory Service"):::backend
        SC("Shopping Cart Service"):::backend
        SALE("Sale Service"):::backend
    end

    %% Supporting Services & Libraries
    subgraph "Supporting Services & Libraries"
        N8TCore("N8T.Core Library"):::supporting
        N8TInfra("N8T.Infrastructure Library"):::supporting
    end

    %% Dapr Runtime Components
    subgraph "Dapr Runtime Components"
        DAPP("appconfig.yaml"):::dapr
        DAPPub("pubsub.yaml"):::dapr
        DAPStore("statestore.yaml"):::dapr
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        TYE("Tye Configuration"):::infra
        DEPLOY("Deployment Units"):::infra
        DB("Databases/External Dependencies"):::infra
    end

    %% Data Flow
    U -->|"accesses"| FE1
    U -->|"accesses"| FE2

    FE1 -->|"APIcalls"| AG
    FE2 -->|"APIcalls"| AG

    AG -->|"serviceinvocation"| ID
    AG -->|"serviceinvocation"| PC
    AG -->|"serviceinvocation"| INV
    AG -->|"serviceinvocation"| SC
    AG -->|"serviceinvocation"| SALE

    SC -->|"pub/subevent"| SALE
    SC -->|"statemanagement"| DAPStore

    %% Backend usage of Supporting Libraries
    ID ---|"uses"| N8TCore
    PC ---|"uses"| N8TCore
    INV ---|"uses"| N8TInfra
    SC ---|"uses"| N8TCore
    SALE ---|"uses"| N8TInfra

    %% Dapr Integration for Service Calls
    AG ---|"daprintegration"| DAPP
    PC ---|"daprintegration"| DAPPub
    INV ---|"daprintegration"| DAPPub

    %% Containerization & Deployment
    AG ---|"containerizedvia"| DEPLOY
    ID ---|"containerizedvia"| DEPLOY
    PC ---|"containerizedvia"| DEPLOY
    INV ---|"containerizedvia"| DEPLOY
    SC ---|"containerizedvia"| DEPLOY
    SALE ---|"containerizedvia"| DEPLOY

    %% External Dependencies
    PC ---|"caches/datain"| DB
    INV ---|"caches/datain"| DB
    SC ---|"persiststatein"| DB

    %% Infrastructure & Dapr Configuration
    AG ---|"configuredwith"| TYE
    DAPP ---|"managedby"| TYE

    %% Styling Classes
    classDef external fill:#F9E79F,stroke:#000,stroke-width:2px;
    classDef frontend fill:#AED6F1,stroke:#000,stroke-width:2px;
    classDef gateway fill:#A9DFBF,stroke:#000,stroke-width:2px;
    classDef backend fill:#A3E4D7,stroke:#000,stroke-width:2px;
    classDef supporting fill:#D7BDE2,stroke:#000,stroke-width:2px;
    classDef dapr fill:#AFEEEE,stroke:#000,stroke-width:2px;
    classDef infra fill:#FAD7A0,stroke:#000,stroke-width:2px;

    %% Click Events
    click FE1 "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/web"
    click FE2 "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/bak/web"
    click AG "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/dotnet/api-gateway"
    click ID "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/dotnet/identity-server"
    click PC "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/rust/crates/product_catalog"
    click INV "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/rust/crates/inventory"
    click SC "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/dotnet/shopping-cart"
    click SALE "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/src/go/cmd/sale"
    click N8TCore "https://github.com/vietnam-devs/coolstore-microservices/blob/feature/upgrade-net6/src/dotnet/building-blocks/N8T.Core"
    click N8TInfra "https://github.com/vietnam-devs/coolstore-microservices/blob/feature/upgrade-net6/src/dotnet/building-blocks/N8T.Infrastructure"
    click DAPP "https://github.com/vietnam-devs/coolstore-microservices/blob/feature/upgrade-net6/components/appconfig.yaml"
    click DAPPub "https://github.com/vietnam-devs/coolstore-microservices/blob/feature/upgrade-net6/components/pubsub.yaml"
    click DAPStore "https://github.com/vietnam-devs/coolstore-microservices/blob/feature/upgrade-net6/components/statestore.yaml"
    click TYE "https://github.com/vietnam-devs/coolstore-microservices/blob/feature/upgrade-net6/tye.yaml"
    click DEPLOY "https://github.com/vietnam-devs/coolstore-microservices/tree/feature/upgrade-net6/deploys/"
```
