# ckadluba/grpcdemos architecture

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

- Interactive diagram: https://gitdiagram.com/ckadluba/grpcdemos
- Repository: https://github.com/ckadluba/grpcdemos

## Overview

##### Main Components
- Client: Represents the application that initiates a gRPC call. For example, in SimpleCalc, AsyncChat, or MinimalHello, the client sends requests and displays results.
- Service Host: The server-side ASP.NET Core application that hosts the gRPC service. This component includes configuration files (like the appsettings.json files and launchSettings.json) and the Startup.cs where service and middleware configurations (logging, endpoints, server reflection, etc.) are set up.
- Shared/Service Libraries: These components contain the business logic and the .proto definitions (or generated stubs) that are shared between the client and server. They represent the contract (IDL via Protobuf) and the implementation of the gRPC service.

##### Relationships and Interactions
- The service host, in turn, utilizes the service library (which implements the service logic) to process the request.
- The shared library (or proto files) ties both ends to the same contract and protocol buffers definitions.
- Specific samples with unique behaviors: bidirectional streaming for AsyncChat, deadline handling for Deadline, metadata exchange for Metadata, and differences in service lifetime patterns illustrated in LifeTime (per-call vs. singleton).

##### Architectural Patterns and Technologies
- That many of these apps are built on ASP.NET Core using either Microsoft’s Grpc.Net or Google’s Grpc.Core libraries.
- That the project leverages configuration files for runtime behavior (e.g., logging levels, HTTP/2 settings).
- How bidirectional streaming (AsyncChat) and unary calls (MinimalHello, SimpleCalc) are implemented.
- Mention the use of service reflection in ServerReflection and protocol definitions in the shared libraries that guide code generation.

##### Essential Elements
- “Client Application (e.g., AsyncChat.Client)” connects to “gRPC Service Host (e.g., AsyncChat.ServiceHost)”
- “Service Library (e.g., AsyncChat.ServiceLib)” which implements the defined gRPC service (e.g., ChatService and ChatHub) using the shared protocol definitions (“AsyncChat.SharedLib” containing Chat.proto).
- Optionally, indicate configuration / logging flows as a separate note.

##### Additional Technical Details
- If useful, annotate major ASP.NET Core artifacts such as Startup.cs, configuration files, and logging setups.
- Mention that most of the projects follow a similar structure based on the gRPC “gRPC Service” template from ASP.NET Core, and that the shared proto file dictates the contract with generated code both on the client and the server.
- You could include external dependencies (e.g., NuGet packages for Grpc.Core, Grpc.Net, etc.) as annotations if they play a key role in differentiating how each sample functions.

