# parth-420/goalchain architecture

> Architecture diagram of the GitHub repository parth-420/goalchain, 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/parth-420/goalchain
- Repository: https://github.com/parth-420/goalchain

## Overview

##### Main Components
- Smart Contract Module:
- Located in the "contract" directory.
- Implemented using Anchor and Rust.
- Contains programs (e.g., the “stake” program) and tests (TypeScript-based tests).
- Key functions: stake_task and complete_task.
- Blockchain Network:
- Represents the Solana blockchain (Devnet/Mainnet) where the smart contract is deployed.
- Relationship to the smart contract by showing deployment tools (Anchor CLI, Solana CLI).
- Frontend Application:
- Found within the "ui" directory.
- Built using Next.js, leveraging the App Router, custom components, hooks, and a TailwindCSS configuration.
- Contains the UI elements (pages, layouts, components, and utility libraries) that interact with the blockchain.
- Integration/API Layer:
- Although still under process, there’s an intended integration where Next.js API routes will interact directly with the smart contract.
- This layer is crucial for triggering smart contract instructions (like stake_task and complete_task) from the frontend.

##### Relationships and Data Flow
- User Interaction:
- The end user interacts with the Next.js frontend UI (web browser).
- The UI captures user actions such as creating or completing a goal.
- API or Direct Wallet Integration:
- (When completed) the frontend will communicate with an API layer or directly use wallet interactions to sign transactions.
- This communication flows to trigger the smart contract functions.
- Blockchain Communication:
- Transactions are sent to the Solana network where the smart contract processes them.
- The response (e.g., funds returned on successful completion) is propagated back through the API layer to update the UI.

##### Important Architectural Patterns
- Separation of Concerns:
- Distinguish between the smart contract (backend on blockchain) and the UI (frontend web application).
- Decentralized Architecture:
- That part of the logic (goal staking and verification) resides on the blockchain, ensuring trustless operations.
- Future API Integration:
- Clearly denote that an API layer will mediate some interactions between the UI and the blockchain, an important design consideration for maintaining clear boundaries.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        U("User"):::user
        FE("Next.js Frontend (TailwindCSS)"):::frontend
        FEComponents("Next.js Pages/Components"):::frontend
        U -->|"interacts"| FE
        FE -->|"renders|captures actions"| FEComponents
    end

    subgraph "API Integration Layer"
        API("API Integration (Planned)"):::api
    end

    subgraph "Smart Contract Layer"
        SC("Smart Contract (Anchor/Rust)"):::backend
        Stake("Stake Program"):::backend
        Tests("TypeScript Tests"):::backend
        Deploy("Deployment Tools (Anchor CLI,Solana CLI)"):::backend
        SC -->|"contains"| Stake
        SC -->|"tested by"| Tests
        SC -->|"deployed via"| Deploy
    end

    subgraph "Blockchain Network"
        BC("Solana Blockchain (Devnet/Mainnet)"):::blockchain
    end

    FE -->|"calls API"| API
    API -->|"triggers stake_task/complete_task"| SC
    SC -->|"executes transactions"| BC
    BC -->|"responds with tx data"| API
    API -->|"updates UI"| FE

    %% Click Events
    click SC "https://github.com/parth-420/goalchain/tree/main/contract"
    click Stake "https://github.com/parth-420/goalchain/tree/main/contract/programs/stake"
    click Tests "https://github.com/parth-420/goalchain/tree/main/contract/tests"
    click Deploy "https://github.com/parth-420/goalchain/blob/main/contract/Anchor.toml"
    click FE "https://github.com/parth-420/goalchain/tree/main/ui/app"
    click API "https://github.com/parth-420/goalchain/blob/main/ui/lib/api-service.ts"

    %% Styles
    classDef user fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef api fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef backend fill:#577590,stroke:#333,stroke-width:2px;
    classDef blockchain fill:#277da1,stroke:#333,stroke-width:2px;
```
