# contre95/controtto architecture

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

- Interactive diagram: https://gitdiagram.com/contre95/controtto
- Repository: https://github.com/contre95/controtto

## Overview

##### Main Components Identification

a) Presentation Layer:
- HTML Templates (views directory)
- Static Assets (public directory)
- HTMX for interactive features

b) Application Layer:
- REST API Handlers (src/rest)
- Application Services
- Managing Service (src/app/managing)
- Querying Service (src/app/querying)

c) Domain Layer:
- PnL Domain Models (src/domain/pnl)
- Asset Management
- Trading Pairs

d) Infrastructure Layer:
- Market Data Gateways (src/gateways/markets)
- Binance API
- BingX API
- Alpha Vantage API
- Tiingo API
- Persistence Layer (src/gateways/sqlite)

##### Component Relationships and Data Flow

**[Web Browser] ←→ [HTMX/Templates]**
- ↓
**[REST Handlers]**
- ↓
**[Application Services]**
- ↓
**[Domain Layer]**
- ↓
**[Infrastructure Layer] → [External APIs]**
- → [SQLite Database]

##### Specific Design Elements

Use these visual elements:

##### Key Architectural Patterns to Highlight

- Clean Architecture pattern (visible in the layer separation)
- Repository pattern (for database access)
- Gateway pattern (for external API access)
- MVC-like structure in the web layer

##### Technical Details

Database:
- SQLite for persistence
- Connection to asset and transaction storage

External Services:
- Market data providers with API connections
- Rate limiting considerations

Web Layer:
- HTMX-based frontend
- Template-based rendering
- Static asset serving

##### Deployment Context

Show:
- Container deployment option
- Volume mounting for persistence
- Port exposures
- Environment variable configuration

Remember to indicate the stateless nature of the application and how it relies on SQLite for persistence, making it suitable for self-hosting and containerization.

This architecture emphasizes the separation of concerns while showing how the application achieves its core functionality of tracking P&L without requiring JavaScript on the frontend, which is a unique characteristic of this project.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef domain fill:#f1c40f,stroke:#f39c12,color:black
    classDef infra fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    
    %% Presentation Layer
    subgraph Presentation
        Browser["Web Browser"]
        Templates["HTML Templates"]:::ui
        StaticAssets["Static Assets"]:::ui
        HTMX["HTMX Interface"]:::ui
    end
    
    %% REST Layer
    subgraph REST
        AssetHandlers["Asset Handlers"]:::service
        MarketHandlers["Market Handlers"]:::service
        PnLHandlers["PnL Handlers"]:::service
        Routes["Routes Config"]:::service
    end
    
    %% Application Layer
    subgraph Application
        Managing["Managing Service"]:::service
        Querying["Querying Service"]:::service
        Config["Configuration"]:::service
    end
    
    %% Domain Layer
    subgraph Domain
        PnLModels["PnL Models"]:::domain
        AssetModels["Asset Models"]:::domain
        TradingPairs["Trading Pairs"]:::domain
        Accounts["Accounts"]:::domain
    end
    
    %% Infrastructure Layer
    subgraph Infrastructure
        SQLite["SQLite Gateway"]:::infra
        
        subgraph "Market Gateways"
            Binance["Binance API"]:::infra
            BingX["BingX API"]:::infra
            AlphaVantage["Alpha Vantage API"]:::infra
            Tiingo["Tiingo API"]:::infra
        end
    end
    
    %% External Services
    subgraph "External APIs"
        BinanceExt["Binance"]:::external
        BingXExt["BingX"]:::external
        AlphaVantageExt["Alpha Vantage"]:::external
        TiingoExt["Tiingo"]:::external
    end
    
    %% Relationships
    Browser --> Templates
    Browser --> StaticAssets
    Browser --> HTMX
    
    HTMX --> AssetHandlers
    HTMX --> MarketHandlers
    HTMX --> PnLHandlers
    
    AssetHandlers & MarketHandlers & PnLHandlers --> Managing
    AssetHandlers & MarketHandlers & PnLHandlers --> Querying
    
    Managing & Querying --> PnLModels
    Managing & Querying --> AssetModels
    Managing & Querying --> TradingPairs
    Managing & Querying --> Accounts
    
    Managing & Querying --> SQLite
    Managing & Querying --> Binance & BingX & AlphaVantage & Tiingo
    
    Binance --> BinanceExt
    BingX --> BingXExt
    AlphaVantage --> AlphaVantageExt
    Tiingo --> TiingoExt
    
    %% Click Events
    click Templates "https://github.com/contre95/controtto/tree/main/views/"
    click StaticAssets "https://github.com/contre95/controtto/tree/main/public/assets/"
    click AssetHandlers "https://github.com/contre95/controtto/blob/main/src/rest/assetHandlers.go"
    click MarketHandlers "https://github.com/contre95/controtto/blob/main/src/rest/marketHandlers.go"
    click PnLHandlers "https://github.com/contre95/controtto/blob/main/src/rest/pnlHandlers.go"
    click Routes "https://github.com/contre95/controtto/blob/main/src/rest/routes.go"
    click Managing "https://github.com/contre95/controtto/blob/main/src/app/managing/manager.go"
    click Querying "https://github.com/contre95/controtto/blob/main/src/app/querying/querier.go"
    click Config "https://github.com/contre95/controtto/blob/main/src/app/config/config.go"
    click PnLModels "https://github.com/contre95/controtto/blob/main/src/domain/pnl/pnl.go"
    click AssetModels "https://github.com/contre95/controtto/blob/main/src/domain/pnl/asset.go"
    click TradingPairs "https://github.com/contre95/controtto/blob/main/src/domain/pnl/tradingPair.go"
    click Accounts "https://github.com/contre95/controtto/blob/main/src/domain/pnl/accounts.go"
    click Binance "https://github.com/contre95/controtto/blob/main/src/gateways/markets/binanceAPI.go"
    click BingX "https://github.com/contre95/controtto/blob/main/src/gateways/markets/bingxAPI.go"
    click AlphaVantage "https://github.com/contre95/controtto/blob/main/src/gateways/markets/alphaVantageAPI.go"
    click Tiingo "https://github.com/contre95/controtto/blob/main/src/gateways/markets/tiingoAPI.go"
    click SQLite "https://github.com/contre95/controtto/blob/main/src/gateways/sqlite/sqlite.go"
```
