# gobicycle/bicycle architecture

> Architecture diagram of the GitHub repository gobicycle/bicycle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gobicycle/bicycle
- Repository: https://github.com/gobicycle/bicycle

## Overview

##### Main System Components

a) Core Processing Components:
- Payment Processor Service (Main Application)
- TON Blockchain Node (External Dependency)
- PostgreSQL Database
- Optional Components:
- RabbitMQ for notifications
- Grafana for monitoring
- Webhook notification system

b) Wallet Components:
- Hot Wallet (Main processing wallet)
- Cold Wallet (Security storage)
- Deposit Addresses (User payment endpoints)

##### Architecture Representation

TOP LAYER:
- External Interfaces (REST API, Webhooks)
- Monitoring (Grafana, Prometheus)

MIDDLE LAYER:
- Core Processing Components
- Block Scanner
- Withdrawal Processor
- Payment Processor
- Queue Manager

BOTTOM LAYER:
- Storage Layer (PostgreSQL)
- Blockchain Interface Layer

##### Component Relationships

- Blockchain interactions (special connector)

##### Specific Implementation Details

a) Payment Flow:
- User → Deposit Address → Hot Wallet → Cold Wallet
- Withdrawal process from Hot Wallet to user wallets

b) Monitoring Flow:
- Metrics collection
- Grafana dashboards
- Prometheus monitoring

c) Security Boundaries:
- API authentication zones
- Blockchain verification boundaries
- Wallet security levels

##### Technical Elements

Specific components from the codebase:
- API Handlers (from /api)
- Blockchain Interface (from /blockchain)
- Core Processing (from /core)
- Database Layer (from /db)
- Queue Management (from /queue)
- Webhook System (from /webhook)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef storage fill:#FFD700,stroke:#333,stroke-width:2px
    classDef monitoring fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef queue fill:#FFA500,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef security fill:#FF6B6B,stroke:#333,stroke-width:2px

    %% External Layer
    subgraph External
        API[REST API Interface]:::api
        TON[TON Blockchain Node]:::external
        WEBHOOKS[Webhook System]:::api
    end

    %% Monitoring Layer
    subgraph Monitoring
        GRAFANA[Grafana Dashboards]:::monitoring
        PROM[Prometheus]:::monitoring
        METRICS[Metrics Collector]:::monitoring
    end

    %% Core Processing Layer
    subgraph Core
        MAIN[Main Service]:::core
        SCANNER[Block Scanner]:::core
        WITHDRAWAL[Withdrawal Processor]:::core
        WALLET[Wallet Management]:::core
        CONFIG[Configuration]:::core
        AUDIT[Audit Logger]:::core
        SHARD[Shard Tracker]:::core
    end

    %% Storage Layer
    subgraph Storage
        DB[(PostgreSQL)]:::storage
        QUEUE{RabbitMQ}:::queue
    end

    %% Relationships
    API --> |Requests| MAIN
    MAIN --> |Process| SCANNER
    SCANNER --> |Monitor| TON
    WITHDRAWAL --> |Process| TON
    WALLET --> |Manage| TON
    MAIN --> |Store| DB
    MAIN --> |Queue| QUEUE
    QUEUE --> |Notify| WEBHOOKS
    METRICS --> |Collect| PROM
    PROM --> |Display| GRAFANA
    SHARD --> |Track| TON
    AUDIT --> |Log| DB

    %% Click Events
    click API "https://github.com/gobicycle/bicycle/blob/master/api/handlers.go"
    click SCANNER "https://github.com/gobicycle/bicycle/blob/master/core/block_scanner.go"
    click WITHDRAWAL "https://github.com/gobicycle/bicycle/blob/master/core/withdrawal_processor.go"
    click WALLET "https://github.com/gobicycle/bicycle/blob/master/core/wallets.go"
    click DB "https://github.com/gobicycle/bicycle/blob/master/deploy/db/01_init.up.sql"
    click QUEUE "https://github.com/gobicycle/bicycle/blob/master/queue/queue.go"
    click WEBHOOKS "https://github.com/gobicycle/bicycle/blob/master/webhook/webhook.go"
    click METRICS "https://github.com/gobicycle/bicycle/blob/master/metrics/metrics.go"
    click GRAFANA "https://github.com/gobicycle/bicycle/blob/master/deploy/grafana/main/dashboards/Payments.json"
    click PROM "https://github.com/gobicycle/bicycle/blob/master/deploy/prometheus/main/prometheus.yml"
    click MAIN "https://github.com/gobicycle/bicycle/blob/master/cmd/processor/main.go"
    click SHARD "https://github.com/gobicycle/bicycle/blob/master/blockchain/shard_tracker.go"
    click AUDIT "https://github.com/gobicycle/bicycle/blob/master/audit/log.go"
    click CONFIG "https://github.com/gobicycle/bicycle/blob/master/config/config.go"

    %% Legend
    subgraph Legend
        L1[API Component]:::api
        L2[Core Service]:::core
        L3[Storage]:::storage
        L4[Monitoring]:::monitoring
        L5[Queue]:::queue
        L6[External Service]:::external
    end
```
