# guboc11/blockhero architecture

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

- Interactive diagram: https://gitdiagram.com/guboc11/blockhero
- Repository: https://github.com/guboc11/blockhero

## Overview

##### Project type and purpose
- This is a decentralized application (dApp) built on the Internet Computer (IC).
- It comprises a Rust‐based canister backend (`BlockHero_backend`) and a React‐based frontend (`BlockHero_frontend`), all managed under DFINITY’s `dfx` toolchain.
- The user interface communicates with on‐chain Canisters (WASM modules) via the IC HTTP API and Candid interfaces.

##### File structure
- Top‐level:
- `dfx.json` – defines canisters and network settings.
- `Cargo.toml`, `Cargo.lock` – orchestrate Rust project dependencies.
- `package.json`, `package-lock.json` – root Node scripts (often proxying calls to `dfx`).
- `src/BlockHero_backend`
- Rust code (`lib.rs`, `types.rs`) and its `Cargo.toml` – your on‐chain business logic.
- `BlockHero_backend.did` – the autogenerated Candid interface.
- `src/BlockHero_frontend`
- A Vite‐powered React application (`main.jsx`, `App.jsx`, etc.) – your dApp’s UI.
- `api.js` – where `createActor` constructs canister actors using Candid.
- Tailwind and SCSS configs – styling and build pipelines.
- `Frontend/frontend`
- A second React app (Create React App) – likely an earlier or alternate UI template.
- Config files (`tsconfig.json`, `tailwind.config.js`, `vite.config.js`) – build and transpilation rules.

##### README for additional insights
- dfx commands to start a local replica, deploy canisters, generate Candid interfaces, and run the frontend dev server.
- Advice on environment variables to switch networks (local vs `ic`).

##### Elements
- Clear labels for:
- Developer Workstation (tools)
- Local Replica (dfx)
- Canister Backend (Rust/WASM + Candid)
- Asset Canister (static files)
- Frontend App (React)
- Browser / End User
- Internet Computer (prod)
- dfx deploy → canister uploads
- Browser → asset canister (UI fetch)
- UI → backend canister (API calls)
- Backend canister ↔ state storage on IC
- Tools & Dev (grey/infrastructure)
- Frontend components (green)
- Backend canisters (blue)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer and Tools
    Dev["Developer Workstation"]:::infra
    Tools["DFX CLI, Rust Toolchain, Node.js/NPM"]:::infra
    Dev --> Tools

    %% DFX Commands
    Tools --> DFXStart["Run dfx start --background"]:::infra
    Tools --> DFXDeploy["Run dfx deploy"]:::infra

    %% Local Development Environment
    subgraph "Local Development Environment"
        Replica["Local Replica (dfx)"]:::infra
        CandidGen["Candid Interface Generator"]:::infra
    end
    DFXStart --> Replica
    DFXDeploy --> Replica

    %% Build and Deploy Sequence
    DFXDeploy --> CompileRust["Compile Rust to WASM"]:::backend
    CompileRust --> GenerateCandid["Generate Candid (.did)"]:::backend
    GenerateCandid --> Upload["Deploy Backend & Asset Canisters"]:::backend
    GenerateCandid --> CandidGen

    %% Canisters on Replica
    subgraph "Canisters on Replica"
        BackendCanister["BlockHero_backend Canister"]:::backend
        AssetCanister["Asset Canister (static files)"]:::frontend
    end
    Upload --> BackendCanister
    Upload --> AssetCanister

    %% Frontend Build
    DFXDeploy --> FrontendBuild["Build Frontend (Vite)"]:::frontend
    FrontendBuild --> AssetCanister

    %% Browser and User Interaction
    AssetCanister -->|serves UI| Browser["Browser / End User"]:::external
    Browser -->|fetch UI| AssetCanister
    Browser -->|calls Actor| APIcalls["createActor → HTTP API"]:::frontend
    APIcalls --> Replica
    Replica --> BackendCanister
    BackendCanister -->|state| Replica

    %% Production on Internet Computer
    subgraph "Internet Computer (Prod)"
        ICBackend["Canisters in Prod"]:::backend
    end
    BackendCanister -->|migrate to prod| ICBackend
    AssetCanister -->|host static assets| ICBackend

    %% Legacy Frontend Path
    Dev --> Legacy["Legacy UI Path"]:::frontend
    subgraph "Legacy CRA Frontend"
        LegacyDir["Frontend/frontend"]:::frontend
        LegacyPkg["package.json"]:::frontend
        LegacyHTML["public/index.html"]:::frontend
    end
    Legacy --> LegacyDir
    LegacyDir --> LegacyPkg
    LegacyDir --> LegacyHTML

    %% File Structure for Click Events
    subgraph "Project File Structure"
        DFXCfg["dfx.json"]:::infra
        RootCargo["Cargo.toml"]:::infra
        RootPkg["package.json"]:::infra

        BackendFS["src/BlockHero_backend"]:::backend
        BkCargo["Cargo.toml"]:::backend
        LibRs["lib.rs"]:::backend
        TypesRs["types.rs"]:::backend
        CandidIDL["BlockHero_backend.did"]:::backend

        FrontFS["src/BlockHero_frontend"]:::frontend
        FEpkg["package.json"]:::frontend
        IndexHTML["index.html"]:::frontend
        ICAssets[".ic-assets.json5"]:::frontend
        APIJS["api.js"]:::frontend
        FEtw["tailwind.config.js"]:::frontend
        FEvite["vite.config.js"]:::frontend
        FETs["tsconfig.json"]:::frontend
        ViteEnv["vite-env.d.ts"]:::frontend
    end

    %% Click Events
    click DFXCfg "https://github.com/guboc11/blockhero/blob/main/dfx.json"
    click RootCargo "https://github.com/guboc11/blockhero/blob/main/Cargo.toml"
    click RootPkg "https://github.com/guboc11/blockhero/blob/main/package.json"

    click BackendFS "https://github.com/guboc11/blockhero/tree/main/src/BlockHero_backend"
    click BkCargo "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_backend/Cargo.toml"
    click LibRs "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_backend/src/lib.rs"
    click TypesRs "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_backend/src/types.rs"
    click CandidIDL "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_backend/BlockHero_backend.did"

    click FrontFS "https://github.com/guboc11/blockhero/tree/main/src/BlockHero_frontend"
    click FEpkg "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/package.json"
    click IndexHTML "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/index.html"
    click ICAssets "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/public/.ic-assets.json5"
    click APIJS "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/src/api.js"
    click FEtw "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/tailwind.config.js"
    click FEvite "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/vite.config.js"
    click FETs "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/tsconfig.json"
    click ViteEnv "https://github.com/guboc11/blockhero/blob/main/src/BlockHero_frontend/src/vite-env.d.ts"

    click LegacyDir "https://github.com/guboc11/blockhero/tree/main/Frontend/frontend"
    click LegacyPkg "https://github.com/guboc11/blockhero/blob/main/Frontend/frontend/package.json"
    click LegacyHTML "https://github.com/guboc11/blockhero/blob/main/Frontend/frontend/public/index.html"

    %% Styles
    classDef infra fill:#f2f2f2,stroke:#ccc;
    classDef frontend fill:#d4edda,stroke:#28a745;
    classDef backend fill:#cce5ff,stroke:#004085;
    classDef external fill:#d1ecf1,stroke:#0c5460;
```
