# tranvugiang/cryptoplant architecture

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

- Interactive diagram: https://gitdiagram.com/tranvugiang/cryptoplant
- Repository: https://github.com/tranvugiang/cryptoplant

## Overview

##### Project Type and Purpose
- This is a blockchain dApp built on Solana:
– On-chain program (“cryptoplant”) written in Rust, managed by Anchor
– Frontend web application using Next.js (app router) + React + Tailwind
– A small standalone Node.js “server” for custom API endpoints
– TypeScript/IDL layers to bridge frontend ↔ on-chain interactions

##### File Structure
Top-level directories:
- anchor/ → Anchor workspace for the Solana program, migrations, IDL, tests
- server/ → Node.js application (app.ts, its own package.json)
- src/ → Next.js 13 “app” directory with pages, API routes, and components
- public/ → static assets
Config files: Anchor.toml, next.config.mjs, tsconfig.json, tailwind.config.ts
Indicators of patterns:
- anchor/programs: on-chain MVC style (program logic in lib.rs)
- src/app and src/components: React feature-driven modules
- API layer both in Next.js (app/api) and a separate server folder

##### README (assumed empty)
- No explicit architecture section, so rely on conventions:
– Anchor IDL under anchor/target/idl
– TypeScript exports in anchor/src/cryptoplant-exports.ts → frontend & server use

##### Main Components & Relationships
a. On-Chain Program (Anchor)
– Component: Rust program “cryptoplant”
– Interfaces: Anchor’s IDL → TypeScript clients
– Deploy: migrations/deploy.ts

b. Frontend (Next.js + React)
– Pages under src/app (account/, cryptoplant/, clusters/, etc.)
– Uses SolanaProvider (src/components/solana) to connect wallet & RPC cluster
– React-Query provider for data fetching
– Component modules: account, cluster, cryptoplant, dashboard in src/components

c. Backend Server (Node.js)
– server/app.ts exposes custom endpoints (e.g., analytics, off-chain data)
– May consume Anchor IDL + cryptoplant-exports.ts to talk on-chain

d. External Services
– Solana RPC nodes / clusters
– Wallet adapters (in browser)

