# hayashi13597/flexibble-web3 architecture

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

- Interactive diagram: https://gitdiagram.com/hayashi13597/flexibble-web3
- Repository: https://github.com/hayashi13597/flexibble-web3

## Overview

##### Project Type & Purpose
- The project is a hybrid web application that combines a creative portfolio platform (resembling Dribbble, here called “Flexibble”) with a crowdfunding component that integrates Web3 functionality.
- The Flexibble side allows users to sign in with Gmail (authentication), share, edit, and delete work; the Crowdfunding side allows users to connect a wallet (e.g., via MetaMask), create campaigns, fund them, and view profiles with campaign lists.
- It leverages Next.js with API routes for serverless backend functions, and it appears to be extended with a GraphQL backend through a “grafbase” integration. There’s also notable Web3-specific modules for blockchain interactions.

##### Analyzing the File Structure
- The top-level directories include:
- app: Contains all Next.js pages and API routes. Here you have separate subdirectories for API routes (such as /api/auth, /api/upload, etc.) and top-level pages for different sections (main page, projects, profiles).
- app/web3: Dedicated folder for Web3-specific pages, including campaign details, creation, and profile views for the campaigning aspect.
- components: Reusable React components that support both the Flexibble and Web3 sides. Note separate Web3 components are also organized under components/Web3Component.
- context, lib, utils: Helper modules handling shared logic like session management, actions, and utilities.
- grafbase and graphql: These indicate a GraphQL service configuration likely used for data handling and possibly managing interactions between the front-end and a database.
- The presence of route.ts files hints at serverless functions used to handle dynamic API endpoints (e.g., for authentication with NextAuth, image uploads, and token management).

