# takokan/0xcampus architecture

> Architecture diagram of the GitHub repository takokan/0xcampus, 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/takokan/0xcampus
- Repository: https://github.com/takokan/0xcampus

## Overview

##### Main Components
- Frontend Application (Next.js):
- Pages & Routing: Represented by the “app” directory. Include sub-components for course-related pages (e.g., courses/[id], courses/page.tsx), creation (app/create/page.tsx), and dashboard (app/dashboard/page.tsx).
- Global Layout and Styling: Files like layout.tsx, globals.css, and app/page.tsx serve as the central entry points and template.
- UI Components: Located in the “components” directory and nested “components/ui”, these are reusable elements (buttons, cards, inputs, etc.) that build up the frontend.

- State and Context Management:
- Wallet Context: The “context/wallet-context.tsx” file suggests integration with a blockchain wallet, crucial for dApp functionality.
- Custom Hooks: In the “hooks” folder (e.g., use-toast.ts), provide additional client-side logic like notifications.

- Blockchain & External Service Integration:
- Blockchain Contract Integration: Code in “lib/contract.ts” and the ABI file (“lib/EducationalPlatformABI.json”) implies that the application interacts with blockchain smart contracts.
- Pinata Integration: “lib/pinata.ts” indicates an integration with the Pinata API, likely for IPFS content storage.
- Utility Functions: The “lib/utils.ts” file supports both UI and blockchain operations.

- Supporting Configuration:
- Build & Configuration Files: Next.js configuration (next.config.ts, tsconfig.json), Tailwind CSS configuration (tailwind.config.ts), PostCSS, ESLint, and package.json files define the project’s environment.
- Testing & Contract Development: The existence of a separate “contract” directory (with tests) shows the smart contracts under test conditions.

##### Relationships and Interactions
- The user interacts with the Frontend Application (built with Next.js) where the routing within the “app” directory determines the displayed page (e.g., courses, dashboard, create).
- UI Components render the visual elements and capture user input.
- Wallet and Application Context (via wallet-context.tsx) manage blockchain interactions, keeping track of user authentication and wallet connectivity.
- The “lib” functions encapsulate the logic to interact with smart contracts and external services (Pinata), which will be called from actions or component events.
- Custom hooks (like use-toast) provide user feedback during asynchronous operations (e.g., blockchain transactions).
- The smart contract code in the “contract” directory (and its tests) represents the on-chain logic that the frontend communicates with.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project is clearly separated into UI (pages and components), business logic (context and hooks), and external service integration (lib).
- Component Reusability: The “components/ui” folder modularizes the UI elements for consistency and easier maintenance.
- Integration with Decentralized Blockchain: Patterns for interacting with smart contracts and wallet connections are seen through context and dedicated library modules.
- Configuration Management: The use of centralized config files shows adherence to best practices for environment setup and styling.

##### Final Elements
- Clear labels for each component (e.g., “Courses Page”, “Dashboard”, “Wallet Context”, “Contract Library”, “Pinata Integration”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Define Classes
    classDef external fill:#f2f2f2,stroke:#999,stroke-width:2px;
    classDef frontend fill:#a3d2f2,stroke:#1b6ca8,stroke-width:2px;
    classDef ui fill:#adebad,stroke:#2d862d,stroke-width:2px;
    classDef state fill:#fceabb,stroke:#f8b500,stroke-width:2px;
    classDef blockchain fill:#ffc966,stroke:#ffa500,stroke-width:2px;
    classDef contract fill:#ff9999,stroke:#d63447,stroke-width:2px;

    %% Global Entity
    U("User"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        NEXT("Pages & Routing"):::frontend
        GLOBAL("Global Layout & Styling"):::frontend
        COURSES("Courses Page"):::frontend
        CREATE("Create Page"):::frontend
        DASHBOARD("Dashboard Page"):::frontend
    end

    %% UI Components
    subgraph "UI Components"
        UI("UI Components"):::ui
    end

    %% State Management
    subgraph "State Management"
        WALLET("Wallet Context"):::state
        HOOKS("Custom Hooks (use-toast)"):::state
    end

    %% Blockchain & External Integration
    subgraph "Blockchain & External Integration"
        CONTRACT_LIB("Contract Library"):::blockchain
        PINATA("Pinata Integration"):::blockchain
        UTILS("Utility Functions"):::blockchain
    end

    %% Smart Contract Layer
    subgraph "Smart Contract Layer"
        SMART("Smart Contracts & Tests"):::contract
    end

    %% Connections
    U -->|"interacts"| NEXT
    NEXT -->|"renders"| GLOBAL
    GLOBAL -->|"routes_to"| COURSES
    GLOBAL -->|"routes_to"| CREATE
    GLOBAL -->|"routes_to"| DASHBOARD
    NEXT -->|"includes"| UI
    UI -->|"leverages"| WALLET
    UI -->|"triggers"| HOOKS
    WALLET -->|"invokes"| CONTRACT_LIB
    HOOKS -->|"invokes"| CONTRACT_LIB
    CONTRACT_LIB -->|"calls"| PINATA
    CONTRACT_LIB -->|"utilizes"| UTILS
    CONTRACT_LIB -->|"interacts_with"| SMART
    PINATA -->|"supplies"| UTILS

    %% Click Events
    click NEXT "https://github.com/takokan/0xcampus/tree/main/0xcampus-app/app"
    click GLOBAL "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/app/layout.tsx"
    click GLOBAL "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/app/globals.css"
    click GLOBAL "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/app/page.tsx"
    click COURSES "https://github.com/takokan/0xcampus/tree/main/0xcampus-app/app/courses"
    click CREATE "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/app/create/page.tsx"
    click DASHBOARD "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/app/dashboard/page.tsx"
    click UI "https://github.com/takokan/0xcampus/tree/main/0xcampus-app/components"
    click UI "https://github.com/takokan/0xcampus/tree/main/0xcampus-app/components/ui"
    click WALLET "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/context/wallet-context.tsx"
    click HOOKS "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/hooks/use-toast.ts"
    click CONTRACT_LIB "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/lib/contract.ts"
    click CONTRACT_LIB "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/lib/EducationalPlatformABI.json"
    click PINATA "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/lib/pinata.ts"
    click UTILS "https://github.com/takokan/0xcampus/blob/main/0xcampus-app/lib/utils.ts"
    click SMART "https://github.com/takokan/0xcampus/tree/main/contract"
```
