# singingsandhill/coinbot architecture

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

- Interactive diagram: https://gitdiagram.com/singingsandhill/coinbot
- Repository: https://github.com/singingsandhill/coinbot

## Overview

##### High-Level Architecture Overview
- CoinBot (Cryptocurrency Trading Service)
- Running Crew Archive (Running Management Service)

##### Application Layer (DTOs)
- Trading-related DTOs (Account, Market, OrderBook, etc.)
- Running-related DTOs (RunnerDistance, RunningRecord)

##### Domain Layer (Services)
- Trading Domain:
- Chart Service
- Candle Service
- Order Service
- Trading Service
- Technical Indicator
- Running Domain:
- Run Service
- Image Text Service
- Stock Service

##### Infrastructure Layer
- Repositories:
- Order History Repository
- Regular Repository
- Running Records Repository
- Trading Signal History Repository
- Stock Repository

##### Global Components
- Configuration (AppConfig, SecurityConfig, SwaggerConfig)
- Error Handling
- Schedulers (TradingScheduler)

B. External Integrations:
- Database (JPA/Hibernate)
- Web Interface (Templates)
- Static Resources (CSS/JS/Images)

##### Key Architectural Patterns to Highlight

- Layered Architecture (Controller → Service → Repository)
- Domain-Driven Design (separate domains for trading and running)
- MVC Pattern (for web interface)
- Repository Pattern (for data access)
- DTO Pattern (for data transfer)

##### Technical Details

- Spring Boot as the main framework
- JPA for database access
- Security configurations
- Scheduled tasks for trading bot
- Static resource handling
- Error handling mechanism

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef service fill:#f1c40f,stroke:#f39c12,color:black
    classDef repository fill:#e67e22,stroke:#d35400,color:white
    classDef config fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        Templates["Templates"]:::frontend
        StaticRes["Static Resources"]:::frontend
        CSS["CSS"]:::frontend
        JS["JavaScript"]:::frontend
        Images["Images"]:::frontend
    end

    %% API Layer
    subgraph Controllers
        ChartCtrl["Chart Controller"]:::api
        MarketCtrl["Market Controller"]:::api
        OrderCtrl["Order Controller"]:::api
        RunningCtrl["Running Controller"]:::api
        StockCtrl["Stock Controller"]:::api
    end

    %% Service Layer
    subgraph TradingServices
        ChartSvc["Chart Service"]:::service
        CandleSvc["Candle Service"]:::service
        OrderSvc["Order Service"]:::service
        TradingSvc["Trading Service"]:::service
        TechInd["Technical Indicator"]:::service
    end

    subgraph RunningServices
        RunSvc["Run Service"]:::service
        ImgTextSvc["Image Text Service"]:::service
        StockSvc["Stock Service"]:::service
    end

    %% Repository Layer
    subgraph Repositories
        OrderHistRepo["Order History Repository"]:::repository
        RegularRepo["Regular Repository"]:::repository
        RunRecRepo["Running Records Repository"]:::repository
        TradingSignalRepo["Trading Signal History Repository"]:::repository
        StockRepo["Stock Repository"]:::repository
    end

    %% Global Components
    subgraph Global
        AppConfig["App Config"]:::config
        SecurityConfig["Security Config"]:::config
        SwaggerConfig["Swagger Config"]:::config
        ErrorHandler["Error Handling"]:::config
        Scheduler["Trading Scheduler"]:::config
    end

    %% External Systems
    Database[(Database)]:::external

    %% Relationships
    Templates --> Controllers
    StaticRes --> Controllers
    
    Controllers --> TradingServices
    Controllers --> RunningServices
    
    TradingServices --> Repositories
    RunningServices --> Repositories
    
    Repositories --> Database
    
    Scheduler --> TradingSvc
    ErrorHandler --> Controllers

    %% Click Events
    click Templates "https://github.com/singingsandhill/CoinBot/tree/main/src/main/resources/templates/"
    click StaticRes "https://github.com/singingsandhill/CoinBot/tree/main/src/main/resources/static/"
    click CSS "https://github.com/singingsandhill/CoinBot/tree/main/src/main/resources/static/css/"
    click JS "https://github.com/singingsandhill/CoinBot/tree/main/src/main/resources/static/js/"
    click Images "https://github.com/singingsandhill/CoinBot/tree/main/src/main/resources/static/images/"
    
    click ChartSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/chart/ChartService.java"
    click CandleSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/market/CandleService.java"
    click OrderSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/order/OrderService.java"
    click TradingSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/trading/TradingService.java"
    click TechInd "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/strategy/TechnicalIndicator.java"
    
    click RunSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/run/Service/RunService.java"
    click ImgTextSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/run/Service/ImageTextService.java"
    click StockSvc "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/stock/Service/StockService.java"
    
    click OrderHistRepo "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/order/Repository/OrderHistoryRepository.java"
    click RegularRepo "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/run/Repository/RegularRepository.java"
    click RunRecRepo "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/run/Repository/RunningRecordsRepository.java"
    click TradingSignalRepo "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/run/Repository/TradingSignalHistoryRepository.java"
    click StockRepo "https://github.com/singingsandhill/CoinBot/blob/main/src/main/java/scoula/coin/domain/stock/Repository/StockRepository.java"
    
    click AppConfig "https://github.com/singingsandhill/CoinBot/tree/main/src/main/java/scoula/coin/global/config/"
    click ErrorHandler "https://github.com/singingsandhill/CoinBot/tree/main/src/main/java/scoula/coin/global/error/"
```
