# chinh00/cshop architecture

> Architecture diagram of the GitHub repository chinh00/cshop, 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/chinh00/cshop
- Repository: https://github.com/chinh00/cshop

## Overview

##### Main Components
- API/Gateway Layer: Represent YARP as your reverse proxy/gateway component which stands at the entry point for external client requests.
- Microservices: Each of the services (Catalog, Basket, Order, Identity, Notification, Payment, Shipping, Comment, UserManager, Search, and Proxy/AppGateway) should be drawn as individual bounded contexts.
- Shared/Building Blocks: Include an infrastructure or “BuildingBlock” layer that holds shared contracts, domain components, repository abstractions, and integration event definitions.
- Communication Infrastructure: Show Kafka as the central event bus. Include Debezium for CDC and the Schema Registry to indicate how messages are versioned and validated.
- Data Stores: Represent the SQL Server (and possibly MongoDB in some services like Notification or Comment) as the prevalent persistent storage. Note any separate database contexts, outbox tables, migration services etc.
- Caching: Include Redis as the caching layer visible to services that require fast data retrieval.
- Internal Communication: Include gRPC channels (and Minimal APIs) between services handling internal or real-time communication.

##### Relationships and Interactions
- That each microservice both exposes its own HTTP endpoints (via Minimal Web APIs or gRPC) and communicates asynchronously via Kafka.
- That CDC (Debezium) taps into the SQL Server to publish events into Kafka for other services to consume.

##### Architectural Patterns and Design Principles
- Use of the Mediator pattern (via MediatR) within services to decouple command/query handling from controllers/services.
- That FluentValidation is plugged into the pipeline for input verification.
- Microservices architecture with a focus on domain-driven design (several services have “Domain”, “Application”, “Infrastructure” folders) as well as integration using event-driven patterns.

