# ai-varun/crypto-tracking architecture

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

- Interactive diagram: https://gitdiagram.com/ai-varun/crypto-tracking
- Repository: https://github.com/ai-varun/crypto-tracking

## Overview

##### Project type and purpose
- This is a full-stack crypto-tracking application consisting of a Next.js/TypeScript frontend and an Express/Node.js backend.
- Purpose: fetch real-time crypto data from external APIs, store/manage it in MongoDB on the backend, and display live updates on the client, allowing users to switch symbols via a modal.

##### File structure
- Top-level separation into two folders: `client/` and `server/`.
- Client side (`client/`):
- Next.js app in `src/app` and `src/pages`
- UI components in `src/components` (CryptoSelector, Modal, PriceTable)
- Redux state management in `src/store`
- Configuration: ESLint, Tailwind, PostCSS, TypeScript.
- Server side (`server/`):
- Express app entry `src/index.ts`
- Controllers in `src/controllers` (dataController.ts)
- Route definitions in `src/routes`
- Business logic in `src/services` (cryptoService.ts)
- Data schema in `src/models` (crypto.ts)
- Configuration via `tsconfig.json`, `.gitignore`, `package.json`.

##### Extract insights from README
- Backend features: real-time fetch, MongoDB storage, REST API (`GET /api/data?symbol=`).
- Frontend features: table of live prices, modal for symbol selection, state management via Redux, data fetch via Axios.

a. Main components
- Frontend (Next.js application)
- Backend (Express service)
- Database (MongoDB)
- External Crypto API(s)
- Redux store on the client
b. Component interactions
- Frontend → Axios HTTP calls → Backend REST API
- Backend → External Crypto API (periodic fetch or on-demand)
- Backend → MongoDB (read/write crypto data)
- Frontend UI dispatches Redux actions, updates store, re-renders PriceTable.
c. Architectural patterns and design principles
- Client: component-based UI, unidirectional data flow via Redux (actions → reducers → store → components).
- Server: MVC-like separation (routes → controllers → services → models).
- Clear separation of concerns: UI vs. business logic vs. data access.
d. Key technologies and frameworks
- Frontend: Next.js, React, TypeScript, Redux, Axios, Tailwind CSS
- Backend: Node.js, Express, TypeScript, Mongoose (or MongoDB driver)
- External service: public crypto pricing API
- Database: MongoDB

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Client (Next.js)" 
        direction TB
        subgraph "Pages & Layout" 
            direction TB
            HomeApp["_app.tsx"]:::frontend
            IndexPage["index.tsx"]:::frontend
            Layout["layout.tsx"]:::frontend
            GlobalsCSS["globals.css"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            PriceTable["PriceTable Component"]:::frontend
            CryptoSelector["CryptoSelector Component"]:::frontend
            Modal["Modal Component"]:::frontend
        end
        subgraph "State Management"
            direction TB
            Store["Redux Store"]:::state
            PriceSlice["Price Slice (Reducer & Async Thunk)"]:::state
        end
    end

    %% API Layer between client and server
    APIRoute["GET /api/data"]:::api

    %% Backend Layer
    subgraph "Server (Express/Node.js)"
        direction TB
        Entry["server/src/index.ts"]:::server
        Routes["server/src/routes/index.ts"]:::server
        Controller["server/src/controllers/dataController.ts"]:::server
        Service["server/src/services/cryptoService.ts"]:::server
        Model["server/src/models/crypto.ts"]:::server
    end

    %% External Systems
    CryptoAPI["External Crypto API"]:::external
    MongoDB["MongoDB Atlas"]:::external

    %% Client Data Flow
    PriceTable -->|"user selects symbol"| CryptoSelector
    CryptoSelector -->|"dispatch selectSymbol"| Store
    Store -->|"state update"| PriceTable
    PriceTable -->|"dispatch fetchPrices"| PriceSlice
    PriceSlice -->|"Axios GET /api/data"| APIRoute

    %% Client to Server
    APIRoute -->|"routes/index.ts"| Entry
    Entry -->|"/api/data"| Routes
    Routes -->|"/api/data"| Controller
    Controller -->|"getData()"| Service

    %% Server Internal Flow
    Service -->|"find/write"| Model
    Model -->|read/write| MongoDB
    Service -->|"fetch from API"| CryptoAPI
    CryptoAPI -->|"data response"| Service
    Service -->|"data"| Controller
    Controller -->|"res.json"| Routes
    Routes -->|"HTTP Response"| Entry
    Entry -->|"HTTP Response"| APIRoute
    APIRoute -->|"Axios response"| PriceSlice
    PriceSlice -->|"update state"| Store
    Store -->|"state change"| PriceTable

    %% Click events
    click HomeApp "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/pages/_app.tsx"
    click IndexPage "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/pages/index.tsx"
    click Layout "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/app/layout.tsx"
    click GlobalsCSS "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/app/globals.css"
    click PriceTable "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/components/PriceTable.tsx"
    click CryptoSelector "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/components/CryptoSelector.tsx"
    click Modal "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/components/Modal.tsx"
    click Store "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/store/store.ts"
    click PriceSlice "https://github.com/ai-varun/crypto-tracking/blob/main/client/src/store/priceSlice.ts"
    click Entry "https://github.com/ai-varun/crypto-tracking/blob/main/server/src/index.ts"
    click Routes "https://github.com/ai-varun/crypto-tracking/blob/main/server/src/routes/index.ts"
    click Controller "https://github.com/ai-varun/crypto-tracking/blob/main/server/src/controllers/dataController.ts"
    click Service "https://github.com/ai-varun/crypto-tracking/blob/main/server/src/services/cryptoService.ts"
    click Model "https://github.com/ai-varun/crypto-tracking/blob/main/server/src/models/crypto.ts"

    %% Styles
    classDef frontend fill:#D6E9FE,stroke:#0366d6,color:#000;
    classDef state fill:#E2F0D9,stroke:#2c8c06,color:#000;
    classDef server fill:#FFE5B4,stroke:#d97706,color:#000;
    classDef external fill:#F2F2F2,stroke:#6b7280,color:#000;
    classDef api fill:#FDE68A,stroke:#b45309,color:#000;
```
