# chanleeip/koinx-submission architecture

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

- Interactive diagram: https://gitdiagram.com/chanleeip/koinx-submission
- Repository: https://github.com/chanleeip/koinx-submission

## Overview

##### Main Components

a. External Components:
- CoinGecko API (indicated by CRYPTO_LISTING_ENDPOINT in .env)
- MongoDB Database (indicated by MONGODB_URI)
- Client Applications (API consumers)

b. Internal Components:
- API Layer (Express.js Server)
- Controllers Layer
- Services Layer (including CRON jobs)
- Models Layer
- Utils Layer

##### Component Organization

**[Client Applications] → [API Gateway]**
- ↑               ↓
**[CoinGecko API] ← [Express.js Server] → [MongoDB]**
- ↓
- [Routes Layer]
- ↓
- [Controllers Layer]
- ↓
- [Services Layer]
- ↓
- [Models Layer]

##### Specific Implementation Details

a. API Routes (from /src/routes/api/v1):
- Version them under /api/v1/

b. Controllers (from /src/controllers):
- GetDeviationdata and getLatestdata controllers
- Them to their respective routes

c. Services:
- Cron_job service separately
- Interaction with external APIs and database

##### Additional Elements

- Environment configurations
- Supported cryptocurrencies (Bitcoin, MATIC, Ethereum)
- API versioning structure

##### Specific Notes for This Project

- CRON job component as it appears to be a crucial service
- How the utils layer supports other components
- TypeScript compilation process
- API versioning structure (/api/v1/)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        Client[Client Applications]
        CoinGecko[CoinGecko API]:::external
        MongoDB[(MongoDB Database)]:::database
    end

    subgraph Server
        API[API Server]:::server
        click API "https://github.com/chanleeip/koinx-submission/blob/main/src/index.ts"
    end

    subgraph "Routes Layer"
        Routes[API Routes Index]:::routes
        click Routes "https://github.com/chanleeip/koinx-submission/blob/main/src/routes/index.ts"
        DevRoute["/api/v1/getDeviation"]:::routes
        click DevRoute "https://github.com/chanleeip/koinx-submission/blob/main/src/routes/api/v1/getDeviation.ts"
        PriceRoute["/api/v1/getLatestPrice"]:::routes
        click PriceRoute "https://github.com/chanleeip/koinx-submission/blob/main/src/routes/api/v1/getLatestPrice.ts"
    end

    subgraph "Controllers Layer"
        Controllers[Controllers Index]:::controller
        click Controllers "https://github.com/chanleeip/koinx-submission/blob/main/src/controllers/index.ts"
        DevController[Deviation Controller]:::controller
        click DevController "https://github.com/chanleeip/koinx-submission/blob/main/src/controllers/getDeviationdata.ts"
        PriceController[Latest Price Controller]:::controller
        click PriceController "https://github.com/chanleeip/koinx-submission/blob/main/src/controllers/getLatestdata.ts"
    end

    subgraph "Services Layer"
        CronJob[CRON Job Service]:::service
        click CronJob "https://github.com/chanleeip/koinx-submission/blob/main/src/services/cron_job.ts"
    end

    subgraph "Models Layer"
        Models[Models Index]:::model
        click Models "https://github.com/chanleeip/koinx-submission/blob/main/src/models/index.ts"
        DataModel[Database Model]:::model
        click DataModel "https://github.com/chanleeip/koinx-submission/blob/main/src/models/model.ts"
    end

    subgraph "Utils Layer"
        Utils[Utility Functions]:::utils
        click Utils "https://github.com/chanleeip/koinx-submission/blob/main/src/utils/utils.ts"
    end

    %% Connections
    Client --> API
    API --> Routes
    Routes --> DevRoute & PriceRoute
    DevRoute --> DevController
    PriceRoute --> PriceController
    DevController & PriceController --> DataModel
    CronJob --> CoinGecko
    CronJob --> DataModel
    DataModel --> MongoDB
    Utils -.- DevController
    Utils -.- PriceController
    Utils -.- CronJob

    %% Styles
    classDef external fill:#1E88E5,color:white
    classDef database fill:#4CAF50,color:white
    classDef server fill:#FFA726,color:white
    classDef routes fill:#9575CD,color:white
    classDef controller fill:#FF7043,color:white
    classDef service fill:#F06292,color:white
    classDef model fill:#4DB6AC,color:white
    classDef utils fill:#90A4AE,color:white

    %% Legend
    subgraph Legend
        L1[External APIs]:::external
        L2[(Database)]:::database
        L3[Server]:::server
        L4[Routes]:::routes
        L5[Controllers]:::controller
        L6[Services]:::service
        L7[Models]:::model
        L8[Utils]:::utils
    end
```