##### Relevant Technologies & Frameworks
- Technologies (Kafka, Debezium, Schema Registry, Redis, YARP, gRPC, Minimal API, Docker Compose).
- For each microservice, if space allows, you might note that they use containerized deployments (Dockerfiles are present) and that they have distinct project structures (separation between Application, Domain, and Infrastructure folders).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External & Presentation Layer"
        A("External Client"):::external
        GW("API Gateway (YARP)"):::gateway
        WC("Web Client (Next.js)"):::client
    end
    A -->|"HTTP"| GW
    GW -->|"Routes"| WC

    subgraph "Microservices Layer"
        C("Catalog Service"):::service
        B("Basket Service"):::service
        O("Order Service"):::service
        I("IdentityServer Service"):::service
        N("Notification Service"):::service
        P("Payment Service"):::service
        S("Shipping Service"):::service
        M("Comment Service"):::service
        U("UserManager Service"):::service
        Se("Search Service"):::service
    end
    GW -->|"Forwards"| C
    GW -->|"Forwards"| B
    GW -->|"Forwards"| O
    GW -->|"Forwards"| I
    GW -->|"Forwards"| N
    GW -->|"Forwards"| P
    GW -->|"Forwards"| S
    GW -->|"Forwards"| M
    GW -->|"Forwards"| U
    GW -->|"Forwards"| Se

    subgraph "Shared & Integration"
        SB("Shared / Building Blocks"):::shared
        CI("Integration Contracts & CDC/gRPC"):::integration
        KB("Kafka Event Bus"):::integration
        DB("Debezium CDC"):::integration
        SR("Schema Registry"):::integration
        GC("gRPC Channel"):::integration
    end
    C -->|"Uses"| SB
    B -->|"Uses"| SB
    O -->|"Uses"| SB
    I -->|"Uses"| SB
    N -->|"Uses"| SB
    P -->|"Uses"| SB
    S -->|"Uses"| SB
    M -->|"Uses"| SB
    U -->|"Uses"| SB
    Se -->|"Uses"| SB

    C -->|"Publishes"| KB
    B -->|"Publishes"| KB
    O -->|"Publishes"| KB
    I -->|"Publishes"| KB
    N -->|"Publishes"| KB
    P -->|"Publishes"| KB
    S -->|"Publishes"| KB
    M -->|"Publishes"| KB
    U -->|"Publishes"| KB
    Se -->|"Publishes"| KB

    C -->|"gRPC"| GC
    B -->|"gRPC"| GC
    O -->|"gRPC"| GC
    I -->|"gRPC"| GC
    N -->|"gRPC"| GC
    P -->|"gRPC"| GC
    S -->|"gRPC"| GC
    M -->|"gRPC"| GC
    U -->|"gRPC"| GC
    Se -->|"gRPC"| GC

    subgraph "Data Stores"
        SQL("SQL Server"):::database
        MDB("MongoDB"):::database
        RC("Redis Cache"):::cache
    end
    C -->|"Reads/Writes"| SQL
    C -->|"Caches"| RC

    B -->|"Reads/Writes"| SQL
    B -->|"Caches"| RC

    O -->|"Reads/Writes"| SQL
    O -->|"Caches"| RC

    I -->|"Reads/Writes"| SQL
    I -->|"Caches"| RC

    N -->|"Reads/Writes"| SQL
    N -->|"Caches"| RC
    N -->|"Uses"| MDB

    P -->|"Reads/Writes"| SQL
    P -->|"Caches"| RC

    S -->|"Reads/Writes"| SQL
    S -->|"Caches"| RC

    M -->|"Reads/Writes"| SQL
    M -->|"Caches"| RC
    M -->|"Uses"| MDB

    U -->|"Reads/Writes"| SQL
    U -->|"Caches"| RC

    Se -->|"Reads/Writes"| SQL
    Se -->|"Caches"| RC

    SQL -->|"CDC"| DB
    DB -->|"Publishes"| KB
    KB -->|"Versioning"| SR

    subgraph "Deployment"
        DC("Docker Compose"):::deployment
    end
    GW -->|"Deployed"| DC
    WC -->|"Deployed"| DC
    C  -->|"Deployed"| DC
    B  -->|"Deployed"| DC
    O  -->|"Deployed"| DC
    I  -->|"Deployed"| DC
    N  -->|"Deployed"| DC
    P  -->|"Deployed"| DC
    S  -->|"Deployed"| DC
    M  -->|"Deployed"| DC
    U  -->|"Deployed"| DC
    Se -->|"Deployed"| DC
    SB -->|"Deployed"| DC
    CI -->|"Deployed"| DC
    KB -->|"Deployed"| DC
    DB -->|"Deployed"| DC
    SR -->|"Deployed"| DC
    RC -->|"Deployed"| DC
    GC -->|"Deployed"| DC

    click GW "https://github.com/chinh00/cshop/tree/main/src/Services/Proxy/AppGateway"
    click WC "https://github.com/chinh00/cshop/tree/main/src/Services/Web/cshopclient"
    click C "https://github.com/chinh00/cshop/tree/main/src/Services/Catalog"
    click B "https://github.com/chinh00/cshop/tree/main/src/Services/Basket"
    click O "https://github.com/chinh00/cshop/tree/main/src/Services/Order"
    click I "https://github.com/chinh00/cshop/blob/main/src/Services/IdentityServer/Identity.Api"
    click N "https://github.com/chinh00/cshop/tree/main/src/Services/Notification"
    click P "https://github.com/chinh00/cshop/tree/main/src/Services/Payment"
    click S "https://github.com/chinh00/cshop/tree/main/src/Services/Shipping"
    click M "https://github.com/chinh00/cshop/tree/main/src/Services/Comment"
    click U "https://github.com/chinh00/cshop/tree/main/src/Services/UserManager"
    click Se "https://github.com/chinh00/cshop/tree/main/src/Services/Search"
    click SB "https://github.com/chinh00/cshop/tree/main/src/BuildingBlock"
    click CI "https://github.com/chinh00/cshop/blob/main/src/BuildingBlock/cShop.Contracts"
    click RC "https://github.com/chinh00/cshop/tree/main/src/BuildingBlock/cShop.Infrastructure/Cache/Redis"

    classDef external fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef gateway fill:#aed6f1,stroke:#2980b9,stroke-width:2px;
    classDef client fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
    classDef service fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
    classDef shared fill:#f5eef8,stroke:#8e44ad,stroke-width:2px;
    classDef integration fill:#e8f8f5,stroke:#16a085,stroke-width:2px;
    classDef database fill:#fef9e7,stroke:#f1c40f,stroke-width:2px;
    classDef cache fill:#fcf3cf,stroke:#f39c12,stroke-width:2px;
    classDef deployment fill:#ebedef,stroke:#7f8c8d,stroke-width:2px;
```
