# phamhau23/bitcoin-chart architecture

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

- Interactive diagram: https://gitdiagram.com/phamhau23/bitcoin-chart
- Repository: https://github.com/phamhau23/bitcoin-chart

## Overview

##### Main Components
- Frontend UI: Represented primarily by the pages and components in the “app” directory. The main entry points are:
- Page: “app/page.tsx” (the main page that the user sees).
- Layout: “app/layout.tsx” (defining the global layout and shared UI structures).
- Components: Found in “app/components” (such as Button, ButtonList, CandlestickChart, CurrentCoinPrice, ToggleTheme, and VolumeChart), which are used to render interactive parts of the UI.
- API Integration / Server-Side Functionality: Located in “app/api”, for instance “app/api/binanceApi.tsx”, which likely handles fetching data from the Binance service.
- Context and Global State: The “app/context” directory contains theme toggling (e.g., toggleTheme.tsx) so include a context component that supports global state management.
- Utility Functions / Libraries: The “app/lib/convertUnixTime.tsx” provides helper functions that are used across the application.
- Static Assets & Global Styling: “app/globals.css”, TailwindCSS configuration (tailwind.config.ts, postcss.config.mjs) and the “public” directory for static assets.
- Configuration and Build Tools: Files like “next.config.ts”, “tsconfig.json”, “package.json”, and “eslint.config.mjs” inform how the app is built and deployed.

##### Relationships and Interactions
- Interface Layer: The user interacts with the application via the browser which loads the main page (app/page.tsx) and other UI components.
- Component Composition: The layout (app/layout.tsx) wraps the page and all components, with each component (charts, buttons, price displays) interacting by receiving props or accessing shared state (e.g., theme context).
- Data Flow: The API layer (app/api/binanceApi.tsx) is called either directly from server components or via client-side fetches. It communicates with an external Binance service to retrieve data, which is then formatted (possibly using utilities from “app/lib”) and passed to UI components like CandlestickChart or VolumeChart.
- Context Usage: Global state (such as the theme) flows from the context provider in “app/context/toggleTheme.tsx” down to various components, controlling appearance and behavior.

##### Architectural Patterns
- Component-Based Architecture: Built around modular React components for reusability.
- Separation of Concerns: Clear separation between API/backend functionality, UI components, and context/state management.
- Server/Client Components: Usage of Next.js’s new app directory structure suggests a mix of server-side rendering (pages and API endpoints) and client-side interactivity (components imported in pages).

##### Relevant Technologies
- Next.js for the framework and routing.
- React for building UI components.
- Tailwind CSS for styling.
- TypeScript, as indicated by the .tsx files and tsconfig.json.
- External integration with Binance (via the “binanceApi.tsx” file).
- Vercel and next/font for deployment and font optimization respectively.

