# headcrab/robin2 architecture

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

- Interactive diagram: https://gitdiagram.com/headcrab/robin2
- Repository: https://github.com/headcrab/robin2

## Overview

##### Main Components

a) Frontend Layer:
- Web Interface (located in /web directory)
- Templates Engine (web/templates)
- Static Assets (CSS, JavaScript, Images)

b) Backend Layer:
- API Handlers (internal/app/handlersApi.go, handlersApiV2.go)
- Web Handlers (internal/app/handlersWeb.go)
- Template Handlers (internal/app/handlersTemplate.go)

c) Core Services:
- Data Formatting Service (internal/format)
- Decoding Service (internal/decode)
- Cache Layer (internal/cache)
- Storage Layer (internal/store)

d) External Systems:
- ClickHouse Database
- Redis Cache
- Various SQL Databases (MySQL, MSSQL, Oracle)

**[Client Layer]**
- ↓ ↑
**[Web/API Layer]**
- ↓ ↑
**[Service Layer]**
- ↓ ↑
**[Data Layer]**

##### Component Relationships

- HTTP requests from clients to handlers
- Data flow between services
- Storage operations
- Cache interactions

##### Specific Implementation Details

a) Data Flow:
- Client requests → Middleware (logging, timing) → Handlers
- Handlers → Format Service → Data Store
- Cache interaction points
- Template rendering flow

b) Multiple Storage Options:
- Supported databases
- Primary storage (ClickHouse)
- Cache layer with Redis and in-memory options

c) Format Processors:
- Supported output formats (JSON, XML, HTML, Grafana)
- Format transformation flow

##### Key Features to Highlight

- Tag data retrieval system
- Template processing engine
- Data grouping and aggregation
- Tag classification system
- Logging system
- Configuration management

##### Additional Elements

Include:
- System boundaries
- External integration points
- Configuration components
- Deployment containers (based on docker-compose files)

##### Notes for Implementation

- Use standard UML notation where applicable
- Version information
- Scaling points
- Monitoring/logging points
- Cache boundaries
- Configuration reload paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
        API["API Client"]
    end

    subgraph Frontend["Frontend Layer"]
        WebUI["Web Interface"]:::frontend
        Templates["Templates Engine"]:::frontend
        Static["Static Assets"]:::frontend
    end

    subgraph API_Layer["API & Web Layer"]
        APIv1["API v1 Handler"]:::api
        APIv2["API v2 Handler"]:::api
        WebH["Web Handler"]:::api
        TempH["Template Handler"]:::api
    end

    subgraph Core["Core Services"]
        Format["Data Formatting"]:::service
        Decode["Decoding Service"]:::service
        Cache["Cache Layer"]:::service
        Storage["Storage Layer"]:::service
    end

    subgraph Caching["Cache Systems"]
        Redis[(Redis Cache)]:::cache
        MemCache["Memory Cache"]:::cache
        ByteCache["Memory Byte Cache"]:::cache
    end

    subgraph Databases["Database Layer"]
        Click[(ClickHouse)]:::db
        MySQL[(MySQL)]:::db
        MSSQL[(MSSQL)]:::db
        Oracle[(Oracle)]:::db
    end

    subgraph Support["Supporting Services"]
        Config["Configuration"]:::support
        Logger["Logger"]:::support
        ErrorH["Error Handler"]:::support
        Middle["Middleware"]:::support
        Utils["Utilities"]:::support
    end

    Browser --> WebUI
    API --> |HTTP/HTTPS| APIv1
    API --> |HTTP/HTTPS| APIv2
    
    WebUI --> WebH
    WebUI --> TempH
    Templates --> TempH
    Static --> WebH

    APIv1 & APIv2 & WebH & TempH --> Format
    Format --> Decode
    Decode --> Cache
    Cache --> Storage

    Cache --> Redis
    Cache --> MemCache
    Cache --> ByteCache

    Storage --> Click
    Storage --> MySQL
    Storage --> MSSQL
    Storage --> Oracle

    APIv1 & APIv2 & WebH & TempH --> Middle
    Middle --> Logger
    Middle --> ErrorH
    Middle --> Config
    Middle --> Utils

    %% Component Mappings
    click WebUI "https://github.com/Headcrab/robin2/tree/master/web/"
    click Templates "https://github.com/Headcrab/robin2/tree/master/web/templates/"
    click Static "https://github.com/Headcrab/robin2/tree/master/web/css/"
    click APIv1 "https://github.com/Headcrab/robin2/blob/master/internal/app/handlersApi.go"
    click APIv2 "https://github.com/Headcrab/robin2/blob/master/internal/app/handlersApiV2.go"
    click WebH "https://github.com/Headcrab/robin2/blob/master/internal/app/handlersWeb.go"
    click TempH "https://github.com/Headcrab/robin2/blob/master/internal/app/handlersTemplate.go"
    click Format "https://github.com/Headcrab/robin2/tree/master/internal/format/"
    click Decode "https://github.com/Headcrab/robin2/blob/master/internal/decode/decode.go"
    click Cache "https://github.com/Headcrab/robin2/tree/master/internal/cache/"
    click Storage "https://github.com/Headcrab/robin2/tree/master/internal/store/"
    click Click "https://github.com/Headcrab/robin2/blob/master/internal/store/clickhouse.go"
    click MySQL "https://github.com/Headcrab/robin2/blob/master/internal/store/mysql.go"
    click MSSQL "https://github.com/Headcrab/robin2/blob/master/internal/store/mssql.go"
    click Oracle "https://github.com/Headcrab/robin2/blob/master/internal/store/oracle.go"
    click Redis "https://github.com/Headcrab/robin2/blob/master/internal/cache/redis.go"
    click MemCache "https://github.com/Headcrab/robin2/blob/master/internal/cache/memory.go"
    click ByteCache "https://github.com/Headcrab/robin2/blob/master/internal/cache/memoryByte.go"
    click Config "https://github.com/Headcrab/robin2/blob/master/internal/config/config.go"
    click Logger "https://github.com/Headcrab/robin2/blob/master/internal/logger/logger.go"
    click ErrorH "https://github.com/Headcrab/robin2/blob/master/internal/errors/errors.go"
    click Middle "https://github.com/Headcrab/robin2/tree/master/internal/middleware/"
    click Utils "https://github.com/Headcrab/robin2/blob/master/internal/utils/utils.go"

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#e74c3c,stroke:#c0392b,color:white
    classDef cache fill:#f1c40f,stroke:#f39c12,color:black
    classDef db fill:#9b59b6,stroke:#8e44ad,color:white
    classDef support fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Component"]:::frontend
        API_L["API Component"]:::api
        Service_L["Core Service"]:::service
        Cache_L["Cache Component"]:::cache
        DB_L["Database"]:::db
        Support_L["Support Service"]:::support
    end
```
