# tokopedia/gripmock architecture

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

- Interactive diagram: https://gitdiagram.com/tokopedia/gripmock
- Repository: https://github.com/tokopedia/gripmock

## Overview

##### Main Components

a) Core Components:
- gRPC Server (Port 4770)
- Stub HTTP Server (Port 4771)
- Protoc Plugin Generator
- Storage Layer

b) External Interfaces:
- Client gRPC Connections
- HTTP Stub Management API
- Proto File Input
- Stub File Input

- Client Layer                                         |

- gRPC Clients  |  |    HTTP Clients   |  |   Proto Files   |  |    Stub Files    |  |

- ↓

- GripMock Core                                        |

- gRPC Server   |←-|    Stub Server    |                                             |
- (Port 4770)  |  |    (Port 4771)    |                                            |

- ↑                     ↑                                                        |

- Generated Code |  |   Storage Layer   |                                             |

- ↑

- Generation Layer                                        |

- protoc-gen-gripmock  |  |           Proto Compiler               |                 |

##### Important Details

a) API Endpoints:
**Stub Server (4771):**
- GET /
- POST /add
- POST /find
- GET /clear

b) Data Flow Markers:
- Client → gRPC Server (4770)
- HTTP Client → Stub Server (4771)
- gRPC Server ↔ Stub Server
- Proto Files → Generator
- Generated Code → gRPC Server

##### Implementation Details

- Example implementations (/example directory)
- Protocol buffer generation (/protogen directory)
- Core mock server implementation (gripmock.go)
- Stub handling (stub directory)

##### Architectural Patterns to Highlight

- Service-based architecture
- Plugin-based code generation
- RESTful stub management
- Dynamic configuration support

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph CL[Client Layer]
        GC[gRPC Clients]:::client
        HC[HTTP Clients]:::client
        PF[Proto Files]:::input
        SF[Stub Files]:::input
    end

    %% GripMock Core Layer
    subgraph GM[GripMock Core]
        GS["gRPC Server<br/>(Port 4770)"]:::server
        SS["Stub Server<br/>(Port 4771)"]:::server
        SL[Storage Layer]:::storage
        GCode[Generated Code]:::generated
    end

    %% Generation Layer
    subgraph GL[Generation Layer]
        PG[protoc-gen-gripmock]:::generator
        PC[Proto Compiler]:::generator
        GT[Generator Template]:::generator
    end

    %% Example Implementations
    subgraph EX[Example Implementations]
        SG[Simple gRPC]:::example
        ST[Streaming]:::example
        MP[Multi-package]:::example
        WK[Well-known Types]:::example
    end

    %% Relationships
    GC --> GS
    HC --> SS
    PF --> PC
    SF --> SL
    SS <--> GS
    PC --> PG
    PG --> GCode
    GCode --> GS
    SS --> SL
    PG --> GT

    %% Click Events
    click GS "https://github.com/tokopedia/gripmock/blob/master/gripmock.go"
    click SL "https://github.com/tokopedia/gripmock/blob/master/stub/storage.go"
    click SS "https://github.com/tokopedia/gripmock/blob/master/stub/stub.go"
    click PG "https://github.com/tokopedia/gripmock/blob/master/protoc-gen-gripmock/generator.go"
    click GT "https://github.com/tokopedia/gripmock/blob/master/protoc-gen-gripmock/server.tmpl"
    click GCode "https://github.com/tokopedia/gripmock/tree/master/protogen/example/"
    click SG "https://github.com/tokopedia/gripmock/tree/master/example/simple/"
    click ST "https://github.com/tokopedia/gripmock/tree/master/example/stream/"
    click MP "https://github.com/tokopedia/gripmock/tree/master/example/multi-package/"
    click WK "https://github.com/tokopedia/gripmock/tree/master/example/well_known_types/"

    %% Styles
    classDef server fill:#2374f7,stroke:#000,stroke-width:2px,color:#fff
    classDef client fill:#85d075,stroke:#000,stroke-width:2px
    classDef input fill:#ffd351,stroke:#000,stroke-width:2px
    classDef storage fill:#ff9d5c,stroke:#000,stroke-width:2px
    classDef generator fill:#f7b32b,stroke:#000,stroke-width:2px
    classDef generated fill:#c9b1ff,stroke:#000,stroke-width:2px
    classDef example fill:#b5e2fa,stroke:#000,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Server Components]:::server
        L2[Client Interfaces]:::client
        L3[Input Files]:::input
        L4[Storage Components]:::storage
        L5[Generator Components]:::generator
        L6[Generated Code]:::generated
        L7[Examples]:::example
    end
```
