# lorenzopalaia/blocktracr architecture

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

- Interactive diagram: https://gitdiagram.com/lorenzopalaia/blocktracr
- Repository: https://github.com/lorenzopalaia/blocktracr

## Overview

Based on an analysis of the file tree and README, Blocktracr is a full-stack web application that displays cryptocurrency market data and provides wallet reports, built with Next.js/React. The system architecture is divided between a client-facing frontend (UI, pages, and components) and server-side backend logic (API endpoints, authentication, and data fetching), plus integration with an external service (Supabase) for the database and authentication.

##### Core Components
- Frontend UI: Represented by the Next.js “app” directory that mostly mirrors the new “app” directory structure in Next.js 13. This includes pages (e.g., dashboard, coins, docs, error pages, account, cookie, etc.) and components (in “app/components” and “components”) for building the user interface.
- API Endpoints: Under “app/api”, separate folders are dedicated to authentication (signin, signup, forgot/reset password, signout, confirm) and cryptocurrency specific endpoints (coins, crypto-list, market-chart, global-market-data, trending). These endpoints are responsible for processing HTTP requests, interacting with data, and responding with JSON.
- State Management & Data Fetching: Custom hooks (in “hooks”) and stores (in “stores”) facilitate asynchronous data retrieval and manage UI state. They are key connectors between the UI components and the API.
- External Services: Supabase is used as the backend service and data store. SQL script files in the “supabase” folder (e.g., exchanges.sql, profiles.sql) highlight the database schema. Also include integration utilities in “utils/supabase”.
- Utility & Config Layers: The “utils”, “types”, “config” files and middleware (Next.js’s middleware.ts) handle cross-cutting concerns like encryption, price conversion, and client/server-side integration.

##### Establish Relationships and Interactions
- Client (Browser) → Frontend: Users interact with the UI built with React, with pages such as dashboard, coins details and account pages.
- UI Components & Hooks ↔ State Stores: Components use custom hooks to fetch data from the API, which are then stored in client-side state stores for reactivity.
- API Endpoints ↔ Supabase: The API endpoints interact with Supabase for running SQL operations, authentication verification, and data retrieval. Clearly mark these dependencies.
- Middleware & Routing: Highlight the role of Next.js middleware and configuration (e.g., next.config.ts) that routes requests and possibly applies site-wide logic (like theming via “ThemeProvider” found in the components).

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project clearly separates the UI (presentational components), data fetching logic (hooks and stores), and backend processes (API endpoints).
- Modular Design: Different directories (account, dashboard, coins, docs) encapsulate features into distinct modules.
- Component Reusability: Extensive use of shared UI components (appearing in both “app/components” and “components/ui”) that promote reusability and consistency.
- Integration with External Services: Supabase integration for database operations and user authentication, along with state management libraries in hooks and stores.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    A("User Browser"):::client

    %% Frontend Layer
    subgraph "Frontend (Next.js UI & Components)"
        B("Next.js Frontend\n(app/ directory)"):::frontend
        C("UI Components\n(app/components, components/)"):::frontend
        D1("Custom Hooks\n(hooks)"):::state
        D2("State Stores\n(stores)"):::state
        E("Routing & Middleware\n(middleware.ts, next.config.ts)"):::utils
    end

    %% Backend API Layer
    subgraph "Backend (API Endpoints)"
        F("Authentication API\n(app/api/auth)"):::api
        G("Crypto Data API\n(app/api/coins, crypto-list, market-chart, global-market-data, trending)"):::api
    end

    %% External Services
    subgraph "External Services"
        H("Supabase Database"):::db
        I("Supabase Integration\n(utils/supabase)"):::db
    end

    %% Utilities & Config
    subgraph "Utilities & Config"
        J("Utility Functions\n(utils, encryption.ts, price.ts)"):::utils
        K("Type Definitions\n(types)"):::utils
        L("Configuration\n(config.ts)"):::utils
    end

    %% Relationships
    A -->|"accesses"| B
    B -->|"renders"| C
    C -->|"invokes"| D1
    D1 -->|"updates"| D2
    D1 -->|"fetchesData"| F
    D1 -->|"fetchesData"| G
    B -->|"routes"| E
    C -->|"calls"| F
    C -->|"calls"| G
    F -->|"interacts"| H
    G -->|"interacts"| H
    F -->|"utilizes"| I
    G -->|"utilizes"| I
    H -->|"responds"| F
    H -->|"responds"| G
    F -->|"configuredBy"| J
    G -->|"configuredBy"| J
    E -->|"applies"| L

    %% Click Events
    click B "https://github.com/lorenzopalaia/blocktracr/tree/main/app/"
    click C "https://github.com/lorenzopalaia/blocktracr/tree/main/app/components"
    click F "https://github.com/lorenzopalaia/blocktracr/tree/main/app/api/auth"
    click G "https://github.com/lorenzopalaia/blocktracr/tree/main/app/api/coins"
    click D1 "https://github.com/lorenzopalaia/blocktracr/tree/main/hooks"
    click D2 "https://github.com/lorenzopalaia/blocktracr/tree/main/stores"
    click I "https://github.com/lorenzopalaia/blocktracr/tree/main/utils/supabase"
    click H "https://github.com/lorenzopalaia/blocktracr/tree/main/supabase"
    click J "https://github.com/lorenzopalaia/blocktracr/tree/main/utils"
    click K "https://github.com/lorenzopalaia/blocktracr/tree/main/types"
    click L "https://github.com/lorenzopalaia/blocktracr/blob/main/config.ts"
    click E "https://github.com/lorenzopalaia/blocktracr/blob/main/middleware.ts"

    %% Class Definitions
    classDef client fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef api fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef db fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef utils fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef state fill:#d1c4e9,stroke:#333,stroke-width:2px;
```
