# mgrzaslewicz/autocoin-arbitrage-monitor architecture

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

- Interactive diagram: https://gitdiagram.com/mgrzaslewicz/autocoin-arbitrage-monitor
- Repository: https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor

## Overview

##### Project Type and Core Purpose
This is a specialized microservice focused on cryptocurrency arbitrage monitoring. Its main responsibilities are:
- Monitoring currency pair spreads across exchanges
- Calculating spread statistics
- Providing authenticated access to arbitrage opportunities

##### Main Components

a) Core Service Components:
- API Layer (represented by /api directory)
- Exchange Integration Layer (/exchange directory)
- Authentication/Authorization Layer (/oauth directory)
- Health Monitoring System (/health directory)
- Metrics Collection (/metrics directory)

b) External Integration Points:
- Multiple Cryptocurrency Exchanges
- OAuth Authentication Server
- Metrics Collection System

**2. Inside the main container, create these key sections:**

- a) Data Input Layer:
- Exchange Order Book Streams
- Exchange Ticker Streams
- Exchange Metadata Service

- b) Processing Core:
- Two-Leg Arbitrage Monitor
- Profit Opportunity Calculator
- Order Book Cache
- Price Service

- c) API & Security Layer:
- REST API Controllers
- OAuth2 Authentication
- Access Token Management

- d) Monitoring & Operations:
- Health Checks
- Metrics Service
- Scheduled Tasks

##### Important Relationships

- Exchange data flows into the Order Book and Ticker Stream services
- Stream services feed into the Arbitrage Monitor
- Arbitrage Monitor connects to the Profit Calculator
- API Controllers receive data from the monitoring components
- OAuth security wraps around the API layer

##### Technical Details to Highlight

- The service's REST-based architecture
- Server-Sent Events (SSE) for real-time data streaming
- OAuth2-based security model
- Multiple exchange support
- Two-leg arbitrage calculation capability

##### Operational Aspects

A section showing:
- Docker deployment capability (based on Dockerfile presence)
- Configuration management (from /config directory)
- Monitoring and health check endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph External["External Systems"]
        EX1[Cryptocurrency Exchanges]
        EX2[OAuth Server]
        EX3[Metrics Collection System]
    end

    subgraph Main["Autocoin Arbitrage Monitor"]
        subgraph DataInput["Data Input Layer"]
            OBS["Order Book Stream"]:::stream
            click OBS "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/orderbookstream/OrderBookSseStreamService.kt"
            TS["Ticker Stream"]:::stream
            click TS "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/tickerstream/TickerSseStreamService.kt"
            EMS["Exchange Metadata Service"]:::service
            click EMS "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/metadata/CachingExchangeMetadataService.kt"
        end

        subgraph Core["Processing Core"]
            TAM["Two-Leg Arbitrage Monitor"]:::core
            click TAM "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/arbitrage/orderbook/TwoLegArbitrageOpportunitiesMonitor.kt"
            PC["Profit Calculator"]:::core
            click PC "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/arbitrage/orderbook/TwoLegArbitrageProfitCalculator.kt"
            OC["Opportunity Cache"]:::cache
            click OC "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/arbitrage/orderbook/TwoLegArbitrageProfitOpportunityCache.kt"
            PS["Price Service"]:::service
            click PS "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/exchange/CachingPriceService.kt"
        end

        subgraph API["API & Security Layer"]
            AC["API Controller"]:::api
            click AC "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/api/ApiController.kt"
            APC["Arbitrage Profit Controller"]:::api
            click APC "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/api/ArbitrageProfitController.kt"
            OAuth["OAuth2 Authentication"]:::security
            click OAuth "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/tree/master/src/main/kotlin/automate/profit/autocoin/oauth"
        end

        subgraph Ops["Monitoring & Operations"]
            HC["Health Checks"]:::monitoring
            click HC "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/tree/master/src/main/kotlin/automate/profit/autocoin/health"
            MS["Metrics Service"]:::monitoring
            click MS "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/blob/master/src/main/kotlin/automate/profit/autocoin/metrics/MetricsService.kt"
            ST["Scheduled Tasks"]:::monitoring
            click ST "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/tree/master/src/main/kotlin/automate/profit/autocoin/scheduled"
        end

        Config["Configuration Management"]:::config
        click Config "https://github.com/mgrzaslewicz/autocoin-arbitrage-monitor/tree/master/src/main/kotlin/automate/profit/autocoin/app/config"
    end

    %% Data Flow Relationships
    EX1 --> OBS
    EX1 --> TS
    EX1 --> EMS
    OBS --> TAM
    TS --> TAM
    EMS --> TAM
    TAM --> PC
    PC --> OC
    OC --> APC
    PS --> PC
    OAuth --> AC
    OAuth --> APC
    EX2 --> OAuth
    MS --> EX3

    %% Health Check Relationships
    HC --> OBS
    HC --> TS
    HC --> MS

    %% Style Definitions
    classDef external fill:#gray
    classDef stream fill:#lightblue
    classDef service fill:#blue
    classDef core fill:#darkblue
    classDef cache fill:#purple
    classDef api fill:#green
    classDef security fill:#red
    classDef monitoring fill:#yellow
    classDef config fill:#orange

    %% Legend
    subgraph Legend
        L1[External Systems]:::external
        L2[Stream Services]:::stream
        L3[Core Services]:::service
        L4[Processing Components]:::core
        L5[Cache Components]:::cache
        L6[API Components]:::api
        L7[Security Components]:::security
        L8[Monitoring Components]:::monitoring
        L9[Configuration]:::config
    end
```
