# ptanh05/nckh_2024 architecture

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

- Interactive diagram: https://gitdiagram.com/ptanh05/nckh_2024
- Repository: https://github.com/ptanh05/nckh_2024

## Overview

##### Project type and purpose
- This is a full-stack, blockchain-enabled web application (a Cardano dApp).
- Frontend: Next.js (App Router, React) with TypeScript/JSX pages under `app/`.
- Backend/API: Next.js serverless routes under `app/api/` that wrap database operations and business logic.
- Service layer: On-chain logic (CIP-68 NFT operations and vesting contracts) under `service/`.
- Database: SQLite or Postgres (inferred from `app/api/sql/db.js`, `schema.js`).
- Blockchain network: Cardano, via `app/cardano/WalletContext.tsx` and adapter files in `service/nftcip68` & `service/vesting`.

##### File structure
Top-level directories:
- app/ – frontend pages, UI flows (mint, burn, lock, unlock, update NFT), plus serverless API routes under app/api.
- service/ – pure business-logic modules for NFT CIP-68 and vesting on Cardano, including Plutus artifacts.
- components/ & components/ui/ – shared React UI primitives and layout components (navbar, footer, theme provider).
- hooks/ – custom React hooks for mobile detection and toast notifications.
- lib/ – shared utilities.
- public/ & styles/ – static assets and global CSS.
- config files (next.config.mjs, tailwind.config.ts).
- db.mjs & schema.mjs – top-level database definitions.

##### README
- Minimal content, so our understanding is driven by the code layout and naming conventions.

