# olofblomqvist/odd-box architecture

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

- Interactive diagram: https://gitdiagram.com/olofblomqvist/odd-box
- Repository: https://github.com/olofblomqvist/odd-box

## Overview

##### Project’s Purpose and Type
- It combines a Rust backend—which manages the reverse proxy logic, configuration parsing, certificate management (including automatic self-signed and Lets-Encrypt certificates), custom server logic, TCP/HTTP proxies—and a web-based UI (in the “web-ui” directory) to provide a graphical administration interface.

##### File Structure and Map Out the Main Components
- Backend (Rust code):
- src/ – Contains the core application.
◦ main.rs: The application entry point.
◦ src/api: API controllers (e.g., settings, sites) that provide an administration API.
◦ src/configuration: Handles parsing of TOML configuration files (supporting legacy and multiple versions).
◦ src/http_proxy and src/tcp_proxy: Modules handling different levels of proxying (HTTP/1.1, HTTP2, TCP tunneling, TLS logic).
◦ src/custom_servers: Implements support for additional or experimental server types.
◦ Other modules (src/letsencrypt.rs, src/logging.rs, src/self_update.rs, src/tui): Manage certificate generation, logging, self-update functionality, and even a terminal-based UI.
- Web UI:
- web-ui/ – Contains a modern frontend built with TypeScript/React (or similar frameworks using TSX files). It includes components, pages, routing, and asset management via Vite.
- This web UI communicates with the backend’s API for configuration and status updates.
- Configuration & Documentation:
- Deployment / Infrastructure/ DevOps:
- Dockerfile(s), .dockerignore, and various devcontainer and devbox configurations indicate containerization and local development integration.
- CI/CD workflows in .github provide automated building, testing, and release pipelines.

##### Link the Components with Their Relationships
- A central Reverse Proxy Backend (Rust) that is responsible for processing incoming HTTP/TCP requests, parsing configuration, managing proxies, and orchestrating hosted processes.
- Development and deployment tools (containerization via Docker, devbox, CI/CD workflows) can be represented as external components/tools that interact with the codebase.

##### Important Architectural Patterns & Design Principles
- Modular Design: Each concern—routing, configuration, API handling, UI rendering—is separated into its own module.
- Declarative Configuration: The use of TOML files for configuration and versioning (v1, v2, v3) shows a design that favors configuration-as-code.
- Cross-platform and extensibility: The architecture’s structure (in src and custom_servers) promotes flexibility and pluggability.
- Reverse Proxy Patterns: The handling of both HTTP-level and TCP-level proxying is clearly central, as is the integration of automated certificate management.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    A["Web UI Frontend"]:::frontend

    %% Backend Layer
    subgraph "Reverse Proxy Backend (Rust)"
        B["Entry Point"]:::backend
        C["API Controllers"]:::backend
        D["Configuration Manager"]:::backend
        E["HTTP Proxy Module"]:::backend
        F["TCP Proxy Module"]:::backend
        G["Custom Servers Module"]:::backend
        H["Certificate Management"]:::backend
        I["Logging Functionality"]:::backend
        J["Self Update"]:::backend
        K["Terminal-based UI"]:::backend
    end

    %% Configuration Files
    L["Configuration Files (TOML) & Schemas"]:::config

    %% Deployment & Infrastructure
    M["Deployment & Infrastructure"]:::deploy

    %% External Integrations
    N["External Services"]:::external

    %% Connections
    A -->|"callsAPI"| C
    L -->|"parseConfig"| D
    D -->|"configures"| E
    D -->|"configures"| F
    D -->|"configures"| G
    H -->|"managesCert"| N
    M -->|"deploys"| B
    M -->|"deploys"| D
    M -->|"deploys"| E
    M -->|"deploys"| F

    %% Styles
    classDef backend fill:#ADD8E6,stroke:#0077AA,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#228B22,stroke-width:2px;
    classDef config fill:#FFFF99,stroke:#CCCC00,stroke-width:2px;
    classDef deploy fill:#D3D3D3,stroke:#808080,stroke-width:2px,stroke-dasharray: 5, 5;
    classDef external fill:#FFB6C1,stroke:#FF69B4,stroke-width:2px,stroke-dasharray: 2, 2;

    %% Click Events
    click B "https://github.com/olofblomqvist/odd-box/blob/main/src/main.rs"
    click C "https://github.com/olofblomqvist/odd-box/tree/main/src/api/controllers"
    click D "https://github.com/olofblomqvist/odd-box/tree/main/src/configuration"
    click E "https://github.com/olofblomqvist/odd-box/tree/main/src/http_proxy"
    click F "https://github.com/olofblomqvist/odd-box/tree/main/src/tcp_proxy"
    click G "https://github.com/olofblomqvist/odd-box/tree/main/src/custom_servers"
    click H "https://github.com/olofblomqvist/odd-box/blob/main/src/letsencrypt.rs"
    click I "https://github.com/olofblomqvist/odd-box/blob/main/src/logging.rs"
    click J "https://github.com/olofblomqvist/odd-box/blob/main/src/self_update.rs"
    click K "https://github.com/olofblomqvist/odd-box/tree/main/src/tui"
    click A "https://github.com/olofblomqvist/odd-box/tree/main/web-ui/"
    click L "https://github.com/olofblomqvist/odd-box/blob/main/odd-box.toml"
    click M "https://github.com/olofblomqvist/odd-box/tree/main/Dockerfile"
```
