# th3y3m/grpc-multi-server-demo architecture

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

- Interactive diagram: https://gitdiagram.com/th3y3m/grpc-multi-server-demo
- Repository: https://github.com/th3y3m/grpc-multi-server-demo

## Overview

##### Project type and purpose
- This is a microservices-style demo (“grpc-multi-server-demo”) built with .NET, showcasing an API Gateway fronting two gRPC back-end services (Category and Product), sharing Protobuf contracts, using Redis caching, and EF Core–backed persistence.

##### File structure
- Top-level projects:
- ApiGateway – ASP.NET Core HTTP API + Redis cache + proxy layer
- CategoryGrpcServer – gRPC service for “Category” with Application, Domain, Infrastructure layers
- ProductGrpcServer – gRPC service for “Product” with CQRS-style Commands/Queries
- GrpcContracts – shared .proto definitions and repository/UoW abstractions
- Notice cross-cutting concerns:
- Caching (CacheRedis)
- Business logic vs proxy layer in ApiGateway
- EF Core Migrations in each gRPC server’s Infrastructure
- Middleware for error wrapping in the Gateway

##### README for additional insights
- README is minimal, but project name and structure strongly imply an API Gateway + multiple gRPC servers demo.
- The purpose: illustrate multi-server gRPC integration, shared contracts, caching, and clean layering.

- Rectangles for logical components (Gateway, Services)
- Labels & details:
- Caching step (Cache key lookup → hit/miss)
- EF Core migrations in service infra

##### Essential elements
- Clear component boundaries with labels
- Annotations for patterns (e.g., “CQRS”, “UnitOfWork”)
- Call out middleware in Gateway (ErrorWrappingApiMiddleware)

## Diagram (Mermaid)

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

    %% API Gateway Layer
    subgraph "API Gateway"
        direction TB
        AG["API Gateway (HTTP API)"]:::gateway
        Middleware["ErrorWrappingApiMiddleware"]:::gateway
        Controller["CategoryController"]:::gateway
        Business["CategoryBusiness"]:::gateway
        Proxy["CategoryServiceProxy"]:::gateway
        CacheLayer["CacheRedis"]:::cache
        Redis[(Redis Cache)]:::cache
    end

    %% Category gRPC Service
    subgraph "Category gRPC Service"
        direction TB
        CatAPI["CategoryServiceImpl"]:::service
        CatApp["GetCategoryByIdQuery/Handler"]:::service
        CatDomain["Category Entity"]:::service
        CatInfra["AppDbContext"]:::service
        CatDB[(CategoryDB)]:::db
    end

    %% Product gRPC Service
    subgraph "Product gRPC Service"
        direction TB
        ProdAPI["ProductServiceImpl"]:::service
        ProdAppCmd["Commands & Handlers"]:::service
        ProdAppQry["Queries & Handlers"]:::service
        ProdDomain["Product Entity"]:::service
        ProdInfra["AppDbContext"]:::service
        ProdDB[(ProductDB)]:::db
    end

    %% Shared Contracts
    subgraph "GrpcContracts (Shared)"
        direction TB
        Protos["Protobuf Schemas"]:::shared
        SharedInt["Repository/UoW Interfaces"]:::shared
        SharedImpl["GenericRepository & UnitOfWork"]:::shared
    end

    %% Data Flows
    Client -->|HTTP/JSON| AG
    AG -->|uses Middleware| Middleware
    AG -->|handles request| Controller
    Controller -->|calls| Business
    Business -->|uses cache| CacheLayer
    CacheLayer -->|lookup| Redis
    Business -->|on miss| Proxy
    Proxy -->|gRPC| CatAPI
    Proxy -->|gRPC| ProdAPI
    CatAPI -->|executes| CatApp
    CatApp -->|uses| CatDomain
    CatDomain -->|persists via| CatInfra
    CatInfra -->|migrates+queries| CatDB
    ProdAPI -->|executes commands| ProdAppCmd
    ProdAPI -->|executes queries| ProdAppQry
    ProdAppCmd -->|uses| ProdDomain
    ProdAppQry -->|uses| ProdDomain
    ProdDomain -->|persists via| ProdInfra
    ProdInfra -->|migrates+queries| ProdDB

    %% Dependencies on Shared Contracts
    Proxy -.->|uses| Protos
    CatAPI -.->|implements| Protos
    ProdAPI -.->|implements| Protos
    CatApp -.->|uses| SharedInt
    ProdAppCmd -.->|uses| SharedInt
    ProdAppQry -.->|uses| SharedInt
    SharedImpl -.->|implements| SharedInt

    %% Click events
    click Controller "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/Controllers/CategoryController.cs"
    click Business "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/Business/Category/CategoryBusiness.cs"
    click Proxy "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/ProxyService/Category/CategoryServiceProxy.cs"
    click CacheLayer "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/CacheRedis/Cache/CacheRedis.cs"
    click Redis "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/CacheRedis/CacheKeys.cs"
    click Middleware "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/Middleware/ErrorWrappingApiMiddleware.cs"
    click AG "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ApiGateway/Program.cs"
    click Protos "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/GrpcContracts/Protos/category.proto"
    click SharedInt "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/GrpcContracts/Shared/Interfaces/IUnitOfWork.cs"
    click SharedImpl "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/GrpcContracts/Shared/UnitOfWork.cs"
    click CatAPI "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/CategoryGrpcServer/API/CategoryServiceImpl.cs"
    click CatApp "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/CategoryGrpcServer/Application/Handlers/GetCategoryByIdHandler.cs"
    click CatDomain "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/CategoryGrpcServer/Domain/Entities/Category.cs"
    click CatInfra "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/CategoryGrpcServer/Infrastructure/Persistence/AppDbContext.cs"
    click ProdAPI "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ProductGrpcServer/API/ProductServiceImpl.cs"
    click ProdAppCmd "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ProductGrpcServer/Application/Handlers/CreateProductHandler.cs"
    click ProdAppQry "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ProductGrpcServer/Application/Handlers/GetProductByIdHandler.cs"
    click ProdDomain "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ProductGrpcServer/Domain/Entities/Product.cs"
    click ProdInfra "https://github.com/th3y3m/grpc-multi-server-demo/blob/main/ProductGrpcServer/Infrastructure/Persistence/AppDbContext.cs"

    %% Styles
    classDef gateway fill:#daf7dc,stroke:#2ecc71,stroke-width:2px
    classDef service fill:#d6e0f0,stroke:#3498db,stroke-width:2px
    classDef cache fill:#ffe5b4,stroke:#e67e22,stroke-width:2px
    classDef db fill:#ececec,stroke:#7f8c8d,stroke-width:2px
    classDef shared fill:#f0e5ff,stroke:#9b59b6,stroke-width:2px
    classDef external fill:#ffffff,stroke:#34495e,stroke-width:2px,stroke-dasharray: 5 5
```
