# shubhtr/grpc-typescript-complete architecture

> Architecture diagram of the GitHub repository shubhtr/grpc-typescript-complete, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shubhtr/grpc-typescript-complete
- Repository: https://github.com/shubhtr/grpc-typescript-complete

## Overview

Project Type: This is a microservices-based application that uses gRPC for communication between client and server components, with two main services: Greeter and User Service.

##### Main Components

a. Client Layer:
- A "gRPC Client" component containing:
- Greeter Client Service
- User Client Service
- Proto-generated client stubs (highlight the proto folder)
- Different user operations (GetUser, CreateUsers, GetUsers)

b. Server Layer:
- A "gRPC Server" component containing:
- Greeter Service Implementation
- User Service Implementation
- Proto-generated server stubs
- Connection to the database (from db.ts)

c. Protocol Buffer Definitions:
- helloworld.proto
- user.proto

##### Component Relationships

- Proto files feeding into both client and server through build scripts
- Database connection from the server

##### Specific Implementation Details

- Blue: Client-side components
- Green: Server-side components
- Yellow: Proto definitions
- Purple: Database
- Gray: Build/compilation processes

**[Proto Definitions Layer]**
- ↓ ↓

- (build scripts)
- ↓ ↓
**[Client Layer] ←→ [Server Layer] → [Database]**

##### Additional Elements

a. Technology Stack Indicators:
- TypeScript
- gRPC
- Node.js
- Protocol Buffers

b. Service Definitions:
- User Service:
- GetUser
- CreateUsers
- GetUsers

- Greeter Service:
- SayHello

##### Implementation Notes

- Notes about the proto compilation process
- TypeScript compilation flow

##### Architectural Patterns to Highlight

- Service-oriented architecture (SOA)
- RPC communication pattern
- Clear separation between client and server
- Protocol Buffer contract-first approach

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Proto
        ProtoFiles["Protocol Buffer Definitions"]
        HelloProto["helloworld.proto"]
        UserProto["user.proto"]
    end

    subgraph BuildScripts
        ClientBuilder["Client Proto Builder"]
        ServerBuilder["Server Proto Builder"]
    end

    subgraph ClientLayer
        Client["gRPC Client"]:::client
        ClientStubs["Generated Client Stubs"]:::client
        GetUser["GetUser Operation"]:::client
        CreateUsers["CreateUsers Operation"]:::client
        GetAllUsers["GetUsers Operation"]:::client
    end

    subgraph ServerLayer
        Server["gRPC Server"]:::server
        ServerStubs["Generated Server Stubs"]:::server
        GreeterImpl["Greeter Service Implementation"]:::server
        UserImpl["User Service Implementation"]:::server
        DB[(Database)]:::database
    end

    %% Relationships
    ProtoFiles --> HelloProto
    ProtoFiles --> UserProto
    HelloProto & UserProto --> |Proto Compilation| ClientBuilder
    HelloProto & UserProto --> |Proto Compilation| ServerBuilder
    ClientBuilder --> ClientStubs
    ServerBuilder --> ServerStubs
    
    Client --> GetUser
    Client --> CreateUsers
    Client --> GetAllUsers
    
    GetUser & CreateUsers & GetAllUsers --> |gRPC Calls| Server
    Server --> DB
    Server --> GreeterImpl
    Server --> UserImpl

    %% Click Events
    click ProtoFiles "https://github.com/shubhtr/grpc-typescript-complete/tree/main/proto/"
    click HelloProto "https://github.com/shubhtr/grpc-typescript-complete/blob/main/proto/helloworld.proto"
    click UserProto "https://github.com/shubhtr/grpc-typescript-complete/blob/main/proto/user.proto"
    click Client "https://github.com/shubhtr/grpc-typescript-complete/blob/main/client/index.ts"
    click GetUser "https://github.com/shubhtr/grpc-typescript-complete/blob/main/client/user/get-user.ts"
    click CreateUsers "https://github.com/shubhtr/grpc-typescript-complete/blob/main/client/user/create-users.ts"
    click GetAllUsers "https://github.com/shubhtr/grpc-typescript-complete/blob/main/client/user/all-users.ts"
    click ClientStubs "https://github.com/shubhtr/grpc-typescript-complete/tree/main/client/proto/"
    click Server "https://github.com/shubhtr/grpc-typescript-complete/blob/main/server/index.ts"
    click ServerStubs "https://github.com/shubhtr/grpc-typescript-complete/tree/main/server/proto/"
    click DB "https://github.com/shubhtr/grpc-typescript-complete/blob/main/server/db.ts"
    click ClientBuilder "https://github.com/shubhtr/grpc-typescript-complete/blob/main/proto/build-client.sh"
    click ServerBuilder "https://github.com/shubhtr/grpc-typescript-complete/blob/main/proto/build-server.sh"

    %% Styles
    classDef client fill:#3498db,stroke:#2980b9,color:#fff
    classDef server fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef proto fill:#f1c40f,stroke:#f39c12,color:#000
    classDef database fill:#9b59b6,stroke:#8e44ad,color:#fff
    classDef builder fill:#95a5a6,stroke:#7f8c8d,color:#fff

    %% Legend
    subgraph Legend
        ClientLegend["Client Components"]:::client
        ServerLegend["Server Components"]:::server
        ProtoLegend["Proto Definitions"]:::proto
        DBLegend["Database"]:::database
        BuildLegend["Build Process"]:::builder
    end
```
