# ttmordred/cryptopath architecture

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

- Interactive diagram: https://gitdiagram.com/ttmordred/cryptopath
- Repository: https://github.com/ttmordred/cryptopath

## Overview

##### Main Components
- Frontend: The application leverages Next.js (React/TypeScript) and Tailwind CSS and is organized under the “app” directory for page-level routing. This includes features such as the Blockchain Explorer, NFT collection pages, Faucet, Portfolio Tracker, Swap, Staking, Click2Earn game, and AI Support Chat. Also, note the “components” directory that provides reusable UI components, custom hooks, and layout pieces.
- Backend/API Layer: Under “app/api” you have a multitude of endpoints (e.g., alchemy, analytics, binance, chainalysis, coinmarketcap, etc.) that expose blockchain data and other financial/market metrics. These endpoints form the data access layer which the frontend consumes.
- Integration & Service Layer: Directories such as “lib”, “services”, and “src/integrations” contain business logic and integration modules for third-party APIs. For instance, they house integration logic for Etherscan, Alchemy, Moralis, Binance, and CoinMarketCap, and also for blockchain utilities.
- Database & External Systems: The project uses a Neo4j graph database for managing graph-oriented blockchain data. Additionally, the README mentions integration with providers like Infura, WalletConnect, and authentication solutions with NextAuth.js.
- State Management & Context: Global state through React’s Context API is used (see “app/QueryProvider.tsx”, “components/context”, and “lib/context”) to manage things such as authentication state, settings, and user session data.

##### Relationships and Data Flow
- Client Tier: End users interact via the web browser (using Next.js pages). Their actions (searches, dashboard interactions, portfolio updates) are handled by the frontend components and pages.
- API Gateway: The Next.js API endpoints (within “app/api”) receive requests from the client and may in turn fetch data from:
– Blockchain data providers (e.g., Etherscan, Infura, Alchemy),
– Market analytics services (e.g., CoinMarketCap, Binance),
– NFT-specific endpoints,
– And even cross-chain or risk analysis services like Chainalysis.
- Service & Integration Layer: The “lib” and “services” directories encapsulate logic for making external API calls. They act as a bridge between the API endpoints and external systems.
- Database Layer: Data that require persistence (e.g., transaction metadata, user interactions) can be routed to or retrieved from the Neo4j database.
- External API & 3rd-Party Services: The system interacts with multiple external platforms (Moralis, DappRadar, Google Gemini, etc.) where appropriate.

##### Key Architectural Patterns & Design Principles
- Full-Stack Separation: Clearly maintain distinct layers for UI, API/backend logic, and third-party integrations.
- Modular and Reusable Components: The rich “components” folder is structured to maximize reuse and maintain clear separation of concerns.
- API-Centric Design: RESTful API endpoints are used for data consumption by frontend pages.
- Integration Abstraction: The service and lib directories abstract third party service integration, simplifying the API endpoints’ responsibilities.
- State Management: Use of React Context and custom hooks (like in “hooks”) helps maintain application state across the client.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Tier"
        FE_Pages("Next.js Pages (app directory)"):::frontend
        FE_Components("UI Components (components directory)"):::frontend
    end

    subgraph "State Management"
        QueryProvider("Query Provider (app/QueryProvider.tsx)"):::state
        UIContext("UI Context (components/context)"):::state
        AuthContext("Auth Context (lib/context/AuthContext.tsx)"):::state
    end

    subgraph "API Backend"
        API("API Endpoints (app/api)"):::api
    end

    subgraph "Integration & Service Layer"
        Alchemy("Alchemy API Logic"):::integration
        CoinAPI("Coin Data Logic"):::integration
        Binance("Binance Service"):::integration
        CMC("CoinMarketCap Service"):::integration
        Supabase("Supabase Integration"):::integration
    end

    subgraph "External & Database"
        Neo4j("Neo4j Database"):::database
        External("External Services"):::external
    end

    %% Relationships between layers
    QueryProvider -->|"provides state"| FE_Pages
    UIContext -->|"provides UI state"| FE_Pages
    AuthContext -->|"manages auth"| FE_Pages

    FE_Pages -->|"APIRequest/Response"| API

    API -->|"calls"| Alchemy
    API -->|"calls"| CoinAPI
    API -->|"calls"| Binance
    API -->|"calls"| CMC
    API -->|"calls"| Supabase
    API -->|"DBAccess"| Neo4j

    Alchemy -->|"fetch"| External
    CoinAPI -->|"fetch"| External
    Binance -->|"fetch"| External
    CMC -->|"fetch"| External
    Supabase -->|"fetch"| External

    %% Class Definitions
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef state fill:#ffd,stroke:#333,stroke-width:2px;
    classDef api fill:#f96,stroke:#333,stroke-width:2px;
    classDef integration fill:#afa,stroke:#333,stroke-width:2px;
    classDef database fill:#fcf,stroke:#333,stroke-width:2px;
    classDef external fill:#eef,stroke:#333,stroke-width:2px;

    %% Click Events
    click FE_Pages "https://github.com/ttmordred/cryptopath/tree/main/app"
    click FE_Components "https://github.com/ttmordred/cryptopath/tree/main/components"
    click API "https://github.com/ttmordred/cryptopath/tree/main/app/api"
    click Alchemy "https://github.com/ttmordred/cryptopath/blob/main/lib/api/alchemyApi.ts"
    click CoinAPI "https://github.com/ttmordred/cryptopath/blob/main/lib/api/coinApi.ts"
    click Binance "https://github.com/ttmordred/cryptopath/blob/main/services/binanceApiService.ts"
    click CMC "https://github.com/ttmordred/cryptopath/blob/main/services/coinMarketCapService.ts"
    click Supabase "https://github.com/ttmordred/cryptopath/tree/main/src/integrations/supabase"
    click QueryProvider "https://github.com/ttmordred/cryptopath/blob/main/app/QueryProvider.tsx"
    click UIContext "https://github.com/ttmordred/cryptopath/tree/main/components/context"
    click AuthContext "https://github.com/ttmordred/cryptopath/blob/main/lib/context/AuthContext.tsx"
    click Neo4j "https://github.com/ttmordred/cryptopath/blob/main/lib/neo4j.ts"
```
