# embracextech/basket-agent-mini-app architecture

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

- Interactive diagram: https://gitdiagram.com/embracextech/basket-agent-mini-app
- Repository: https://github.com/embracextech/basket-agent-mini-app

## Overview

##### Main Components
- Frontend/UI Layer: Represented by the React-based components, pages, and layouts. Key folders are:
- src/components: Contains the reusable UI elements such as TokenModal, Agent Cards, forms (multi-step for agent creation), modals (e.g., TerminateModal), and base components for error handling, links, and date pickers.
- src/pages: Major routed pages like AssetPage, CreatePage, MainPage, ManagePage (with sub-pages like Deposit and Withdraw).
- src/navigation: Route definitions that control the flow of the app.
- Core/Services Layer: Encapsulated in the src/services folder. These files (e.g., agent.service.ts, token.service.ts) handle API interactions including authentication, chain operations, and interactions with external Para services.
- State Management & Data Fetching: The src/stores and src/core/tanstack-query folders suggest the use of state management and query management to handle asynchronous data.
- Utility & Constants Layer: Utilities in src/utils and constants in src/constants define common helper functions, formatting, environmental variables, and core business constants (like tokens, chains, and logging formats).
- External Integrations: The README directs the user to integrate with external resources:
- Para API (for wallet and secure onboarding)
- Reown API and Basket Agent API (handled externally)

##### Relationships & Interactions
- The UI components (under src/components and src/pages) interact with services (src/services) for data fetching and trading operations.
- Navigation (src/navigation/routes.tsx) orchestrates the routing between pages.
- State management (src/stores and tanstack-query’s provider) distributes and caches data across components.
- External APIs (Para, Reown) are invoked via service layers, establishing network call flows from the frontend to these external systems.
- Core utilities support the transformation and formatting of data across components and services.

##### Architectural Patterns / Design Principles
- Modular Component-Based Architecture: The separation into various features (agent creation, asset management, trade logs) hints at a well-layered modular approach.
- Separation of Concerns: Dividing UI elements, service layers, and state management ensures that each module is responsible for a single piece of functionality.
- Micro Frontend Patterns (if any significant decomposition exists): Though not a full micro front-end system, the separation between Manage, Test, and Main pages along with the agent components indicates logical separation for ease of maintenance.
- Dependency Injection and Centralized Configuration: Notice how environment configuration and Axios core are placed in src/core/env and src/core/axios.
- Organized Routing: The navigation folder and clearly separated pages indicate a route-based design which is central to modern SPAs.

##### Technologies, Frameworks & Libraries
- React + TypeScript for UI components.
- Vite as the build tool and development server (check vite.config.ts).
- Integration with external APIs like Para via dedicated providers (src/core/para/provider.tsx, config.ts).
- Tanstack (likely React Query) for asynchronous query management (src/core/tanstack-query).
- Styling using Tailwind CSS (tailwind.config.js) along with custom CSS files (e.g., datepicker.css, DisplayData.css).
- Axios for API requests (under src/core/axios).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Application Subgraphs
    subgraph "Frontend Application"
        %% UI Layer
        subgraph "UI Layer"
            UI["UI Components (React+TS)"]:::ui
            PAGES["Pages"]:::ui
            NAV["Navigation"]:::ui
        end

        %% State Management
        subgraph "State Management"
            STORE["Stores"]:::state
            TANSTACK["Tanstack Query Provider"]:::state
        end

        %% Services & Business Logic
        subgraph "Services & Business Logic"
            SERVICES["Services"]:::service
            AXIOS["Axios Core"]:::service
        end

        %% Utilities & Constants
        subgraph "Utilities & Constants"
            UTIL["Utilities"]:::util
            CONST["Constants"]:::util
        end

        %% Environment & Configuration
        subgraph "Environment & Configuration"
            ENV["Env Config"]:::config
            VITE["Vite Config"]:::config
            TAILWIND["Tailwind CSS"]:::config
            POSTCSS["PostCSS Config"]:::config
        end
    end

    %% External Integrations Subgraph
    subgraph "External Integrations"
        PARA["Para Integration"]:::external
        BASKET["Basket Agent API"]:::external
        REOWN["Reown API"]:::external
    end

    %% Connections within Frontend Application
    NAV -->|"routes_to"| PAGES
    UI -->|"updates_state"| STORE
    PAGES -->|"uses_state"| TANSTACK

    UI -->|"calls_service"| SERVICES
    PAGES -->|"calls_service"| SERVICES

    %% Service Layer calling external APIs
    SERVICES -->|"API_call"| BASKET
    SERVICES -->|"API_call"| REOWN
    AXIOS -->|"handles_requests"| PARA

    %% Utilities & Constants supporting UI and Services
    UTIL ---|"supports"| UI
    UTIL ---|"supports"| SERVICES
    CONST ---|"defines"| SERVICES

    %% Environment & Configuration supporting core modules
    ENV ---|"configures"| SERVICES
    VITE ---|"build_tool"| SERVICES
    TAILWIND ---|"styles"| UI
    POSTCSS ---|"styles"| UI

    %% Class definitions for styling
    classDef ui fill:#f9e79f,stroke:#b9770e,stroke-width:2px;
    classDef state fill:#a9dfbf,stroke:#239B56,stroke-width:2px;
    classDef service fill:#fad7a0,stroke:#CA6F1E,stroke-width:2px;
    classDef util fill:#aed6f1,stroke:#2471A3,stroke-width:2px;
    classDef config fill:#f5b7b1,stroke:#922B21,stroke-width:2px;
    classDef external fill:#f1948a,stroke:#922B21,stroke-width:2px;

    %% Click Events for mapped components
    click UI "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/components"
    click PAGES "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/pages"
    click NAV "https://github.com/embracextech/basket-agent-mini-app/blob/main/src/navigation/routes.tsx"
    click SERVICES "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/services"
    click AXIOS "https://github.com/embracextech/basket-agent-mini-app/blob/main/src/core/axios/index.ts"
    click STORE "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/stores"
    click TANSTACK "https://github.com/embracextech/basket-agent-mini-app/blob/main/src/core/tanstack-query/provider.tsx"
    click UTIL "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/utils"
    click CONST "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/constants"
    click PARA "https://github.com/embracextech/basket-agent-mini-app/tree/main/src/core/para"
    click ENV "https://github.com/embracextech/basket-agent-mini-app/blob/main/src/core/env/index.ts"
    click VITE "https://github.com/embracextech/basket-agent-mini-app/blob/main/vite.config.ts"
    click TAILWIND "https://github.com/embracextech/basket-agent-mini-app/blob/main/tailwind.config.js"
    click POSTCSS "https://github.com/embracextech/basket-agent-mini-app/blob/main/postcss.config.js"
```