- The Client layer (several sample clients).
- The Server layer featuring the service host configured with ASP.NET Core.
- The Business Logic layer represented by service libraries.
- The Shared Contract layer (shared libraries housing the .proto files).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Applications Layer
    subgraph "Client Applications"
        AC_Client("AsyncChat Client"):::client
        AE_Client("AsyncEcho Client"):::client
        DL_Client("Deadline Client"):::client
        GW_Client("GrpcWeb Client"):::client
        LT_Client("LifeTime Client"):::client
        MD_Client("Metadata Client"):::client
        MGG_Client("MinimalGoogleGrpc Client"):::client
        MH_Client("MinimalHello Client"):::client
        SC_Client("SimpleCalc Client"):::client
    end

    %% gRPC Service Hosts Layer
    subgraph "gRPC Service Hosts"
        AC_Host("AsyncChat Service Host"):::host
        AE_Host("AsyncEcho Service Host"):::host
        DL_Host("Deadline Service"):::host
        GW_Host("GrpcWeb Service"):::host
        LT_Host_G("LifeTime Service Host (GoogleGrpc)"):::host
        LT_Host_PC("LifeTime Service Host (PerCall)"):::host
        LT_Host_S("LifeTime Service Host (Singleton)"):::host
        MD_Host("Metadata Service"):::host
        MGG_Host("MinimalGoogleGrpc Service"):::host
        MH_Host("MinimalHello Service"):::host
        SR_Host("Server Reflection Service"):::host
        SC_Host("SimpleCalc Service Host"):::host
    end

    %% Service Libraries Layer
    subgraph "Service Libraries"
        AC_Lib("AsyncChat ServiceLib"):::library
        AE_Lib("AsyncEcho ServiceLib"):::library
        LT_Lib("LifeTime ServiceLib"):::library
        MH_Lib("MinimalHello ServiceLib"):::library
        SC_Lib("SimpleCalc ServiceLib"):::library
    end

    %% Shared Contracts / Protos Layer
    subgraph "Shared Contracts/Protos"
        AC_Shared("AsyncChat SharedLib"):::shared
        AE_Shared("AsyncEcho SharedLib"):::shared
        DL_Proto("Deadline Protos"):::shared
        GW_Proto("GrpcWeb Protos"):::shared
        LT_Shared("LifeTime SharedLib"):::shared
        MD_Proto("Metadata Protos"):::shared
        MGG_Proto("MinimalGoogleGrpc Protos"):::shared
        MH_Proto("MinimalHello Protos"):::shared
        SC_Shared("SimpleCalc SharedLib"):::shared
    end

    %% Configuration / Startup Layer
    subgraph "Configuration/Startup"
        Config("Startup & Config"):::config
    end

    %% AsyncChat Sample
    AC_Client -->|"grpc_call"| AC_Host
    AC_Host -->|"uses"| AC_Lib
    AC_Lib -->|"contract"| AC_Shared
    AC_Host --> Config

    %% AsyncEcho Sample
    AE_Client -->|"grpc_call"| AE_Host
    AE_Host -->|"uses"| AE_Lib
    AE_Lib -->|"contract"| AE_Shared
    AE_Host --> Config

    %% Deadline Sample
    DL_Client -->|"grpc_call"| DL_Host
    DL_Host -->|"proto"| DL_Proto
    DL_Host --> Config

    %% GrpcWeb Sample
    GW_Client -->|"grpc_call"| GW_Host
    GW_Host -->|"proto"| GW_Proto
    GW_Host --> Config

    %% LifeTime Sample (multiple variants)
    LT_Client -->|"grpc_call"| LT_Host_G
    LT_Client -->|"grpc_call"| LT_Host_PC
    LT_Client -->|"grpc_call"| LT_Host_S
    LT_Host_G -->|"calls"| LT_Lib
    LT_Host_PC -->|"calls"| LT_Lib
    LT_Host_S -->|"calls"| LT_Lib
    LT_Lib -->|"contract"| LT_Shared
    LT_Host_G --> Config
    LT_Host_PC --> Config
    LT_Host_S --> Config

    %% Metadata Sample
    MD_Client -->|"grpc_call"| MD_Host
    MD_Host -->|"proto"| MD_Proto
    MD_Host --> Config

    %% MinimalGoogleGrpc Sample
    MGG_Client -->|"grpc_call"| MGG_Host
    MGG_Host -->|"proto"| MGG_Proto
    MGG_Host --> Config

    %% MinimalHello Sample
    MH_Client -->|"grpc_call"| MH_Host
    MH_Host -->|"calls"| MH_Lib
    MH_Lib -->|"contract"| MH_Proto
    MH_Host --> Config

    %% SimpleCalc Sample
    SC_Client -->|"grpc_call"| SC_Host
    SC_Host -->|"calls"| SC_Lib
    SC_Lib -->|"contract"| SC_Shared
    SC_Host --> Config

    %% Server Reflection (standalone service)
    SR_Host --> Config

    %% Click Events for Client Components
    click AC_Client "https://github.com/ckadluba/grpcdemos/blob/master/AsyncChat/AsyncChat.Client"
    click AE_Client "https://github.com/ckadluba/grpcdemos/blob/master/AsyncEcho/AsyncEcho.Client"
    click DL_Client "https://github.com/ckadluba/grpcdemos/blob/master/Deadline/Deadline.Client"
    click GW_Client "https://github.com/ckadluba/grpcdemos/blob/master/GrpcWeb/GrpcWeb.Client"
    click LT_Client "https://github.com/ckadluba/grpcdemos/blob/master/LifeTime/LifeTime.Client"
    click MD_Client "https://github.com/ckadluba/grpcdemos/blob/master/Metadata/Metadata.Client"
    click MGG_Client "https://github.com/ckadluba/grpcdemos/blob/master/MinimalGoogleGrpc/MinimalGoogleGrpc.Client"
    click MH_Client "https://github.com/ckadluba/grpcdemos/blob/master/MinimalHello/MinimalHello.Client"
    click SC_Client "https://github.com/ckadluba/grpcdemos/blob/master/SimpleCalc/SimpleCalc.Client"

    %% Click Events for Service Host Components
    click AC_Host "https://github.com/ckadluba/grpcdemos/blob/master/AsyncChat/AsyncChat.ServiceHost"
    click AE_Host "https://github.com/ckadluba/grpcdemos/blob/master/AsyncEcho/AsyncEcho.ServiceHost"
    click DL_Host "https://github.com/ckadluba/grpcdemos/blob/master/Deadline/Deadline.Service"
    click GW_Host "https://github.com/ckadluba/grpcdemos/blob/master/GrpcWeb/GrpcWeb.Service"
    click LT_Host_G "https://github.com/ckadluba/grpcdemos/blob/master/LifeTime/LifeTime.ServiceHostGoogleGrpc"
    click LT_Host_PC "https://github.com/ckadluba/grpcdemos/blob/master/LifeTime/LifeTime.ServiceHostPerCall"
    click LT_Host_S "https://github.com/ckadluba/grpcdemos/blob/master/LifeTime/LifeTime.ServiceHostSingleton"
    click MD_Host "https://github.com/ckadluba/grpcdemos/blob/master/Metadata/Metadata.Service"
    click MGG_Host "https://github.com/ckadluba/grpcdemos/blob/master/MinimalGoogleGrpc/MinimalGoogleGrpc.Service"
    click MH_Host "https://github.com/ckadluba/grpcdemos/blob/master/MinimalHello/MinimalHello.Service"
    click SR_Host "https://github.com/ckadluba/grpcdemos/blob/master/ServerReflection/ServerReflection.Service"
    click SC_Host "https://github.com/ckadluba/grpcdemos/blob/master/SimpleCalc/SimpleCalc.ServiceHost"

    %% Click Events for Service Library Components
    click AC_Lib "https://github.com/ckadluba/grpcdemos/blob/master/AsyncChat/AsyncChat.ServiceLib"
    click AE_Lib "https://github.com/ckadluba/grpcdemos/blob/master/AsyncEcho/AsyncEcho.ServiceLib"
    click LT_Lib "https://github.com/ckadluba/grpcdemos/blob/master/LifeTime/LifeTime.ServiceLib"
    click MH_Lib "https://github.com/ckadluba/grpcdemos/tree/master/MinimalHello/MinimalHello.Service/Services"
    click SC_Lib "https://github.com/ckadluba/grpcdemos/blob/master/SimpleCalc/SimpleCalc.ServiceLib"

    %% Click Events for Shared/Contract Components
    click AC_Shared "https://github.com/ckadluba/grpcdemos/blob/master/AsyncChat/AsyncChat.SharedLib"
    click AE_Shared "https://github.com/ckadluba/grpcdemos/blob/master/AsyncEcho/AsyncEcho.SharedLib"
    click DL_Proto "https://github.com/ckadluba/grpcdemos/tree/master/Deadline/Deadline.Service/Protos"
    click GW_Proto "https://github.com/ckadluba/grpcdemos/tree/master/GrpcWeb/GrpcWeb.Service/Protos"
    click LT_Shared "https://github.com/ckadluba/grpcdemos/blob/master/LifeTime/LifeTime.SharedLib"
    click MD_Proto "https://github.com/ckadluba/grpcdemos/tree/master/Metadata/Metadata.Service/Protos"
    click MGG_Proto "https://github.com/ckadluba/grpcdemos/tree/master/MinimalGoogleGrpc/MinimalGoogleGrpc.Service/Protos"
    click MH_Proto "https://github.com/ckadluba/grpcdemos/tree/master/MinimalHello/MinimalHello.Service/Protos"
    click SC_Shared "https://github.com/ckadluba/grpcdemos/blob/master/SimpleCalc/SimpleCalc.SharedLib"

    %% Styles
    classDef client fill:#DDEEFF,stroke:#000,stroke-width:1px;
    classDef host fill:#B3E5FC,stroke:#000,stroke-width:1px;
    classDef library fill:#C8E6C9,stroke:#000,stroke-width:1px;
    classDef shared fill:#FFECB3,stroke:#000,stroke-width:1px;
    classDef config fill:#E1BEE7,stroke:#000,stroke-width:1px;
```