▸ From the “User/Browser” to “UI (app/page.tsx → app/layout.tsx → Components)”.
▸ From UI components to the “API Layer (binanceApi.tsx)” indicating data requests.
▸ From the API layer to the “External Binance Service” representing data fetching.
- Role of static assets and styling by showing the connection to Tailwind and global CSS files.
- A deployment note (like Vercel) to indicate where the application will be hosted.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interaction
    Browser["Browser/User"]:::external

    %% Frontend UI
    subgraph "Frontend UI"
        Page["Main Page (Page)"]:::frontend
        Layout["Global Layout"]:::frontend
    end

    %% UI Components
    subgraph "UI Components"
        Button["Button Component"]:::component
        ButtonList["Button List"]:::component
        Candlestick["CandlestickChart – displays price trends"]:::component
        CurrentPrice["Current Coin Price"]:::component
        ToggleTheme["ToggleTheme – manages UI theme state"]:::component
        VolumeChart["VolumeChart"]:::component
    end

    %% API & Server-Side Functionality
    subgraph "API & Server"
        BinanceAPI["binanceApi – fetches live data"]:::api
        ExternalService["External Binance Service"]:::externalService
    end

    %% Context & Utilities
    subgraph "Context & Utilities"
        ThemeContext["Theme Toggle Context"]:::context
        ConvertTime["Convert Unix Time Utility"]:::utility
    end

    %% Static Assets & Configuration
    subgraph "Static Assets & Config"
        GlobalCSS["Global CSS"]:::static
        Tailwind["Tailwind CSS Config"]:::static
        NextConfig["Next.js Config"]:::config
        TSConfig["TypeScript Config"]:::config
        PackageJSON["Package.json"]:::config
        ESLint["ESLint Config"]:::config
        PublicAssets["Public Assets"]:::static
    end

    %% Flow Connections
    Browser -->|"requests"| Page
    Page -->|"renders via"| Layout
    Layout -->|"composes"| Button
    Layout -->|"composes"| ButtonList
    Layout -->|"composes"| Candlestick
    Layout -->|"composes"| CurrentPrice
    Layout -->|"composes"| ToggleTheme
    Layout -->|"composes"| VolumeChart

    %% UI Components interactions with API & Context
    ToggleTheme -->|"accesses"| ThemeContext
    Candlestick -->|"transforms data using"| ConvertTime
    VolumeChart -->|"fetches data from"| BinanceAPI
    CurrentPrice -->|"fetches data from"| BinanceAPI
    ButtonList -->|"triggers"| BinanceAPI

    %% API Integration
    BinanceAPI -->|"calls"| ExternalService

    %% Styling connections
    Layout -->|"styled by"| GlobalCSS
    Button -->|"styled by"| GlobalCSS
    ButtonList -->|"styled by"| GlobalCSS
    Candlestick -->|"styled by"| GlobalCSS
    CurrentPrice -->|"styled by"| GlobalCSS
    ToggleTheme -->|"styled by"| GlobalCSS
    VolumeChart -->|"styled by"| GlobalCSS

    %% Build & Configuration support
    Layout -->|"configured by"| NextConfig
    Page -->|"configured by"| TSConfig
    Layout -->|"uses"| Tailwind
    Button -->|"uses"| Tailwind
    ExternalService -->|"deployment info"| PackageJSON
    NextConfig -->|"linted by"| ESLint

    %% Click Events for Component Mapping
    click Page "https://github.com/phamhau23/bitcoin-chart/blob/main/app/page.tsx"
    click Layout "https://github.com/phamhau23/bitcoin-chart/blob/main/app/layout.tsx"
    click Button "https://github.com/phamhau23/bitcoin-chart/blob/main/app/components/Button.tsx"
    click ButtonList "https://github.com/phamhau23/bitcoin-chart/blob/main/app/components/ButtonList.tsx"
    click Candlestick "https://github.com/phamhau23/bitcoin-chart/blob/main/app/components/CandlestickChart.tsx"
    click CurrentPrice "https://github.com/phamhau23/bitcoin-chart/blob/main/app/components/CurrentCoinPrice.tsx"
    click ToggleTheme "https://github.com/phamhau23/bitcoin-chart/blob/main/app/components/ToggleTheme.tsx"
    click VolumeChart "https://github.com/phamhau23/bitcoin-chart/blob/main/app/components/VolumeChart.tsx"
    click BinanceAPI "https://github.com/phamhau23/bitcoin-chart/blob/main/app/api/binanceApi.tsx"
    click ThemeContext "https://github.com/phamhau23/bitcoin-chart/blob/main/app/context/toggleTheme.tsx"
    click ConvertTime "https://github.com/phamhau23/bitcoin-chart/blob/main/app/lib/convertUnixTime.tsx"
    click GlobalCSS "https://github.com/phamhau23/bitcoin-chart/blob/main/app/globals.css"
    click Tailwind "https://github.com/phamhau23/bitcoin-chart/blob/main/tailwind.config.ts"
    click ESLint "https://github.com/phamhau23/bitcoin-chart/blob/main/eslint.config.mjs"
    click NextConfig "https://github.com/phamhau23/bitcoin-chart/blob/main/next.config.ts"
    click TSConfig "https://github.com/phamhau23/bitcoin-chart/blob/main/tsconfig.json"
    click PackageJSON "https://github.com/phamhau23/bitcoin-chart/blob/main/package.json"
    click PublicAssets "https://github.com/phamhau23/bitcoin-chart/tree/main/public"

%% Styles
classDef frontend fill:#C6E2FF,stroke:#034078,stroke-width:2px;
classDef component fill:#FFEEAD,stroke:#FF7F50,stroke-width:2px;
classDef api fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
classDef externalService fill:#FADCD9,stroke:#E74C3C,stroke-width:2px,stroke-dasharray:5 5;
classDef context fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
classDef utility fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
classDef static fill:#D6EAF8,stroke:#2980B9,stroke-width:2px;
classDef config fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
