# divyanshu-yu/crypto-project architecture

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

- Interactive diagram: https://gitdiagram.com/divyanshu-yu/crypto-project
- Repository: https://github.com/divyanshu-yu/crypto-project

## Overview

##### Main Components and Layers
- User Interface (Frontend): This is built using React and consists of multiple pages (LandingPage, Coin, Compare, Dashboard, Watchlist) and a wide range of UI components.
- Common/Shared Components: These include Header, Footer, Button, Loader, and TopButton that provide common functionality across different pages.
- Domain-Specific Components:
- CoinPage: Contains detailed coin info, line charts, day selection, and a toggle component.
- ComparePage: Offers coin selection for comparing details.
- Dashboard: Manages grid/list displays, pagination, search, and tabs for quick coin overviews.
- Utility Functions: Found in the “src/functions” directory, these include functions like getCoinData, getPrices, convertNumber, get100Coins, etc. They handle data fetching, formatting, and preparing chart data for the UI.
- External API Service: Integration with the CoinGecko API is implied by functions such as getCoinData and getPrices. This external service is the source of real-time crypto data.

##### Relationships and Data Flow
- The App Component (src/App.js) acts as the central container and orchestrates the routing between pages.
- Each page (e.g., Coin.js, Dashboard.js, Compare.js, Home.js, Watchlist.js) imports appropriate components and utility functions.
- UI components call the utility functions to fetch and format data; for example, the CoinPage components request and display real-time coin data using Axios for API calls.
- Pass data from parent components (pages) to child components (e.g., line charts, selectors) to render the visualizations and interactive elements.
- Some components, such as those handling watchlist functionality, also trigger actions that modify application state or local storage by invoking functions like saveItemToWatchlist or removeItemToWatchlist.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: Emphasize reusable UI components structured by feature (e.g., CoinPage, Dashboard) and shared/common utilities.
- Separation of Concerns:
- Presentation (React components and CSS files) is kept separate from business logic (utility functions).
- Data fetching and API integration reside within the functions directory rather than being embedded inside components.
- Service Integration: Use of external data services (CoinGecko API) is clearly isolated, making it easier to test and update.
- Responsive Design Principles: Although not explicitly detailed, the use of MUI hints at a design that may be responsive and consistent across devices.
- Animations and Enhanced UX: Framer Motion is used to introduce fluid animations to transitions and interactions.

##### Technologies, Frameworks, and Libraries
- React.js for UI rendering and component management.
- Material-UI (MUI) for styled React components.
- Chart.js for rendering interactive time-series charts.
- Axios for making API calls to the CoinGecko API.
- Framer Motion for smooth UI animations.
- CSS modules or component-specific style files for custom styling.

##### Components
- Labels: Use clear labels for every component, such as “LandingPage,” “CoinPage,” “Dashboard,” “ComparePage,” and “Watchlist.”

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global Entities
    User["User"]:::ui
    App["App Component"]:::ui

    %% User Interaction Layer
    User --> App

    %% Pages Layer
    subgraph "Pages"
        LandingPage["LandingPage"]:::ui
        CoinPage["CoinPage"]:::ui
        ComparePage["ComparePage"]:::ui
        Dashboard["Dashboard"]:::ui
        Watchlist["Watchlist"]:::ui
    end

    %% App routing to pages
    App --> LandingPage
    App --> CoinPage
    App --> ComparePage
    App --> Dashboard
    App --> Watchlist

    %% CoinPage Subcomponents
    subgraph "CoinPage Components"
        Info["Info"]:::ui
        LineChart["LineChart"]:::ui
        SelectDays["SelectDays"]:::ui
        ToggleComponent["ToggleComponent"]:::ui
    end
    %% CoinPage breakdown connections
    CoinPage --> Info
    CoinPage --> LineChart
    CoinPage --> SelectDays
    CoinPage --> ToggleComponent

    %% Dashboard Subcomponents
    subgraph "Dashboard Components"
        Grid["Grid"]:::ui
        List["List"]:::ui
        Pagination["Pagination"]:::ui
        Search["Search"]:::ui
        Tabs["Tabs"]:::ui
    end
    %% Dashboard breakdown connections
    Dashboard --> Grid
    Dashboard --> List
    Dashboard --> Pagination
    Dashboard --> Search
    Dashboard --> Tabs

    %% Common Components used across pages
    subgraph "Common Components"
        Header["Header & Drawer"]:::common
        Footer["Footer"]:::common
        Button["Button"]:::common
        Loader["Loader"]:::common
        TopButton["TopButton"]:::common
    end
    %% Assume App integrates common components
    App --> Header
    App --> Footer
    App --> Button
    App --> Loader
    App --> TopButton

    %% Utility Functions for business logic and API calls
    Utility["Utility Functions"]:::utils

    %% UI components interaction with Utility Functions
    Info --> Utility
    LineChart --> Utility
    SelectDays --> Utility
    ToggleComponent --> Utility
    Grid --> Utility
    List --> Utility
    Pagination --> Utility
    Search --> Utility
    Tabs --> Utility

    %% External API Service
    ExternalAPI["CoinGecko API"]:::external
    Utility -- "fetchesData" --> ExternalAPI

    %% Click Events
    click App "https://github.com/divyanshu-yu/crypto-project/blob/main/src/App.js"
    click LandingPage "https://github.com/divyanshu-yu/crypto-project/tree/main/src/components/LandingPage/MainComponent"
    click Info "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/CoinPage/Info/index.js"
    click LineChart "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/CoinPage/LineChart/index.js"
    click SelectDays "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/CoinPage/SelectDays/index.js"
    click ToggleComponent "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/CoinPage/ToggleComponent/index.js"
    click ComparePage "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/ComparePage/SelectCoins/index.js"
    click Grid "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Dashboard/Grid/index.js"
    click List "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Dashboard/List/index.js"
    click Pagination "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Dashboard/Pagination/index.js"
    click Search "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Dashboard/Search/index.js"
    click Tabs "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Dashboard/Tabs/index.js"
    click Watchlist "https://github.com/divyanshu-yu/crypto-project/blob/main/src/pages/Watchlist.js"
    click Header "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Common/Header/index.js"
    click Footer "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Common/Footer/footer.js"
    click Button "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Common/Button/index.js"
    click Loader "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Common/Loader/index.js"
    click TopButton "https://github.com/divyanshu-yu/crypto-project/blob/main/src/components/Common/TopButton/index.js"
    click Utility "https://github.com/divyanshu-yu/crypto-project/tree/main/src/functions"
    click ExternalAPI "https://github.com/divyanshu-yu/crypto-project/blob/main/src/functions/getCoinData.js"

    %% Styles
    classDef ui fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef common fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef utils fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
