# lukasgss/workerservicecrypto architecture

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

- Interactive diagram: https://gitdiagram.com/lukasgss/workerservicecrypto
- Repository: https://github.com/lukasgss/workerservicecrypto

## Overview

##### Key Components

a) External Systems:
- CoinLore API (external data source)
- SQL Server Database
- Hangfire Server

b) Internal Components:
- Worker Service
- API Controllers
- Domain Entities (Coin, Exchange)
- Application Services
- Repositories

##### Detailed Component Breakdown

Worker Service Section:
- HangfireWorker
- CryptoClient (for CoinLore API communication)
- InternalApiClient
- DatabaseInitializer

API Layer:
- CoinsController
- ExchangesController
- ErrorHandlerMiddleware

Application Layer:
- CoinService
- ExchangeService
- DTOs and Interfaces

Domain Layer:
- Coin Entity
- Exchange Entity
- Money ValueObject

Infrastructure Layer:
- AppDbContext
- Repositories
- Database Configurations

##### Connection and Flow Representation

- Hourly data flow from CoinLore API → Worker Service → Internal API
- API request flow: Client → API Controllers → Application Services → Repositories → Database
- Dependency flow between layers (following Clean Architecture)

##### Technical Details to Note

Annotations for:
- .NET Core framework
- Entity Framework Core
- Hangfire scheduling (1-hour interval)
- SQL Server database
- REST API endpoints

- The Clean Architecture pattern
- The separation between the worker service and the main application
- The data flow from external API to internal storage
- The relationship between different layers while maintaining dependency rules

Remember to maintain Clean Architecture's dependency rule: all dependencies should point inward, with the Domain layer having no dependencies on outer layers.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef external fill:#gray,stroke:#333
    classDef api fill:#90EE90,stroke:#333
    classDef application fill:#ADD8E6,stroke:#333
    classDef domain fill:#FFB6C1,stroke:#333
    classDef infrastructure fill:#DDA0DD,stroke:#333
    classDef worker fill:#FFA500,stroke:#333

    %% External Systems
    CoinLore["CoinLore API"]:::external
    DB[(SQL Server)]:::external
    Hangfire["Hangfire Server"]:::external

    %% Worker Service
    subgraph Worker["Worker Service"]
        HWorker["HangfireWorker"]:::worker
        CClient["CryptoClient"]:::worker
        IClient["InternalApiClient"]:::worker
        DBInit["DatabaseInitializer"]:::worker
    end

    %% API Layer
    subgraph APILayer["API Layer"]
        CoinsCtrl["CoinsController"]:::api
        ExchangesCtrl["ExchangesController"]:::api
        ErrorHandler["ErrorHandlerMiddleware"]:::api
    end

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        CoinSvc["CoinService"]:::application
        ExchangeSvc["ExchangeService"]:::application
        DTOs["DTOs"]:::application
        Interfaces["Service Interfaces"]:::application
    end

    %% Domain Layer
    subgraph DomainLayer["Domain Layer"]
        CoinEntity["Coin Entity"]:::domain
        ExchangeEntity["Exchange Entity"]:::domain
        MoneyVO["Money ValueObject"]:::domain
    end

    %% Infrastructure Layer
    subgraph InfraLayer["Infrastructure Layer"]
        DbContext["AppDbContext"]:::infrastructure
        CoinRepo["CoinRepository"]:::infrastructure
        ExchangeRepo["ExchangeRepository"]:::infrastructure
        DbConfig["Database Configurations"]:::infrastructure
    end

    %% Relationships
    CoinLore --> CClient
    CClient --> HWorker
    HWorker --> IClient
    IClient --> CoinsCtrl
    IClient --> ExchangesCtrl
    
    CoinsCtrl --> CoinSvc
    ExchangesCtrl --> ExchangeSvc
    
    CoinSvc --> CoinRepo
    ExchangeSvc --> ExchangeRepo
    
    CoinRepo --> DbContext
    ExchangeRepo --> DbContext
    DbContext --> DB
    
    Hangfire --> HWorker
    DBInit --> DB

    %% Click Events
    click HWorker "https://github.com/lukasgss/workerServiceCrypto/blob/main/WorkerService/Hangfire/HangfireWorker.cs"
    click CClient "https://github.com/lukasgss/workerServiceCrypto/blob/main/WorkerService/ExternalServices/CryptoClient.cs"
    click IClient "https://github.com/lukasgss/workerServiceCrypto/blob/main/WorkerService/InternalServices/InternalApiClient.cs"
    click DBInit "https://github.com/lukasgss/workerServiceCrypto/blob/main/WorkerService/DatabaseInitializer.cs"
    click CoinsCtrl "https://github.com/lukasgss/workerServiceCrypto/blob/main/Api/Controllers/CoinsController.cs"
    click ExchangesCtrl "https://github.com/lukasgss/workerServiceCrypto/blob/main/Api/Controllers/ExchangesController.cs"
    click ErrorHandler "https://github.com/lukasgss/workerServiceCrypto/blob/main/Api/Middlewares/ErrorHandlerMiddleware.cs"
    click CoinEntity "https://github.com/lukasgss/workerServiceCrypto/blob/main/Domain/CryptoCurrency/Entities/Coin.cs"
    click ExchangeEntity "https://github.com/lukasgss/workerServiceCrypto/blob/main/Domain/CryptoCurrency/Entities/Exchange.cs"
    click MoneyVO "https://github.com/lukasgss/workerServiceCrypto/blob/main/Domain/CryptoCurrency/ValueObjects/Money.cs"
    click CoinSvc "https://github.com/lukasgss/workerServiceCrypto/blob/main/Application/Services/CoinService.cs"
    click ExchangeSvc "https://github.com/lukasgss/workerServiceCrypto/blob/main/Application/Services/ExchangeService.cs"
    click DTOs "https://github.com/lukasgss/workerServiceCrypto/tree/main/Application/Common/DTOs"
    click Interfaces "https://github.com/lukasgss/workerServiceCrypto/tree/main/Application/Common/Interfaces"
    click DbContext "https://github.com/lukasgss/workerServiceCrypto/blob/main/Infrastructure/Persistence/AppDbContext.cs"
    click CoinRepo "https://github.com/lukasgss/workerServiceCrypto/blob/main/Infrastructure/Persistence/Repositories/CoinRepository.cs"
    click ExchangeRepo "https://github.com/lukasgss/workerServiceCrypto/blob/main/Infrastructure/Persistence/Repositories/ExchangeRepository.cs"
    click DbConfig "https://github.com/lukasgss/workerServiceCrypto/tree/main/Infrastructure/Persistence/Configurations"
```
