# axyl1410/edunft-network architecture

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

- Interactive diagram: https://gitdiagram.com/axyl1410/edunft-network
- Repository: https://github.com/axyl1410/edunft-network

## Overview

##### Project Type and Purpose
- This is a full-stack, monorepo application for a blockchain-based education certification platform (EduNFT Network).
- It follows a microservices-style architecture within a single repo, with separate Next.js frontends for student, school, enterprise, and homepage, a NestJS REST+WebSocket API, a Hardhat smart-contract service, and shared component/config packages.

##### File Structure and Map to Logical Components
- apps/api → NestJS backend service
- Controllers (REST endpoints)
- Services (business logic, MongoDB via Mongoose, JWT auth, Socket.io gateways)
- Blockchain module (wraps ThirdWeb SDK or raw RPC calls)
- apps/student, apps/school, apps/enterprise, apps/homepage → Four Next.js frontends
- Each runs on its own port
- Uses shared UI components (packages/ui) and shared hooks/utilities
- Interacts with the backend via REST and WebSocket, and directly with Web3 (ThirdWeb SDK)
- apps/hardhat → Smart-contract compilation, testing, deployment to FORMASKETCHPAD
- packages/ui, packages/eslint-config, packages/typescript-config → Shared libraries and configs

##### README Insights
- Microservices architecture: distinct UI apps, a monolithic API, and a blockchain service
- Key technologies: Next.js, NestJS, MongoDB, Solidity (Hardhat), ThirdWeb, Socket.io
- System Architecture section already calls out: Frontends ↔ API ↔ Database & Blockchain

##### Main Components
- Student Portal (Next.js)
- School Portal (Next.js)
- Enterprise Portal (Next.js)
- Marketing/Landing Page (Next.js)
- NestJS REST controllers
- WebSocket Gateways (Socket.io)
- Authentication/Authorization module (JWT, role-based guards)
- Blockchain integration module (ThirdWeb SDK wrapper)
c. Data Layer:
- MongoDB (hosted instance)
- Mongoose ODM
d. Blockchain Layer:
- FORMA_SKETCHPAD network
- Smart Contracts (ERC-721 QuestionReward, certificate NFTs) deployed via Hardhat
e. Shared Packages:
- UI component library (packages/ui)
- ESLint & TypeScript config libraries

##### Relationships and Data Flows
- Browsers → Frontends: User interacts, submits forms, triggers wallet connections
- Frontends → API REST endpoints: HTTP POST/GET for user data, files, questions, events, collections
- Frontends ↔ API via WebSocket: Real-time updates (notifications, chat messages, event registration)
- Frontends → Blockchain: ThirdWeb client calls for minting, buying, selling NFTs
- API → Database: Read/write user profiles, metadata, events, question/Q&A histories
- API → Blockchain: Reads on-chain state, writes transactions via ThirdWeb or native RPC
- Hardhat scripts → Blockchain: Contract deployment, testing, migration

##### Architectural Patterns and Principles
- Separation of Concerns: Each portal is its own Next.js app; backend modules organize by feature
- Modularization: Shared packages for UI and config, promoting DRY across apps
- Layered Architecture: Presentation (Next.js) → API (NestJS controllers/services) → Persistence/Contract
- Event-Driven/Real-Time: Socket.io gateways for push updates
- Micro-Frontends within Monorepo: Logical isolation, independent deployment ports

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Student["Student Portal (Next.js)\nPort:3001"]:::frontend
        School["School Portal (Next.js)\nPort:3002"]:::frontend
        Enterprise["Enterprise Portal (Next.js)\nPort:3003"]:::frontend
        Homepage["Marketing/Landing Page (Next.js)\nPort:3000"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        API["NestJS API\n- REST Controllers\n- Services\n- Socket.io Gateways\n- Auth Module\n- Blockchain Module"]:::api
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB\n(via Mongoose)"]:::db
    end

    %% Blockchain Layer
    subgraph "Blockchain Network"
        direction TB
        SC["Smart Contracts\n(ERC-721)"]:::blockchain
    end

    %% DevOps Layer
    subgraph "DevOps"
        direction TB
        Hardhat["Hardhat Service"]:::devops
    end

    %% Shared Libraries
    subgraph "Shared Packages"
        direction TB
        UI["UI Component Library"]:::libs
        ESLint["ESLint Config"]:::libs
        TSConfig["TypeScript Config"]:::libs
    end

    %% Connections
    Student -->|HTTP/REST| API
    School -->|HTTP/REST| API
    Enterprise -->|HTTP/REST| API
    Homepage -->|HTTP/REST| API

    Student <-->|WebSocket| API
    School <-->|WebSocket| API
    Enterprise <-->|WebSocket| API
    Homepage <-->|WebSocket| API

    Student -->|ThirdWeb SDK| SC
    School -->|ThirdWeb SDK| SC
    Enterprise -->|ThirdWeb SDK| SC
    Homepage -->|ThirdWeb SDK| SC

    API -->|Mongoose| MongoDB
    API -->|ThirdWeb/RPC| SC

    Hardhat -->|Deploy & Test| SC

    UI --> Student
    UI --> School
    UI --> Enterprise
    UI --> Homepage

    ESLint --> Student
    ESLint --> School
    ESLint --> Enterprise
    ESLint --> Homepage

    TSConfig --> Student
    TSConfig --> School
    TSConfig --> Enterprise
    TSConfig --> Homepage

    %% Click Events
    click Student "https://github.com/axyl1410/edunft-network/tree/main/apps/student"
    click School "https://github.com/axyl1410/edunft-network/tree/main/apps/school"
    click Enterprise "https://github.com/axyl1410/edunft-network/tree/main/apps/enterprise"
    click Homepage "https://github.com/axyl1410/edunft-network/tree/main/apps/homepage"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api"
    click UI "https://github.com/axyl1410/edunft-network/tree/main/packages/ui"
    click ESLint "https://github.com/axyl1410/edunft-network/tree/main/packages/eslint-config"
    click TSConfig "https://github.com/axyl1410/edunft-network/tree/main/packages/typescript-config"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api/src/controller"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api/src/service"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api/src/gateway"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api/src/auth"
    click API "https://github.com/axyl1410/edunft-network/blob/main/apps/api/src/module/auth.module.ts"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api/src/blockchain"
    click API "https://github.com/axyl1410/edunft-network/tree/main/apps/api/src/schema"
    click Hardhat "https://github.com/axyl1410/edunft-network/tree/main/apps/hardhat"
    click Hardhat "https://github.com/axyl1410/edunft-network/tree/main/apps/hardhat/contracts"
    click Hardhat "https://github.com/axyl1410/edunft-network/blob/main/apps/hardhat/scripts/deploy.ts"
    click Hardhat "https://github.com/axyl1410/edunft-network/tree/main/apps/hardhat/test"
    click Hardhat "https://github.com/axyl1410/edunft-network/blob/main/apps/hardhat/hardhat.config.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef api fill:#40E0D0,stroke:#000,stroke-width:1px
    classDef db fill:#90EE90,stroke:#000,stroke-width:1px
    classDef blockchain fill:#D8BFD8,stroke:#000,stroke-width:1px
    classDef devops fill:#FFE4B5,stroke:#000,stroke-width:1px
    classDef libs fill:#D3D3D3,stroke:#000,stroke-width:1px
```
