# lumif-ai/mcp-chart-server architecture

> Architecture diagram of the GitHub repository lumif-ai/mcp-chart-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lumif-ai/mcp-chart-server
- Repository: https://github.com/lumif-ai/mcp-chart-server

## Overview

##### Project type and purpose
- This is a back-end microservice written in Node.js/TypeScript whose job is to fetch cryptocurrency OHLCV data from external exchanges/APIs (Binance, Bitquery), compute technical indicators (EMA, others), generate chart data/themes, persist results in MongoDB, and expose chart data (or images) via an API endpoint.

##### File structure
- Top-level files:
- package.json, tsconfig.json – standard Node/TS config
- index.ts – application entrypoint (starts server or CLI)
- src/config – configuration modules
- mongodb.config.ts – MongoDB connection parameters
- chart.theme.ts – chart styling/theme settings
- src/models – data schemas
- agent.model.ts – Mongoose schema/model for charting “agents” or jobs
- src/services – core business logic
- ohlcv.service.ts – orchestration of fetching raw OHLCV data
- ema.service.ts – computing EMA indicator from OHLCV
- mongodb.service.ts – persistence layer for read/write to MongoDB
- src/utils – thin wrappers and helpers
- binance.utils.ts, bitquery.utils.ts – adapter/clients for external data sources
- chart.utils.ts – routines for building chart payloads (e.g., Chart.js config)
- indicator.ts – helper functions for other indicators

##### README for additional insights
- README simply names the project (“mcp-chart”) but lacks an architecture section. All structural clues come from the file tree.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::external

    subgraph "Controller (API Layer)"
        API["API Server"]:::api
    end

    subgraph "Service Layer"
        OHLCV["OHLCV Service"]:::service
        EMA["EMA Service"]:::service
        MongoSvc["MongoDB Service"]:::service
    end

    subgraph "Utility/Adapter Layer"
        Binance["Binance Adapter"]:::adapter
        Bitquery["Bitquery Adapter"]:::adapter
        IndicatorUtil["Indicator Utilities"]:::adapter
        ChartUtil["Chart Utilities"]:::adapter
    end

    subgraph "Config/Models"
        subgraph "Config"
            MongoCfg["MongoDB Config"]:::config
            ThemeCfg["Chart Theme Config"]:::config
        end
        subgraph "Models"
            AgentModel["Agent Model"]:::model
        end
    end

    MongoDB[(MongoDB)]:::database

    Client -->|"GET /chart"| API
    API -->|"ingest data"| OHLCV
    API -->|"compute indicators"| EMA
    API -->|"assemble chart"| ChartUtil
    OHLCV -->|"fetch raw data"| Binance
    OHLCV -->|"fetch raw data"| Bitquery
    OHLCV -->|"persist raw data"| MongoSvc
    EMA -->|"load OHLCV"| MongoSvc
    EMA -->|"indicator data"| ChartUtil
    MongoSvc -->|"uses schema"| AgentModel
    MongoSvc -->|"stores data"| MongoDB
    ChartUtil -->|"apply theme"| ThemeCfg
    ChartUtil -->|"return payload"| API
    MongoCfg -->|"db params"| MongoSvc

    click API "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/index.ts"
    click MongoCfg "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/config/mongodb.config.ts"
    click ThemeCfg "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/config/chart.theme.ts"
    click AgentModel "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/models/agent.model.ts"
    click OHLCV "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/services/ohlcv.service.ts"
    click EMA "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/services/ema.service.ts"
    click MongoSvc "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/services/mongodb.service.ts"
    click Binance "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/utils/binance.utils.ts"
    click Bitquery "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/utils/bitquery.utils.ts"
    click ChartUtil "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/utils/chart.utils.ts"
    click IndicatorUtil "https://github.com/lumif-ai/mcp-chart-server/blob/main/src/utils/indicator.ts"

    classDef api fill:#cceeff,stroke:#333,stroke-width:1px
    classDef service fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef adapter fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef config fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef model fill:#d0d0d0,stroke:#333,stroke-width:1px
    classDef database fill:#ffffcc,stroke:#333,stroke-width:1px
    classDef external fill:#ffeb99,stroke:#333,stroke-width:1px
```