##### Key Components
a. Frontend (Client – Next.js):
- Two major sections: Flexibble (general pages such as home, create/edit project, profiles) and Crowdfunding/Web3 (pages under app/web3 including campaign details, wallet connection, campaign creation, etc.).
- Shared components (Navbar, Footer, Modals, Form components) that are rendered in these pages.
- Layout components (layout.tsx files) organizing the overall structure.
b. Backend/API Routes:
- API Endpoints:
- Auth endpoints for NextAuth (app/api/auth).
- Token and image handling endpoints.
- Upload and delete-image endpoints.
- These serverless routes manage communication with data services.
c. GraphQL Backend (Grafbase):
- The grafbase directory holds configuration and an environment file for the GraphQL backend.
- This is connected to the “graphql” folder where client-side graphql queries/mutations are defined, suggesting that the frontend interacts with this layer to manage persistent data.
d. Web3 Integration:
- Dedicated components and pages that allow wallet connection, interaction with blockchain/campaign smart contracts.
- Components under components/Web3Component (e.g., DisplayCampaigns, FundCard, CustomButton) indicate how the UI is built for blockchain interactions.
e. Supporting Services & Libraries:
- Authentication using NextAuth (indicated by the [...nextauth] folder).
- Third-party integrations with MetaMask for wallet connection.
- Utility libraries and context management to manage global states like sessions and modals.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Notice the clear separation between UI (pages/components), API routes (serverless functions), GraphQL backend configuration, and utility functions.
- Modularization: Components are grouped by domain (regular vs. Web3) and API functionality, making it easier to identify dependencies and extend functionality.
- Integration Layer: The app serves as an integration point between conventional RESTful API calls and modern GraphQL interactions, along with blockchain (Web3) operations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flexibble Frontend UI
    subgraph "Flexibble Frontend UI"
        F1["Home Page"]:::flexibble
        F2["Create Project"]:::flexibble
        F3["Edit Project"]:::flexibble
        F4["Profile Page"]:::flexibble
        F5["Project Details"]:::flexibble
        F6["Shared Layout"]:::flexibble
        F7["Navbar"]:::flexibble
        F8["Footer"]:::flexibble
        F9["Modal"]:::flexibble
        F10["FormField"]:::flexibble
        F11["ProjectCard"]:::flexibble
    end

    %% Crowdfunding/Web3 Frontend UI
    subgraph "CrowdFunding/Web3 Frontend UI"
        W1["Web3 Home"]:::web3
        W2["Create Campaign"]:::web3
        W3["Web3 Profile"]:::web3
        W4["Campaign Details"]:::web3
        W5["Web3 Layout"]:::web3
        W6["CountBox"]:::web3
        W7["CustomButton"]:::web3
        W8["DisplayCampaigns"]:::web3
        W9["FundCard"]:::web3
        W10["Loader"]:::web3
        W11["Web3 Navbar"]:::web3
        W12["Sidebar"]:::web3
        W13["Web3Index"]:::web3
    end

    %% Backend API Routes
    subgraph "Backend API Routes"
        A1["Auth Endpoint"]:::api
        A2["Token Endpoint"]:::api
        A3["Upload Endpoint"]:::api
        A4["Delete Image Endpoint"]:::api
    end

    %% GraphQL Backend
    subgraph "GraphQL Backend"
        G1["Grafbase Config"]:::graphql
        G2["Grafbase Env"]:::graphql
        G3["GraphQL Client"]:::graphql
    end

    %% Supporting Services & Utilities
    subgraph "Supporting Services & Utilities"
        S1["Session"]:::support
        S2["Actions"]:::support
        S3["Global Context"]:::support
        S4["Utilities"]:::support
        S5["Constants"]:::support
        S6["Web3 Constants"]:::support
    end

    %% Connections from Flexibble Frontend to API Routes
    F1 -->|"callsAPI"| A1
    F2 -->|"submitProject"| A3
    F4 -->|"fetchUserData"| A1

    %% Connections from Crowdfunding/Web3 Frontend to API Routes
    W1 -->|"initWallet"| A1
    W2 -->|"createCampaign"| A3
    W4 -->|"fetchCampaign"| A1

    %% API Routes connecting to GraphQL Backend
    A1 -->|"fetchGraphQL"| G3
    A2 -->|"refreshToken"| G3
    A3 -->|"uploadData"| G3
    A4 -->|"deleteData"| G3

    %% Supporting Services linking to Frontend and API components
    S1 -.-> F6
    S2 -.-> F7
    S3 -.-> F1
    S4 -.-> A1
    S5 -.-> F10
    S6 -.-> W7

    %% Style classes
    classDef flexibble fill:#AEDFF7,stroke:#000,stroke-width:1px;
    classDef web3 fill:#FFDD9E,stroke:#000,stroke-width:1px;
    classDef api fill:#C3F7B0,stroke:#000,stroke-width:1px;
    classDef graphql fill:#FCE9AE,stroke:#000,stroke-width:1px;
    classDef support fill:#E6A9EC,stroke:#000,stroke-width:1px;

    %% Click Events for Flexibble Frontend UI
    click F1 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/page.tsx"
    click F2 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/create-project/page.tsx"
    click F3 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/edit-project/[id]/page.tsx"
    click F4 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/profile/[id]/page.tsx"
    click F5 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/project/[id]/page.tsx"
    click F6 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/layout.tsx"
    click F7 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Navbar.tsx"
    click F8 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Footer.tsx"
    click F9 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Modal.tsx"
    click F10 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/FormField.tsx"
    click F11 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/ProjectCard.tsx"

    %% Click Events for CrowdFunding/Web3 Frontend UI
    click W1 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/web3/page.tsx"
    click W2 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/web3/create-campaign/page.tsx"
    click W3 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/web3/profile/page.tsx"
    click W4 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/web3/campaign-details/[campaign]/page.tsx"
    click W5 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/web3/layout.tsx"
    click W6 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/CountBox.tsx"
    click W7 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/CustomButton.tsx"
    click W8 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/DisplayCampaigns.tsx"
    click W9 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/FundCard.tsx"
    click W10 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/Loader.tsx"
    click W11 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/Navbar.tsx"
    click W12 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/Sidebar.tsx"
    click W13 "https://github.com/hayashi13597/flexibble-web3/blob/main/components/Web3Component/index.tsx"

    %% Click Events for Backend API Routes
    click A1 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/api/auth/[...nextauth]/route.ts"
    click A2 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/api/auth/token/route.ts"
    click A3 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/api/upload/route.ts"
    click A4 "https://github.com/hayashi13597/flexibble-web3/blob/main/app/api/delete-image/route.ts"

    %% Click Events for GraphQL Backend
    click G1 "https://github.com/hayashi13597/flexibble-web3/blob/main/grafbase/grafbase.config.ts"
    click G2 "https://github.com/hayashi13597/flexibble-web3/blob/main/grafbase/.env"
    click G3 "https://github.com/hayashi13597/flexibble-web3/blob/main/graphql/index.ts"

    %% Click Events for Supporting Services & Utilities
    click S1 "https://github.com/hayashi13597/flexibble-web3/blob/main/lib/session.ts"
    click S2 "https://github.com/hayashi13597/flexibble-web3/blob/main/lib/actions.ts"
    click S3 "https://github.com/hayashi13597/flexibble-web3/blob/main/context/index.tsx"
    click S4 "https://github.com/hayashi13597/flexibble-web3/blob/main/utils/index.ts"
    click S5 "https://github.com/hayashi13597/flexibble-web3/blob/main/constants/index.ts"
    click S6 "https://github.com/hayashi13597/flexibble-web3/blob/main/constants/web3.ts"
```
