# jatin-mehra119/crypto-intelligence-pro architecture

> Architecture diagram of the GitHub repository jatin-mehra119/crypto-intelligence-pro, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jatin-mehra119/crypto-intelligence-pro
- Repository: https://github.com/jatin-mehra119/crypto-intelligence-pro

## Overview

##### Project Type & Purpose
- Crypto Intelligence Pro is a single‐page, data‐driven market analysis tool built with Python and Streamlit. It exposes a web UI (“frontend”) that ties into a service layer (“backend”) for real‐time data fetching, sentiment analysis, technical indicator computation, and AI forecasting.

##### Main Components
a. Frontend (Streamlit App)
- app/main.py – Streamlit entry point and UI layout
- app/models.py – Pydantic models for request/response schemas
b. Service Layer (Business Logic)
- app/services/data_fetcher.py – Retrieves/caches OHLC data from the CoinGecko API
- app/services/crypto_analyzer.py –
– Scrapes or fetches news articles (via Playwright under the hood)
– Submits text to Groq AI for sentiment and market‐forecasting
c. Utility Layer
- app/utils/visualization.py – Generates Plotly charts (line, candlestick, pie)
d. Configuration
- app/config.py – Reads environment variables (GROQ_API_KEY, etc.)
e. Infrastructure
- Dockerfile / Dockerfile_GCP – Container build for local/GCP Cloud Run
- .github/workflows/push_to_hf.yaml – CI/CD workflow deploying code & docs to Hugging Face Spaces (and optionally triggering GCP builds)
- Google Cloud Run – Hosts the containerized Streamlit service
f. External Services
- CoinGecko REST API
- Groq AI inference endpoint
- News sources (web pages via Playwright)

##### Relationships & Data Flow
1) User’s Browser ⇨ Streamlit UI (app/main.py)
2) UI events invoke Service Layer methods
3) DataFetcher calls CoinGecko ⇨ returns price data
4) CryptoAnalyzer scrapes/fetches articles ⇨ calls Groq API for sentiment & forecasting
5) Business logic returns raw & processed data to the UI
6) Visualization utils render charts and dashboards
7) Results displayed in the browser

##### Architectural Patterns & Principles
- Layered Architecture: clear separation of presentation, business logic, and utilities
- Single‐container microservice: all Python code in one Docker image
- External integration points abstracted behind service interfaces
- CI/CD via GitHub Actions pushing to Hugging Face Spaces and triggers GCP deployment

##### Must‐Have Elements
- Visual separation of internal vs external vs infra
- Notation of environment/configuration injection point

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Browser["User's Browser"]:::external

    %% Server Container
    subgraph "Server (Container)" 
        direction TB
        UI["Streamlit UI\n(app/main.py)"]:::frontend
        Models["Pydantic Models\n(app/models.py)"]:::frontend
        Config["Configuration\n(app/config.py)"]:::backend
        subgraph "Service Layer"
            direction TB
            DataFetcher["DataFetcher\n(app/services/data_fetcher.py)"]:::service
            CryptoAnalyzer["CryptoAnalyzer\n(app/services/crypto_analyzer.py)"]:::service
        end
        Utils["Visualization Utils\n(app/utils/visualization.py)"]:::utility
    end

    %% External Services
    CoinGecko["CoinGecko API"]:::external
    GroqAI["Groq AI Endpoint"]:::external
    News["News Sources\n(via Playwright)"]:::external

    %% Infrastructure
    subgraph "Infrastructure" 
        direction TB
        DockerLocal["Dockerfile"]:::infra
        DockerGCP["Dockerfile_GCP"]:::infra
        CloudRun["GCP Cloud Run"]:::infra
    end

    %% CI/CD
    subgraph "CI/CD Pipeline"
        direction TB
        GitHub["GitHub Actions\n(.github/workflows/push_to_hf.yaml)"]:::cicd
        HFSpaces["Hugging Face Spaces"]:::cicd
        GCPBuild["GCP Cloud Build"]:::cicd
    end

    %% Data Flow
    Browser -->|"Streamlit RPC"| UI
    UI -->|"uses models"| Models
    UI -->|"invokes"| DataFetcher
    UI -->|"invokes"| CryptoAnalyzer
    DataFetcher -->|"HTTPS REST"| CoinGecko
    CryptoAnalyzer -->|"Web Scraping"| News
    CryptoAnalyzer -->|"HTTPS REST"| GroqAI
    DataFetcher -->|"returns data"| UI
    CryptoAnalyzer -->|"returns sentiment & forecast"| UI
    UI -->|"renders charts"| Utils
    Utils -->|"renders to browser"| Browser

    %% Config Injection
    Config --> DataFetcher
    Config --> CryptoAnalyzer
    Config --> UI

    %% CI/CD Flow
    GitHub -->|"deploy code & docs"| HFSpaces
    GitHub -->|"trigger build"| GCPBuild
    GCPBuild -->|"uses Dockerfile_GCP"| DockerGCP
    DockerLocal --> Container
    DockerGCP --> Container
    Container["Server (Container)"] -->|"deployed"| CloudRun

    %% Click Events
    click UI "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/app/main.py"
    click Models "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/app/models.py"
    click DataFetcher "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/app/services/data_fetcher.py"
    click CryptoAnalyzer "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/app/services/crypto_analyzer.py"
    click Utils "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/app/utils/visualization.py"
    click Config "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/app/config.py"
    click DockerLocal "https://github.com/jatin-mehra119/crypto-intelligence-pro/tree/main/Dockerfile"
    click DockerGCP "https://github.com/jatin-mehra119/crypto-intelligence-pro/tree/main/Dockerfile_GCP"
    click GitHub "https://github.com/jatin-mehra119/crypto-intelligence-pro/blob/main/.github/workflows/push_to_hf.yaml"

    %% Styling
    classDef frontend fill:#D0E8FF,stroke:#0366D6,stroke-width:2px
    classDef service fill:#E8F4D0,stroke:#6A8E00,stroke-width:2px
    classDef utility fill:#F0E0FF,stroke:#8C00A3,stroke-width:2px
    classDef backend fill:#FFE8D0,stroke:#D07000,stroke-width:2px
    classDef external fill:#D0FFD6,stroke:#008F3C,stroke-width:2px
    classDef infra fill:#FFE8C2,stroke:#D67E00,stroke-width:2px
    classDef cicd fill:#F2D0FF,stroke:#9C00A8,stroke-width:2px
```
