# scio-labs/inkathon architecture

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

- Interactive diagram: https://gitdiagram.com/scio-labs/inkathon
- Repository: https://github.com/scio-labs/inkathon

## Overview

##### Main Components
- Smart Contracts & Blockchain Interaction:
- The “contracts” directory houses the Rust/ink! smart contracts.
- Deployment scripts, Cargo.toml files, and deployment artifacts (like WASM binaries, JSON metadata, and deployment scripts) orchestrate contract compilation, type-generation (via typechain-polkadot), and deployment to a Substrate-based chain.
- Local deployment is facilitated by scripts that build and deploy these contracts onto a Substrate Contracts Node.
- Frontend Application:
- The “frontend” directory contains a Next.js application that serves as the user interface.
- It includes UI components (both generic and web3-specific) for connecting wallets, displaying chain info, and interacting with the smart contract.
- Configuration files (environment variables in .env, tailwind config, etc.) and components indicate that the UI is built with React, TypeScript, and tailwindcss while using shadcn/ui components.
- Infrastructure & Deployment:
- Dockerfiles (for both contracts and frontend) and docker-compose files are provided for containerized deployments.
- There's a monorepo structure managed by pnpm workspaces (with separate package.json files in the root, contracts, and frontend) which adds an extra layer of dependency management and build orchestration.
- Development & Tooling:

##### Relationships and Interactions
- The smart contract lifecycle starts with development in the “contracts” directory, goes through build scripts (pnpm run build) to generate artifacts, and is then deployed (via pnpm run deploy) onto the blockchain node.
- Environment configuration plays a vital role: for example, the frontend reads environment variables (configured in the .env file) to decide which deployed contract addresses to interact with.
- Docker components should be included to illustrate the containerized deployment of both frontend and contracts node.

##### Architectural Patterns and Design Principles
- Monorepo Architecture: Clearly separate the system into “contracts” and “frontend” packages with their own dependency trees.
- Separation of Concerns: Show how the blockchain backend (smart contracts) is decoupled from the UI logic and is interacted with through well-defined APIs (contract interactions via hooks).
- Type-Safe Contract Generation: Emphasize the use of tools like typechain-polkadot to bridge Rust and TypeScript, ensuring type safety between contract artifacts and the frontend.

##### Relevant Technologies
- Backend/Contracts: Rust, ink!, cargo-contract, Substrate Contracts Node.
- Frontend: Next.js (app directory), React, TypeScript, Tailwind CSS, shadcn/ui, ESLint & Prettier.
- Infrastructure: Docker, Docker Compose, pnpm workspaces, and CI/CD workflows (GitHub Actions workflows).
- Web3 Integration: polkadot-js, useInkathon, and typechain-polkadot.

