# himasnhu-at/crypto-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/himasnhu-at/crypto-tracker
- Repository: https://github.com/himasnhu-at/crypto-tracker

## Overview

##### Main Components

a) External Components:
- CoinGecko API (implied from cryptocurrency data fetching)
- MongoDB Database
- Client Applications (API consumers)

b) Internal Components:
- NestJS Application Server
- Crypto Module
- Background Service
- Database Schema Layer

**Client Layer**

**API Layer (NestJS)**

**Data Layer (MongoDB)**

##### Detailed Component Breakdown

a) API Layer (Main Focus):
- Main Application Module (AppModule)
- Crypto Module (CryptoModule)
- Controllers (CryptoController)
- Services (CryptoService)

b) Data Flow Paths:
1. Client requests to API endpoints (/crypto/stats, /crypto/deviation, /crypto/fetch-prices)
2. Service communication with external CoinGecko API
3. Data persistence flow to MongoDB
4. Background service data polling path

##### Specific Implementation Details

**┌─────────────────────────────────────────────────────┐**
- Client Applications                 │
- ┘
- ↓ HTTP
**┌─────────────────────────────────────────────────────┐**
- NestJS Application                 │
- ┌─────────────┐        ┌───────────────────────┐  │
- AppModule   │        │     CryptoModule      │  │
- ┘        │  ┌─────────────────┐  │  │
- CryptoController  │  │  │
- /stats        │  │  │
- /deviation    │  │  │
- /fetch-prices │  │  │
- ┘  │  │
- ┌─────────────────┐  │  │
- CryptoService   │  │  │
- ┘  │  │
- ┘  │
- ┘
- ↙                           ↘
**┌─────────────────┐            ┌─────────────────┐**
- CoinGecko API │            │    MongoDB      │
- ┘            │ (CryptoPrice    │
- Schema)        │
- ┘

##### Key Elements to Highlight

a) API Endpoints:
- GET /crypto/stats
- GET /crypto/deviation
- GET /crypto/fetch-prices
- GET / (health check)

b) Data Models:
- CryptoPriceSchema (showing fields: price, marketCap, 24hChange)

c) Background Services:
- Price fetching service
- Data aggregation for deviation calculation

##### Additional Notes

- A note about Docker containerization
- Test coverage points (controller, service, and e2e tests)
- Environment configuration requirements
- Scaling possibilities with Docker Compose

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CA[Client Applications]
    end

    subgraph NestJS[NestJS Application Server]
        AM[AppModule]:::module
        HC[Health Check]:::controller
        
        subgraph CryptoMod[Crypto Module]
            CC[CryptoController]:::controller
            CS[CryptoService]:::service
            CPS[CryptoPriceSchema]:::schema
            BGS[Background Service]:::service
        end
    end

    subgraph External
        CG[CoinGecko API]:::external
        DB[(MongoDB)]:::database
    end

    %% Client Layer Connections
    CA --> |HTTP| CC

    %% Controller Routes
    CC --> |"/crypto/stats"| CS
    CC --> |"/crypto/deviation"| CS
    CC --> |"/crypto/fetch-prices"| CS

    %% Service Connections
    CS --> CG
    CS --> DB
    BGS --> CG
    BGS --> DB

    %% Schema Connection
    CPS --> DB

    %% Testing Points
    CT[Controller Tests]:::test
    ST[Service Tests]:::test
    ET[E2E Tests]:::test

    CT -.-> CC
    ST -.-> CS
    ET -.-> AM

    %% Legend
    classDef controller fill:#2196F3,stroke:#000,color:#fff
    classDef service fill:#4CAF50,stroke:#000,color:#fff
    classDef module fill:#9C27B0,stroke:#000,color:#fff
    classDef schema fill:#FF9800,stroke:#000,color:#fff
    classDef database fill:#795548,stroke:#000,color:#fff
    classDef external fill:#FFC107,stroke:#000,color:#000
    classDef test fill:#607D8B,stroke:#000,color:#fff

    %% Click Events
    click AM "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/app.module.ts"
    click CC "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/crypto/crypto.controller.ts"
    click CS "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/crypto/crypto.service.ts"
    click CPS "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/crypto/schemas/crypto-price.schema.ts"
    click CT "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/crypto/crypto.controller.spec.ts"
    click ST "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/crypto/crypto.service.spec.ts"
    click ET "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/test/app.e2e-spec.ts"
    click HC "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/app.controller.ts"
    click NestJS "https://github.com/Himasnhu-AT/crypto-tracker/blob/main/src/main.ts"
```
