# anish-u/luna-fund architecture

> Architecture diagram of the GitHub repository anish-u/luna-fund, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anish-u/luna-fund
- Repository: https://github.com/anish-u/luna-fund

## Overview

##### Project Type and Purpose
- Luna Fund is a full-stack decentralized crowdfunding dApp.
- Frontend: Next.js + TypeScript + TailwindCSS, using the app-router, React contexts, and a component design system (atoms/molecules/organisms).
- Blockchain layer: Solidity smart contracts deployed via Hardhat to a local or public Ethereum network.
- Interactions: Browser users connect wallets (e.g. via Web3Modal), read/write on-chain via Ethers.js.

##### File-Structure Analysis
Top-level:
- app/ – Next.js routes (home, missions, create, mission details, requests).
- components/ – UI design system:
– atoms (buttons, progress bar)
– molecules (NavBar, Footer, MissionCard)
– organisms (page-level composites)
- context/ – LunaFund React context for shared state.
- wrapper/ – clientWrapper for app-wide providers (e.g. Web3Modal).
- contracts/ – Solidity contracts.
- scripts/ – Hardhat deploy script (deploy.js).
- hardhat.config.js – local blockchain config.
- public/demo/images – documentation screenshots.
- config files – next.config.ts, tailwind.config.js, tsconfig.json.

##### README Insights
- Emphasizes on-chain mission creation, funding, and governed withdrawals.
- Uses Ethers.js for contract calls, Web3Modal for wallet.
- Hardhat handles testing and deployment scripts.

a. Main Components
1. User Browser
2. Next.js Frontend (UI)
3. Web3Modal Wallet Connector
4. Ethers.js Client Library
5. Ethereum Node (Hardhat local node or Infura/Alchemy on mainnet/testnet)
6. Solidity Smart Contracts (MissionFactory, Mission, Request)
7. Deployment Script (Hardhat scripts/deploy.js)
8. (Optional) Off-chain Data Store or IPFS if extended in future

b. Relationships & Data Flow
- Browser → Next.js UI (React components)
- UI triggers Web3Modal to connect wallet → returns signer
- UI/Ethers.js calls smart-contract functions (createMission, contribute, createRequest, approveRequest, finalizeRequest) on the Ethereum node
- Ethereum node processes transactions and emits events
- UI subscribes to events or polls contract state to update progress bars and pages

c. Architectural Patterns & Principles
- Component-based UI (Atomic Design: atoms → molecules → organisms)
- Context API for global state (wallet state, contract instance)
- App routing using Next.js File-System Router
- Single-Page-App with server-side prerendering and CSR for dynamic on-chain data
- Separation of concerns: UI, business logic (contract ABI + Ethers.js), blockchain execution

d. Key Technologies & Frameworks
- Frontend: Next.js, React, TypeScript, TailwindCSS
- Blockchain: Solidity, Hardhat, Ethers.js, Web3Modal
- Deployment: Hardhat + scripts/deploy.js
- Tooling: pnpm/npm, ESLint, Prettier, VSCode settings

## Diagram (Mermaid)