##### Architectural Patterns & Design Principles
- Separation of concerns:
– On-chain logic isolated in Anchor workspace
– Frontend UI & data layers in Next.js + React
– Off-chain APIs in Node.js server
- Feature-driven frontend modules (data-access, UI, feature container)
- IDL as contract between on-chain and TypeScript clients

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Client
    subgraph "Browser Client"
        direction TB
        UI["Next.js App Router"]:::frontend
        CSS["globals.css"]:::frontend
        ReactQuery["React-Query Provider"]:::frontend
        SolanaProv["SolanaProvider"]:::frontend
        subgraph "Pages"
            direction TB
            AccountPage["Account Page"]:::frontend
            AccountDetail["Account Detail Page"]:::frontend
            ClustersPage["Clusters Page"]:::frontend
            CryptoplantPage["Cryptoplant Page"]:::frontend
            APIHello["API Hello Route"]:::frontend
        end
    end

    %% Frontend Components
    subgraph "Frontend Feature Modules"
        direction TB
        subgraph "Account Feature"
            ADA["account-data-access"]:::feature
            ALF["account-list-feature"]:::feature
            ADF["account-detail-feature"]:::feature
            AUI["account-ui"]:::feature
        end
        subgraph "Cluster Feature"
            CDA["cluster-data-access"]:::feature
            CF["cluster-feature"]:::feature
            CUI["cluster-ui"]:::feature
        end
        subgraph "Cryptoplant Feature"
            CPDA["cryptoplant-data-access"]:::feature
            CPF["cryptoplant-feature"]:::feature
            CPU["cryptoplant-ui"]:::feature
        end
        Dashboard["dashboard-feature"]:::feature
        UILayout["ui-layout"]:::feature
    end

    %% Backend Server
    subgraph "Server (Node.js)"
        direction TB
        API["app.ts"]:::backend
    end

    %% Blockchain Network & On-Chain
    subgraph "Blockchain Network"
        direction TB
        RPC["Solana RPC Nodes"]:::external
        WAdapter["Wallet Adapters"]:::external
        subgraph "On-Chain Program (Anchor)"
            direction TB
            RustProg["cryptoplant Rust Program"]:::chain
            IDLJson["Anchor IDL (cryptoplant.json)"]:::chain
            TypesTS["Anchor Types (cryptoplant.ts)"]:::chain
            Deploy["Deploy Script"]:::chain
        end
    end

    %% Connections
    UI -->|uses| ReactQuery
    UI -->|includes| CSS
    ReactQuery -->|wraps| SolanaProv
    SolanaProv -->|connects to| RPC
    SolanaProv -->|uses| WAdapter

    AccountPage -->|renders| ADA
    AccountDetail -->|renders| ADF
    ClustersPage -->|renders| CF
    CryptoplantPage -->|renders| CPF
    APIHello -->|calls| API

    AccountPage -->|layout| UILayout
    AccountDetail -->|layout| UILayout
    ClustersPage -->|layout| UILayout
    CryptoplantPage -->|layout| UILayout

    ADA -->|fetches| RPC
    CDA -->|fetches| RPC
    CPDA -->|fetches| RPC

    API -->|uses IDL Client| TypesTS
    API -->|submits tx| RPC

    RustProg -->|deployed via| Deploy
    RustProg -->|IDL generated| IDLJson
    IDLJson -->|generates| TypesTS

    RPC -->|executes| RustProg
    RPC -->|returns state| ResState[(On-Chain Accounts)]:::external
    ResState -->|queried by| RPC

    %% Click events
    click RustProg "https://github.com/tranvugiang/cryptoplant/blob/main/anchor/programs/cryptoplant/src/lib.rs"
    click Deploy "https://github.com/tranvugiang/cryptoplant/blob/main/anchor/migrations/deploy.ts"
    click IDLJson "https://github.com/tranvugiang/cryptoplant/blob/main/anchor/target/idl/cryptoplant.json"
    click TypesTS "https://github.com/tranvugiang/cryptoplant/blob/main/anchor/target/types/cryptoplant.ts"
    click ADA "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/account/account-data-access.tsx"
    click ALF "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/account/account-list-feature.tsx"
    click ADF "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/account/account-detail-feature.tsx"
    click AUI "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/account/account-ui.tsx"
    click CDA "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/cluster/cluster-data-access.tsx"
    click CF "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/cluster/cluster-feature.tsx"
    click CUI "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/cluster/cluster-ui.tsx"
    click CPDA "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/cryptoplant/cryptoplant-data-access.tsx"
    click CPF "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/cryptoplant/cryptoplant-feature.tsx"
    click CPU "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/cryptoplant/cryptoplant-ui.tsx"
    click Dashboard "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/dashboard/dashboard-feature.tsx"
    click UILayout "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/ui/ui-layout.tsx"
    click API "https://github.com/tranvugiang/cryptoplant/blob/main/server/app.ts"
    click UI "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/layout.tsx"
    click CSS "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/globals.css"
    click AccountPage "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/account/page.tsx"
    click AccountDetail "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/account/[address]/page.tsx"
    click ClustersPage "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/clusters/page.tsx"
    click CryptoplantPage "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/cryptoplant/page.tsx"
    click APIHello "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/api/hello/route.ts"
    click ReactQuery "https://github.com/tranvugiang/cryptoplant/blob/main/src/app/react-query-provider.tsx"
    click SolanaProv "https://github.com/tranvugiang/cryptoplant/blob/main/src/components/solana/solana-provider.tsx"
    click Deploy "https://github.com/tranvugiang/cryptoplant/blob/main/anchor/programs/cryptoplant/Cargo.toml"
    click IDLJson "https://github.com/tranvugiang/cryptoplant/blob/main/anchor/src/cryptoplant-exports.ts"
    click API "https://github.com/tranvugiang/cryptoplant/blob/main/server/package.json"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef feature fill:#1E90FF,stroke:#333,stroke-width:1px
    classDef backend fill:#FFA500,stroke:#333,stroke-width:1px
    classDef chain fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
