# jondoescoding/kryptt architecture

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

- Interactive diagram: https://gitdiagram.com/jondoescoding/kryptt
- Repository: https://github.com/jondoescoding/kryptt

## Overview

##### Main Components
- Frontend: This is a Next.js application located under the “frontend” directory. It contains pages for login, registration, dashboards, and various trading-related functionalities. It also includes API routes that interact with the backend, custom components (UI elements, hooks, layouts), and integration with Supabase for authentication.
- Backend: Held in the “backend” directory, the backend uses FastAPI (with uvicorn for development) to expose RESTful endpoints. It’s structured with an “api/v1” folder that contains routes for account management, agents, trading assets, models, and tools. The “core” folder contains configurations, cross-origin resource sharing (CORS) settings, logging, and service initialization logic.
- External Integrations:
- Alpaca API: Facilitates trading operations (orders, positions) through secure, regulated channels.
- Supabase: Manages user authentication (JWT sessions) and likely provides database services. Files in “frontend/src/lib/supabase” suggest both client and server integration.
- Future integrations: A donation system via Paddle, as noted in the README.
- LLM models and LangGraph: Suggested integration points for natural language trading, where users may issue commands like “Buy $50 AAPL.”

##### Architectural Patterns
- Separation of Concerns: Clear isolation between the frontend and backend services ensures modularity. The frontend layer handles user interaction and presentation, while the backend manages business logic, trading execution, and external API integration.
- Modularized API Endpoints: The “api/v1” directory in the backend indicates versioning and a structured approach to exposing different functionalities, such as accounts, agents, models, and tools.
- Service and Integration Layers: The “core” folder encapsulates configuration, logging, CORS, and agent initialization. Likewise, external services (e.g., Alpaca and Supabase) are integrated at specific touching points which should be clearly defined in the system design.

- Frontend (Next.js Application): Highlight pages (auth, dashboard, chat, and settings) and key libraries (Supabase client, UI components, hooks).
- Backend (FastAPI Application): Include sub-components such as API endpoints (account, agents, assets, models, tools) and core modules (config, logging, agent initialization).
- External Services:
▪ Alpaca API: Emphasize integration via trading endpoints and order management.
▪ Supabase: Authentication, user management, and possibly database services.
▪ Future Donation Integration (Paddle).
- AI/LLM Service: If applicable, label a component representing natural language trading command processing, indicating where LLM models and associated tools may be applied.

- The Frontend communicates with the Backend via HTTP APIs.
- The Backend sends requests to external services (Alpaca, Supabase).
- Inter-module communication within the backend (e.g., API endpoints calling core services and agents) can also be represented.

##### Specific Architectural Details
- For the Frontend:
- File tree components such as “src/app/auth”, “dashboard”, and “components” to indicate the compartmentalization of UI functionality.
- State management and API calls that integrate with authentication via Supabase.
- For the Backend:
- Layering inside the “backend/app” directory: the “api/v1” endpoints for trading logic, agents for processing orders and positions, and core modules that handle configurations and logging.
- How environment variables (.env file) and configuration management support different deployment scenarios as explained in the README.
- For External Services:
- Clearly demarcate interactions with Alpaca for live trade operations and with Supabase for JWT-based secure authentication.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE["Next.js Application"]:::frontend
        FE1["Authentication Pages"]:::frontend
        FE2["Authentication Components"]:::frontend
        FE3["Trading API Endpoints"]:::frontend
        FE4["Supabase Integration (Client & Server)"]:::frontend
    end

    subgraph "Backend Layer"
        BE["FastAPI Application"]:::backend
        BE1["API Endpoints (v1)"]:::backend
        BE2["Agents (Order & Position Management)"]:::backend
        BE3["Tools (Orders & Positions)"]:::backend
        BE4["Core Services & Configurations"]:::backend
        BE5["Alpaca API Integration (Trading Data)"]:::backend
    end

    subgraph "External Services"
        EX1["Alpaca API"]:::external
        EX2["Supabase Service"]:::external
        EX3["Donation Integration (Paddle)"]:::external
        EX4["AI/LLM Service"]:::external
    end

    %% Relationships between Frontend and Backend
    FE -->|"HTTP_API"| BE1
    FE4 -->|"Uses"| EX2

    %% Backend internal relationships
    BE1 -->|"Calls"| BE4
    BE1 -->|"RoutesTo"| BE2
    BE1 -->|"RoutesTo"| BE3
    BE1 -->|"Contains"| BE5
    BE2 -->|"CollaboratesWith"| BE3
    BE2 -->|"Manages"| BE5
    BE3 -->|"Manages"| BE5
    
    %% Backend integration with External Services
    BE5 -->|"IntegratesWith"| EX1
    BE1 -->|"UtilizesAuth"| EX2
    BE1 -->|"MayInvokeNLP"| EX4

    %% Click Events for Frontend
    click FE "https://github.com/jondoescoding/kryptt/tree/main/frontend/"
    click FE1 "https://github.com/jondoescoding/kryptt/tree/main/frontend/src/app/(auth)"
    click FE2 "https://github.com/jondoescoding/kryptt/tree/main/frontend/src/components/auth"
    click FE3 "https://github.com/jondoescoding/kryptt/tree/main/frontend/src/app/api/alpaca"
    click FE4 "https://github.com/jondoescoding/kryptt/tree/main/frontend/src/lib/supabase"

    %% Click Events for Backend
    click BE1 "https://github.com/jondoescoding/kryptt/tree/main/backend/app/api/v1"
    click BE2 "https://github.com/jondoescoding/kryptt/tree/main/backend/app/api/v1/agents"
    click BE3 "https://github.com/jondoescoding/kryptt/tree/main/backend/app/api/v1/tools"
    click BE4 "https://github.com/jondoescoding/kryptt/tree/main/backend/app/core"
    click BE5 "https://github.com/jondoescoding/kryptt/blob/main/backend/app/api/v1/models/alpaca_user_data.py"

    %% Styles
    classDef frontend fill:#90ee90,stroke:#006400,stroke-width:2px;
    classDef backend fill:#add8e6,stroke:#00008b,stroke-width:2px;
    classDef external fill:#ffe4e1,stroke:#8b0000,stroke-width:2px;
```