```mermaid
flowchart TB
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef middleware fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef blockchain fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef external fill:#EEEEEE,stroke:#333,stroke-width:1px

    UserBrowser(("User Browser")):::external

    subgraph "Frontend (Next.js + TypeScript)" 
        direction TB
        subgraph "UI Routes" 
            direction TB
            Home["Home Route"]:::frontend
            MissionsList["Missions List Route"]:::frontend
            MissionDetails["Mission Details Route"]:::frontend
            Requests["Requests Route"]:::frontend
            CreateMission["Create Mission Route"]:::frontend
        end
        subgraph "Atomic Design System" 
            direction TB
            subgraph Atoms
                Button["Button"]:::frontend
                ProgressBar["Progress Bar"]:::frontend
            end
            subgraph Molecules
                NavBar["NavBar"]:::frontend
                Footer["Footer"]:::frontend
                MissionCard["MissionCard"]:::frontend
            end
            subgraph Organisms
                HomeOrg["Home Organism"]:::frontend
                MissionsOrg["Missions Organism"]:::frontend
                MissionOrg["Mission Organism"]:::frontend
                CreateMissionOrg["Create Mission Organism"]:::frontend
                CreateRequestOrg["Create Request Organism"]:::frontend
            end
        end
        ContextProvider["LunaFund Context Provider"]:::frontend
        Wrapper["Client Wrapper (Web3Modal, Ethers.js)"]:::frontend
        Constants["SmartContract Config"]:::frontend
        subgraph "Config Files"
            nextConfig["next.config.ts"]:::frontend
            tailwindConfig["tailwind.config.js"]:::frontend
            tsconfig["tsconfig.json"]:::frontend
        end
    end

    subgraph "Middleware" 
        direction TB
        Web3Modal["Web3Modal"]:::middleware
        EthersJS["Ethers.js Service"]:::middleware
    end

    subgraph "Blockchain Layer"
        direction TB
        EthereumNode["Ethereum Node\n(Local Hardhat / Infura)"]:::blockchain
        SmartContracts(("Smart Contract State")):::blockchain
    end

    subgraph "Deployment"
        direction TB
        HardhatConfig["hardhat.config.js"]:::blockchain
        DeployScript["Deploy Script"]:::blockchain
        TypeDefs["Mission Types"]:::blockchain
    end

    UserBrowser -->|interacts with| Home
    UserBrowser --> MissionsList
    UserBrowser --> MissionDetails
    UserBrowser --> Requests
    UserBrowser --> CreateMission

    Home --> Wrapper
    MissionsList --> Wrapper
    MissionDetails --> Wrapper
    Requests --> Wrapper
    CreateMission --> Wrapper

    Wrapper --> Web3Modal
    Wrapper --> EthersJS
    ContextProvider --> Wrapper
    Home --> ContextProvider
    MissionsList --> ContextProvider
    MissionDetails --> ContextProvider
    CreateMission --> ContextProvider
    Requests --> ContextProvider

    EthersJS -->|eth_sendTransaction / call| EthereumNode
    EthereumNode -->|emit event / state| EthersJS
    EthersJS -->|update| HomeOrg
    EthersJS -->|update| MissionsOrg
    EthersJS -->|update| MissionOrg

    DeployScript -->|deploys| SmartContracts
    HardhatConfig --> DeployScript
    TypeDefs --> HomeOrg

    EthereumNode --> SmartContracts

    class Home,MissionsList,MissionDetails,Requests,CreateMission,Button,ProgressBar,NavBar,Footer,MissionCard,HomeOrg,MissionsOrg,MissionOrg,CreateMissionOrg,CreateRequestOrg,ContextProvider,Wrapper,Constants,nextConfig,tailwindConfig,tsconfig frontend
    class Web3Modal,EthersJS middleware
    class EthereumNode,SmartContracts,HardhatConfig,DeployScript,TypeDefs blockchain

    click Home "https://github.com/anish-u/luna-fund/blob/main/app/(routes)/page.tsx"
    click MissionsList "https://github.com/anish-u/luna-fund/blob/main/app/(routes)/missions/page.tsx"
    click MissionDetails "https://github.com/anish-u/luna-fund/blob/main/app/(routes)/missions/[missionId]/page.tsx"
    click Requests "https://github.com/anish-u/luna-fund/blob/main/app/(routes)/missions/[missionId]/requests/page.tsx"
    click CreateMission "https://github.com/anish-u/luna-fund/blob/main/app/(routes)/missions/create/page.tsx"

    click Button "https://github.com/anish-u/luna-fund/blob/main/components/atoms/button.tsx"
    click ProgressBar "https://github.com/anish-u/luna-fund/blob/main/components/atoms/progress-bar.tsx"
    click NavBar "https://github.com/anish-u/luna-fund/blob/main/components/molecules/NavBar.tsx"
    click Footer "https://github.com/anish-u/luna-fund/blob/main/components/molecules/Footer.tsx"
    click MissionCard "https://github.com/anish-u/luna-fund/blob/main/components/molecules/MissionCard.tsx"
    click HomeOrg "https://github.com/anish-u/luna-fund/blob/main/components/organisms/home.tsx"
    click MissionsOrg "https://github.com/anish-u/luna-fund/blob/main/components/organisms/missions.tsx"
    click MissionOrg "https://github.com/anish-u/luna-fund/blob/main/components/organisms/mission.tsx"
    click CreateMissionOrg "https://github.com/anish-u/luna-fund/blob/main/components/organisms/create-mission.tsx"
    click CreateRequestOrg "https://github.com/anish-u/luna-fund/blob/main/components/organisms/create-request.tsx"

    click ContextProvider "https://github.com/anish-u/luna-fund/blob/main/context/LunaFund.tsx"
    click Wrapper "https://github.com/anish-u/luna-fund/blob/main/wrapper/clientWrapper.tsx"
    click Constants "https://github.com/anish-u/luna-fund/blob/main/constants/smartContract.ts"
    click HardhatConfig "https://github.com/anish-u/luna-fund/blob/main/hardhat.config.js"
    click DeployScript "https://github.com/anish-u/luna-fund/blob/main/scripts/deploy.js"
    click TypeDefs "https://github.com/anish-u/luna-fund/blob/main/types/mission.ts"
    click nextConfig "https://github.com/anish-u/luna-fund/blob/main/next.config.ts"
    click tailwindConfig "https://github.com/anish-u/luna-fund/blob/main/tailwind.config.js"
    click tsconfig "https://github.com/anish-u/luna-fund/blob/main/tsconfig.json"
```