– Blue for frontend components,
– Green for backend/API,
– Orange for blockchain interactions,
– Grey for DB.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        WalletCtx["WalletContext"]:::frontend
        UIComponents["Shared UI Components"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        subgraph "Pages"
            Mint["Mint NFT (page.tsx)"]:::frontend
            Burn["Burn NFT (page.tsx)"]:::frontend
            Lock["Lock Assets (page.tsx)"]:::frontend
            Unlock["Unlock Assets (page.tsx)"]:::frontend
            Update["Update NFT (page.tsx)"]:::frontend
            Home["Home Page (page.tsx)"]:::frontend
        end
    end

    %% API Layer
    subgraph "API Layer"
        SQLRoutes["SQL Routes"]:::api
        TransactionsAPI["Transactions Endpoints"]:::api
        UserAPI["User Endpoints"]:::api
        TransactionService["Transaction Service"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        subgraph "NFT CIP-68 Logic"
            Adapter["Adapter (adapter.ts)"]:::service
            MintSvc["Mint Module (mint.ts)"]:::service
            BurnSvc["Burn Module (burn.ts)"]:::service
            UpdateSvc["Update Module (update.ts)"]:::service
            Interface["Interface (interface.ts)"]:::service
            PlutusNFT["Plutus JSON (plutus.json)"]:::service
        end
        subgraph "Vesting Logic"
            LockSvc["Lock Module (lock.ts)"]:::service
            UnlockSvc["Unlock Module (unlock.ts)"]:::service
            CommonSvc["Common Module (common.ts)"]:::service
            PlutusVest["Plutus JSON (plutus.json)"]:::service
        end
    end

    %% Data & External Systems
    DB["Database (SQLite/Postgres)"]:::db
    Blockchain["Cardano Network"]:::blockchain

    %% Connections: Frontend to API
    WalletCtx -->|uses| Mint
    WalletCtx -->|uses| Burn
    WalletCtx -->|uses| Lock
    WalletCtx -->|uses| Unlock
    WalletCtx -->|uses| Update
    UIComponents -->|renders| Mint
    UIComponents -->|renders| Burn
    UIComponents -->|renders| Lock
    UIComponents -->|renders| Unlock
    UIComponents -->|renders| Update
    Hooks -->|enhances| Mint
    Hooks -->|enhances| Burn
    Hooks -->|enhances| Lock
    Hooks -->|enhances| Unlock
    Hooks -->|enhances| Update

    Mint -->|calls| TransactionsAPI
    Burn -->|calls| TransactionsAPI
    Lock -->|calls| TransactionsAPI
    Unlock -->|calls| TransactionsAPI
    Update -->|calls| TransactionsAPI
    Home -->|calls| UserAPI

    %% API to Service & DB
    TransactionsAPI -->|orchestrates| TransactionService
    UserAPI -->|orchestrates| TransactionService
    SQLRoutes -->|connects| DB
    TransactionService -->|reads/writes| DB
    TransactionService -->|delegates| Adapter
    TransactionService -->|delegates| LockSvc
    TransactionService -->|delegates| UnlockSvc

    %% Service to Blockchain
    Adapter -->|executes| MintSvc
    Adapter -->|executes| BurnSvc
    Adapter -->|executes| UpdateSvc
    MintSvc -->|submits tx| Blockchain
    BurnSvc -->|submits tx| Blockchain
    UpdateSvc -->|submits tx| Blockchain

    LockSvc -->|executes| CommonSvc
    UnlockSvc -->|executes| CommonSvc
    LockSvc -->|submits tx| Blockchain
    UnlockSvc -->|submits tx| Blockchain

    %% Click Events: Frontend Pages
    click Mint "https://github.com/ptanh05/nckh_2024/blob/main/app/mint-nft/page.tsx"
    click Burn "https://github.com/ptanh05/nckh_2024/blob/main/app/burn-nft/page.tsx"
    click Lock "https://github.com/ptanh05/nckh_2024/blob/main/app/lock-assets/page.tsx"
    click Unlock "https://github.com/ptanh05/nckh_2024/blob/main/app/unlock/page.tsx"
    click Update "https://github.com/ptanh05/nckh_2024/blob/main/app/update-nft/page.tsx"
    click Home "https://github.com/ptanh05/nckh_2024/blob/main/app/page.tsx"

    %% Click Events: Wallet Context
    click WalletCtx "https://github.com/ptanh05/nckh_2024/blob/main/app/cardano/WalletContext.tsx"
    click WalletCtx "https://github.com/ptanh05/nckh_2024/blob/main/app/cardano/wallet.tsx"

    %% Click Events: UI Components
    click UIComponents "https://github.com/ptanh05/nckh_2024/blob/main/components/navbar.tsx"
    click UIComponents "https://github.com/ptanh05/nckh_2024/blob/main/components/footer.tsx"
    click UIComponents "https://github.com/ptanh05/nckh_2024/blob/main/components/theme-provider.tsx"
    click UIComponents "https://github.com/ptanh05/nckh_2024/tree/main/components/ui/"

    %% Click Events: Hooks
    click Hooks "https://github.com/ptanh05/nckh_2024/blob/main/hooks/use-mobile.tsx"
    click Hooks "https://github.com/ptanh05/nckh_2024/blob/main/hooks/use-toast.ts"

    %% Click Events: API Layer
    click SQLRoutes "https://github.com/ptanh05/nckh_2024/blob/main/app/api/sql/db.js"
    click SQLRoutes "https://github.com/ptanh05/nckh_2024/blob/main/app/api/sql/schema.js"
    click SQLRoutes "https://github.com/ptanh05/nckh_2024/blob/main/app/api/sql/test.js"
    click TransactionsAPI "https://github.com/ptanh05/nckh_2024/blob/main/app/api/transactions/route.js"
    click TransactionsAPI "https://github.com/ptanh05/nckh_2024/blob/main/app/api/transactions/[id]/route.js"
    click UserAPI "https://github.com/ptanh05/nckh_2024/blob/main/app/api/user/route.js"
    click TransactionService "https://github.com/ptanh05/nckh_2024/blob/main/app/services/transactionService.js"

    %% Click Events: Service Layer - NFT CIP-68
    click Adapter "https://github.com/ptanh05/nckh_2024/blob/main/service/nftcip68/adapter.ts"
    click MintSvc "https://github.com/ptanh05/nckh_2024/blob/main/service/nftcip68/mint.ts"
    click BurnSvc "https://github.com/ptanh05/nckh_2024/blob/main/service/nftcip68/burn.ts"
    click UpdateSvc "https://github.com/ptanh05/nckh_2024/blob/main/service/nftcip68/update.ts"
    click Interface "https://github.com/ptanh05/nckh_2024/blob/main/service/nftcip68/interface.ts"
    click PlutusNFT "https://github.com/ptanh05/nckh_2024/blob/main/service/nftcip68/plutus.json"

    %% Click Events: Service Layer - Vesting
    click LockSvc "https://github.com/ptanh05/nckh_2024/blob/main/service/vesting/lock.ts"
    click UnlockSvc "https://github.com/ptanh05/nckh_2024/blob/main/service/vesting/unlock.ts"
    click CommonSvc "https://github.com/ptanh05/nckh_2024/blob/main/service/vesting/common.ts"
    click PlutusVest "https://github.com/ptanh05/nckh_2024/blob/main/service/vesting/plutus.json"

    %% Click Events: Database Definitions
    click DB "https://github.com/ptanh05/nckh_2024/blob/main/db.mjs"
    click DB "https://github.com/ptanh05/nckh_2024/blob/main/schema.mjs"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#5499C7,color:#1B4F72
    classDef api fill:#ABEBC6,stroke:#28B463,color:#145A32
    classDef service fill:#F5B041,stroke:#D68910,color:#7E5109
    classDef db fill:#D5DBDB,stroke:#85929E,color:#1B2631
    classDef blockchain fill:#FAD7A0,stroke:#DC7633,color:#7D6608
```
