# nathanliow/opensol architecture

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

- Interactive diagram: https://gitdiagram.com/nathanliow/opensol
- Repository: https://github.com/nathanliow/opensol

## Overview

##### Main Components
a. Frontend: This is the user interface built with Next.js. Include subcomponents such as:
- Application Pages (the “app” directory including dashboards, project pages, etc.).
- API routes for authentication and projects.
- Component modules (canvas, code display, nodes, templates, etc.) that create the visual programming interface.
- Providers and contexts (for managing state such as Supabase authentication and wallet context).
b. Backend: Focus on its modular “block-functions” architecture. Show:
- Block functions organized by subcategories (“default”, “helius”, “defi”, “misc”).
- The specialized compiler package that converts user flows into executable actions through modules like FlowCompiler.
c. Blockchain Contracts: Include the smart contract layer (e.g., fee_manager.rs) managed in the apps/contracts directory, which interacts with the Solana blockchain.
d. External Services:
- Helius API endpoints (evident from the extensive set of functions under block-functions/helius).
- Supabase as a data persistence/authentication layer (as hinted in the frontend’s libs and providers).

##### Relationships and Interactions
- Users interact with the Frontend (visual programming UI) to create flows.
- The Frontend communicates with Backend APIs (for retrieval and execution of block functions).
- The Backend executes block-functions that interface with external services like Helius (for blockchain data) and potentially Supabase (for user data and persistence).
- The Backend and/or Frontend may also interact with blockchain contracts on Solana (for performing transactions, fee management, etc.).
- Method invocations such as wallet logins, project submissions, and contributions relating to the incentivization model—underscoring how front-end actions translate into blockchain operations.

##### Architectural Patterns and Design Principles
- Modular Architecture: Emphasize how the backend splits functionality into distinct “block-functions” modules (default, helius, defi, misc) and a separate compiler package, supporting extensibility and community contributions.
- Separation of Concerns: Clearly segregate the frontend (UI/UX and client-side interactions) from the backend (business logic and blockchain interactions) to adhere to clean architectural patterns.
- No-Code Visual Programming Layer: Illustrate how the visual node system (with components like FunctionNode, HeliusNode, MathNode, etc.) provides the abstraction layer over the low-level blockchain operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    U("User"):::user

    %% UI Layer: Frontend (Next.js & React)
    subgraph "User Interface: Frontend (Next.js & React)"
        U1["Application Pages & API Routes"]:::frontend
        U2["Component Modules"]:::frontend
        U3["Providers and Contexts"]:::frontend
        U4["Libs (Supabase, etc.)"]:::frontend
    end

    %% Application Logic: Backend (Block-Functions & Compiler)
    subgraph "Application Logic: Backend (Block-Functions & Compiler)"
        CM["Compiler Module"]:::backend
        BF["Block Functions"]:::backend
        subgraph "Block Functions Breakdown"
            BF1["Default"]:::backend
            BF2["Helius"]:::backend
            BF3["DeFi"]:::backend
            BF4["Misc"]:::backend
        end
        BF --> BF1
        BF --> BF2
        BF --> BF3
        BF --> BF4
    end

    %% Blockchain Integration & External Services
    subgraph "Blockchain & External Integration"
        E1["Smart Contracts (Rust)"]:::external
        E2["Helius API"]:::external
        E3["Supabase Service"]:::external
    end

    %% Connections - User interactions with Frontend
    U -->|"interacts"| U1
    U -->|"createsFlows"| U2

    %% Frontend interactions
    U2 -->|"sendsFlow"| CM
    U1 -->|"callsAPI"| BF

    U4 -->|"supports"| U3
    U3 -->|"managesAuth"| E3

    %% Backend interactions
    CM -->|"triggersExecution"| BF
    BF -->|"initiatesTxn"| E1
    BF2 -->|"calls"| E2

    %% Click Events for Frontend Components
    click U1 "https://github.com/nathanliow/opensol/tree/main/apps/frontend/src/app"
    click U2 "https://github.com/nathanliow/opensol/tree/main/apps/frontend/src/components"
    click U3 "https://github.com/nathanliow/opensol/tree/main/apps/frontend/src/app/providers"
    click U3 "https://github.com/nathanliow/opensol/tree/main/apps/frontend/src/contexts"
    click U4 "https://github.com/nathanliow/opensol/tree/main/apps/frontend/src/lib"

    %% Click Events for Backend Components
    click CM "https://github.com/nathanliow/opensol/tree/main/apps/backend/src/packages/compiler"
    click BF "https://github.com/nathanliow/opensol/tree/main/apps/backend/src/block-functions"
    click BF1 "https://github.com/nathanliow/opensol/tree/main/apps/backend/src/block-functions/default"
    click BF2 "https://github.com/nathanliow/opensol/tree/main/apps/backend/src/block-functions/default/helius"
    click BF3 "https://github.com/nathanliow/opensol/tree/main/apps/backend/src/block-functions/defi"
    click BF4 "https://github.com/nathanliow/opensol/tree/main/apps/backend/src/block-functions/misc"

    %% Click Events for Blockchain Contracts
    click E1 "https://github.com/nathanliow/opensol/blob/main/apps/contracts/src/fee_manager.rs"

    %% Click Event for Supabase Service
    click E3 "https://github.com/nathanliow/opensol/blob/main/apps/frontend/src/lib/supabase.ts"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef user fill:#D5F5E3,stroke:#117864,stroke-width:2px;
```
