# axyl1410/generative-hub-app architecture

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

- Interactive diagram: https://gitdiagram.com/axyl1410/generative-hub-app
- Repository: https://github.com/axyl1410/generative-hub-app

## Overview

##### Main Components
- Frontend (Client)
- Built with Next.js using the new App router and written in TypeScript.
- Integrates Thirdweb for wallet connection, uses Tailwind CSS, Shadcn for UI, and Framer Motion for animations.
- Contains pages for creating, minting, exploring, buying, selling NFTs as well as i18n support.
- Backend (Server)
- Built in TypeScript with Node.js.
- Uses Express-style API routing and controllers, middleware, models, and services to handle business logic.
- Manages endpoints for NFT operations including collection management, user authentication (using JWT), smart contract deployment, etc.
- Smart Contracts & Blockchain Integration
- The backend includes a "contracts" directory and uses Hardhat (as seen in hardhat.config.js) to compile and deploy smart contracts.
- Artifacts and deployment scripts indicate integration with Ethereum-based systems and the Forma NFTs Protocol.
- Databases & External Services
- Two databases are used: MongoDB (for likely document storage) and MySQL (for structured data).
- External integration with Forma technology to optimize smart contract interactions (lower gas fees, improved security).

##### Relationships and Interactions
- The Frontend communicates with the Backend via API routes (REST/Next.js API routes, as seen in both frontend and backend “api” directories).
- The Backend API uses controllers (e.g., collectionController.js, nftController.js, userController.js) and services to handle business logic.
- The Backend interacts with multiple databases for persisting NFT collections, user data, transactions, etc.
- The Backend also orchestrates blockchain operations via scripts (deploy.js, deployCollection.js) and smart contract integration facilitated by Hardhat and contract artifacts.
- Thirdweb integration in the frontend handles wallet connections, while onchain operations (and possibly zero-knowledge proofs as mentioned in the README) provide secure and decentralized processing of NFT metadata.

##### Architectural Patterns and Principles
- MVC Pattern: Notice the separation into controllers, routes, and models on the backend.
- Layered Architecture: Clear separation between the presentation layer (frontend), business logic (backend services/controllers), and data layer (databases + smart contracts).
- API-driven Development: Both frontend and backend use API routes for communication.
- Integration with external services: Thirdweb for blockchain wallet connectivity and Forma for smart contract optimization.

##### Relevant Technologies and Libraries
- Frontend: Next.js, React, TypeScript, Tailwind CSS, Shadcn UI, Framer Motion, Thirdweb.
- Backend: Node.js, Express-like API router, JWT authentication, MongoDB, MySQL.
- Blockchain Tools: Hardhat, OpenZeppelin contracts (as seen in the artifacts), deployed contract details.
- Others: Axios (for HTTP requests), utility libraries and custom hooks in the frontend, and various configuration files to manage different environments.

##### Instructing Details
- From the Frontend to the Backend to represent API calls.
- From the Backend to the Databases indicating data persistence.
- From the Backend to the Smart Contract layer (and vice versa for blockchain events/transactions).
- API/backend services (rectangles),

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client (Frontend)
    subgraph "Client (Frontend)"
        F1["Next.js App Router"]:::frontend
        F2["UI Components"]:::frontend
        F3["Thirdweb Integration"]:::frontend
    end

    %% Server (Backend)
    subgraph "Server (Backend)"
        B1["API Routes"]:::backend
        B2["Middleware"]:::backend
        B3["Controllers"]:::backend
        B4["Services"]:::backend
        B5["Models"]:::backend
    end

    %% Blockchain & Smart Contracts
    subgraph "Blockchain & Smart Contracts"
        BC1["Contracts Source"]:::blockchain
        BC2["Deployment Scripts"]:::blockchain
        BC3["Hardhat Config"]:::blockchain
        BC4["Contract Artifacts"]:::blockchain
        BC5["Blockchain Config"]:::blockchain
    end

    %% Databases
    subgraph "Databases"
        DB1["MySQL"]:::db
        DB2["MongoDB"]:::db
    end

    %% Connections between layers
    F1 -->|"API_Request"| B1
    B1 -->|"auth_check"| B2
    B2 -->|"Route_to_Controller"| B3
    B3 -->|"Controller_calls"| B4
    B4 -->|"Service_calls"| B5
    B5 -->|"Persist_MySQL"| DB1
    B5 -->|"Persist_MongoDB"| DB2
    B4 -->|"Deploy_SC"| BC2
    B3 -->|"SmartContract_call"| BC1

    %% Frontend additional interactions
    F2 -->|"Renders"| F1
    F3 -->|"Wallet_Tx"| BC1

    %% Blockchain internal configuration arrows
    BC3 -->|"configures"| BC2
    BC5 -->|"provides_config"| BC2

    %% Styles
    classDef frontend fill:#66CCFF,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFCC66,stroke:#000,stroke-width:2px;
    classDef db fill:#CCFFCC,stroke:#000,stroke-width:2px;
    classDef blockchain fill:#FF9999,stroke:#000,stroke-width:2px;

    %% Click Events
    click F1 "https://github.com/axyl1410/generative-hub-app/tree/main/frontend/app/"
    click F2 "https://github.com/axyl1410/generative-hub-app/tree/main/frontend/components/"
    click F3 "https://github.com/axyl1410/generative-hub-app/tree/main/frontend/components/thirdweb/"
    click B1 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/src/routes/"
    click B2 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/src/middleware/"
    click B3 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/src/controllers/"
    click B4 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/src/services/"
    click B5 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/src/models/"
    click BC1 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/contracts/"
    click BC2 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/scripts/"
    click BC3 "https://github.com/axyl1410/generative-hub-app/blob/main/backend/hardhat.config.js"
    click BC4 "https://github.com/axyl1410/generative-hub-app/tree/main/backend/artifacts/"
    click BC5 "https://github.com/axyl1410/generative-hub-app/blob/main/backend/config/blockchain.js"
    click DB1 "https://github.com/axyl1410/generative-hub-app/blob/main/backend/config/mysql.js"
```
