# raidoh/truebit-retire-mint-api architecture

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

- Interactive diagram: https://gitdiagram.com/raidoh/truebit-retire-mint-api
- Repository: https://github.com/raidoh/truebit-retire-mint-api

## Overview

##### Main Components

a) Server Layer:
- HTTP Server (from cmd/server)
- Router & API Handlers (from internal/api)
- Configuration Management (from internal/config)

b) Service Layer:
- Truebit Calculator Service (from internal/service)
- Ethereum Client Integration (from internal/client)

c) External Dependencies:
- Ethereum Network
- Environment Configuration (.env)

**[Client Layer]**

- ▼
**[API Layer]**

- ▼
**[Service Layer] ←→ [Ethereum Network]**

##### Detailed Component Breakdown

a) Client Layer (Top):
- Use cloud symbols for external access points

b) API Layer (Middle):
- Rectangle for Router (internal/api/router.go)
- Connected to Handlers (internal/api/handlers.go)
- REST endpoint (/truebit)

c) Service Layer (Bottom):
- Rectangle for Truebit Service (internal/service/truebit.go)
- Rectangle for Ethereum Client (internal/client/ethereum.go)
- Database symbol for configuration store

##### Connection and Flow Representation

- Incoming HTTP requests from clients to API
- Internal flow from handlers to services
- Communication between Ethereum client and external network
- Configuration loading paths

##### Additional Elements

Include:
- Version/environment indicators
- Clear labeling of all components
- Data flow direction indicators

##### Technical Details to Highlight

- REST endpoint (/truebit)
- Environment configuration dependencies
- Integration points with Ethereum network
- Utility package usage (pkg/utils)

##### Specific Implementation Notes

- The separation between API, service, and client layers
- The role of the Ethereum client in calculations
- Configuration management flow
- The simplicity and focused nature of the calculator service

Remember to:
- Keep the main calculation flow clear and central
- Error handling paths
- Where environment variables are used
- Public vs internal package boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External
        Client[Client/Browser]
        Ethereum[Ethereum Network]:::external
    end

    subgraph API_Layer
        Server["HTTP Server"]:::server
        Router["API Router"]:::router
        Handlers["API Handlers"]:::handlers
        Endpoint["/truebit Endpoint"]:::api
    end

    subgraph Service_Layer
        Calculator["Truebit Calculator Service"]:::service
        EthClient["Ethereum Client"]:::client
        Models["Data Models"]:::models
    end

    subgraph Config_Layer
        Config["Configuration Management"]:::config
        EnvFile["Environment Config"]:::config
        Utils["Utility Functions"]:::utils
    end

    %% Connections
    Client --> Server
    Server --> Router
    Router --> Handlers
    Handlers --> Endpoint
    Endpoint --> Calculator
    Calculator --> EthClient
    EthClient --> Ethereum
    Calculator --> Models
    Config --> Server
    Config --> Calculator
    Config --> EthClient
    EnvFile --> Config
    Calculator --> Utils
    EthClient --> Utils

    %% Styles
    classDef external fill:#C0C0C0,stroke:#333,stroke-width:2px
    classDef server fill:#B0E0E6,stroke:#333,stroke-width:2px
    classDef router fill:#98FB98,stroke:#333,stroke-width:2px
    classDef handlers fill:#98FB98,stroke:#333,stroke-width:2px
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef service fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef client fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef models fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef config fill:#E6E6FA,stroke:#333,stroke-width:2px
    classDef utils fill:#F0E68C,stroke:#333,stroke-width:2px

    %% Click Events
    click Server "https://github.com/raidoh/truebit-retire-mint-api/blob/main/cmd/server/main.go"
    click Router "https://github.com/raidoh/truebit-retire-mint-api/blob/main/internal/api/router.go"
    click Handlers "https://github.com/raidoh/truebit-retire-mint-api/blob/main/internal/api/handlers.go"
    click Calculator "https://github.com/raidoh/truebit-retire-mint-api/blob/main/internal/service/truebit.go"
    click EthClient "https://github.com/raidoh/truebit-retire-mint-api/blob/main/internal/client/ethereum.go"
    click Config "https://github.com/raidoh/truebit-retire-mint-api/blob/main/internal/config/config.go"
    click EnvFile "https://github.com/raidoh/truebit-retire-mint-api/blob/main/.env"
    click Models "https://github.com/raidoh/truebit-retire-mint-api/blob/main/internal/models/types.go"
    click Utils "https://github.com/raidoh/truebit-retire-mint-api/blob/main/pkg/utils/formatter.go"
```