##### Final Touches
- Keep the user (or client) interactions in mind, displaying how the user inputs result in contract calls.
- Optionally, include additional development environment elements (like the VSCode workspace) to highlight how developers interact with the project during development.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Smart Contracts & Blockchain Interaction
    subgraph "Smart Contracts & Blockchain Interaction"
        direction TB
        SC1("Contracts Directory"):::service
        SC2("Smart Contracts (Rust/ink!)"):::service
        SC4("Build & Deploy Scripts"):::tool
        SC3("Deployment Artifacts (WASM, JSON)"):::service
        SC1 --> SC2
        SC2 --> SC3
        SC4 --> SC3

        subgraph "Contracts Files"
            direction TB
            C1("Cargo.toml"):::file
            C2("lib.rs (Greeter Contract)"):::file
            C3("greeter.contract"):::file
            C4("greeter.json"):::file
            C5("greeter.wasm"):::file
            C6("deploy.ts (Deployment Script)"):::file
        end
        SC1 --- C1
        SC1 --- C2
        C2 --- C3
        C3 --- C4
        C4 --- C5
        SC1 --- C6
    end

    %% Blockchain Node
    subgraph "Blockchain Node"
        BN("Substrate Contracts Node"):::blockchain
    end

    %% Frontend Application
    subgraph "Frontend Application"
        direction TB
        FE1("Next.js App (React & TypeScript)"):::service
        FE2("UI Components & Web3 Integration"):::service
        FE3("Environment Configurations (.env, tailwind)"):::config
        FE1 --> FE2
        FE3 --> FE1
        subgraph "Frontend Files"
            direction TB
            FEF1("package.json"):::file
            FEF2("next.config.js"):::file
            FEF3("greeter-contract-interactions.tsx"):::file
        end
        FE1 --- FEF1
        FE1 --- FEF2
        FE2 --- FEF3
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        direction TB
        ID1("Docker Containers"):::docker
        ID2("pnpm Workspaces & CI/CD Pipelines"):::tool
        subgraph "Deployment Files"
            direction TB
            INF1("Dockerfile.contracts"):::file
            INF2("Dockerfile.frontend"):::file
            INF3("docker-compose.contracts.yaml"):::file
            INF4("docker-compose.frontend.yaml"):::file
            INF5("vercel.json"):::file
            INF6("pnpm-workspace.yaml"):::file
        end
        ID1 --- INF1
        ID1 --- INF2
        ID1 --- INF3
        ID1 --- INF4
        ID1 --- INF5
        ID2 --- INF6
    end

    %% Development & Tooling
    subgraph "Development & Tooling"
        direction TB
        DT1("VSCode Workspace"):::dev
        DT2("Pre-commit Hooks & Testing Scripts"):::dev
        subgraph "Development Files"
            direction TB
            DTFile1(".github/workflows"):::file
            DTFile2(".simple-git-hooks.js"):::file
            DTFile3(".vscode/"):::file
            DTFile4("inkathon.code-workspace"):::file
        end
        DT1 --- DTFile1
        DT2 --- DTFile2
        DT1 --- DTFile3
        DT1 --- DTFile4
    end

    %% Inter-component Relationships
    FE2 -->|"web3calls"| BN
    SC3 -->|"deployed_to"| BN
    ID2 --- SC4
    ID2 --- FE1
    ID1 --> SC3
    ID1 --> FE1
    User("User"):::user
    User --> FE2

    %% Class Definitions for Colors
    classDef service fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef file fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef tool fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#9d4edd,stroke:#333,stroke-width:2px;
    classDef config fill:#43aa8b,stroke:#333,stroke-width:2px;
    classDef docker fill:#ff595e,stroke:#333,stroke-width:2px;
    classDef dev fill:#8ac926,stroke:#333,stroke-width:2px;
    classDef user fill:#4d908e,stroke:#333,stroke-width:2px;

    %% Click Events for Smart Contracts Components
    click SC1 "https://github.com/scio-labs/inkathon/tree/main/contracts/"
    click C1 "https://github.com/scio-labs/inkathon/blob/main/contracts/Cargo.toml"
    click C2 "https://github.com/scio-labs/inkathon/blob/main/contracts/src/greeter/lib.rs"
    click C3 "https://github.com/scio-labs/inkathon/blob/main/contracts/deployments/greeter/greeter.contract"
    click C4 "https://github.com/scio-labs/inkathon/blob/main/contracts/deployments/greeter/greeter.json"
    click C5 "https://github.com/scio-labs/inkathon/blob/main/contracts/deployments/greeter/greeter.wasm"
    click C6 "https://github.com/scio-labs/inkathon/blob/main/contracts/scripts/deploy.ts"

    %% Click Events for Frontend Components
    click FE1 "https://github.com/scio-labs/inkathon/tree/main/frontend/"
    click FEF1 "https://github.com/scio-labs/inkathon/blob/main/frontend/package.json"
    click FEF2 "https://github.com/scio-labs/inkathon/blob/main/frontend/next.config.js"
    click FEF3 "https://github.com/scio-labs/inkathon/blob/main/frontend/src/components/web3/greeter-contract-interactions.tsx"

    %% Click Events for Infrastructure Components
    click INF1 "https://github.com/scio-labs/inkathon/blob/main/Dockerfile.contracts"
    click INF2 "https://github.com/scio-labs/inkathon/blob/main/Dockerfile.frontend"
    click INF3 "https://github.com/scio-labs/inkathon/blob/main/docker-compose.contracts.yaml"
    click INF4 "https://github.com/scio-labs/inkathon/blob/main/docker-compose.frontend.yaml"
    click INF5 "https://github.com/scio-labs/inkathon/blob/main/vercel.json"
    click INF6 "https://github.com/scio-labs/inkathon/blob/main/pnpm-workspace.yaml"

    %% Click Events for Development Components
    click DTFile1 "https://github.com/scio-labs/inkathon/tree/main/.github/workflows"
    click DTFile2 "https://github.com/scio-labs/inkathon/blob/main/.simple-git-hooks.js"
    click DTFile3 "https://github.com/scio-labs/inkathon/tree/main/.vscode/"
    click DTFile4 "https://github.com/scio-labs/inkathon/blob/main/inkathon.code-workspace"
```
