# alexlee202604-hub/vote-dapp architecture

> Architecture diagram of the GitHub repository alexlee202604-hub/vote-dapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alexlee202604-hub/vote-dapp
- Repository: https://github.com/alexlee202604-hub/vote-dapp

## Overview

1. **Repository shape**
   This is a three-part dApp: a Next.js frontend, Solidity smart contracts, and Circom zero-knowledge circuits. The key architectural boundary is between the browser/UI layer and the on-chain + proving layer.

2. **Frontend subsystem (`frontend/`)**
   The app uses Next.js 15 App Router with TypeScript. UI routes are organized by domain:
   - `/campaigns` for crowdfunding
   - `/proposals` for voting
   - create/detail pages for each
   Shared chrome lives in `src/components` (`Navbar`, `Footer`), while blockchain wiring lives in `src/config` (`wagmi.ts`, `contracts.ts`).

3. **Wallet and chain interaction**
   The frontend talks to Sepolia through the user’s wallet, typically MetaMask. `wagmi`, `viem`, and `@tanstack/react-query` are the main client-side Web3/data-fetching layer. `providers.tsx` is the boundary where app-wide wallet/query providers are mounted.

4. **On-chain contracts subsystem (`contracts/`)**
   This repo’s core business logic lives in Solidity contracts compiled and tested with Foundry. The README names three main contracts:
   - `Crowdfunding` for ETH/ERC20 fundraising
   - `ZKVoting` for anonymous proposals and voting
   - `DAOToken` as the governance token
   The contracts depend on OpenZeppelin primitives for security and standard token/access patterns.

5. **Crowdfunding flow**
   Users create a campaign, contribute funds, and the campaign creator can withdraw only after the target is met; otherwise contributors can refund. This is a direct user → frontend → RPC → contract flow, with the contract enforcing state transitions and using `ReentrancyGuard` plus checks-effects-interactions patterns to protect withdrawals/refunds.

6. **Anonymous voting flow**
   Voting is split across proof generation and on-chain verification. The user submits a Groth16 proof to `ZKVoting`; the contract verifies it through a dedicated `Groth16Verifier` contract, then records the vote while preventing replay/double-voting via a nullifier. Vote choice is encoded in the proof payload (`voteHash` parity per the README).

7. **Zero-knowledge circuit subsystem (`circuits/`)**
   Circom circuits are separate from the Solidity and frontend code:
   - `membership.circom` proves DAO membership
   - `anonymous_vote.circom` proves eligibility and vote validity
   The circuits are built independently and feed the verifier/proof pipeline used by `ZKVoting`.

8. **Deployment and environment boundary**
   The repo is designed around Sepolia testnet deployment. The frontend depends on deployed addresses in `frontend/src/config/contracts.ts`, while the contracts side includes a Foundry deploy script under `contracts/script`. This means address/config drift between frontend and deployed contracts is an important integration boundary.

9. **Testing and verification**
   Contract correctness is primarily enforced by Foundry tests in `contracts/test`, with fuzzing mentioned in the README. This is a separate verification layer from the frontend and circuit builds. The repository also includes OpenZeppelin’s own test and tooling dependencies under `contracts/lib/openzeppelin-contracts` and Foundry standard utilities under `contracts/lib/forge-std`.

10. **Library and tooling dependencies that affect architecture**
    The contracts are not standalone; they rely on OpenZeppelin for ERC20, access control, reentrancy protection, and upgrade/proxy utilities. Foundry is the build/test/deploy toolchain. Circom tooling is isolated in the `circuits` package with its own Node dependencies and build step.

11. **Likely end-to-end interaction model**
    A user flow starts in the browser UI, connects a wallet, reads campaign/proposal state from Sepolia, and sends transactions back through the wallet to the contracts. For voting, the browser/user workflow also includes generating or supplying a ZK proof, which the contract validates on-chain before accepting the vote. The frontend is therefore a thin orchestration layer; the authoritative state and rules live on-chain, with ZK proving as a separate cryptographic subsystem.

Main entry points: [`contracts/src`](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src) (ZKVoting), [`contracts/script`](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/script) (Deploy script), [`frontend/src/config/contracts.ts`](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/config/contracts.ts) (Chain config), [`frontend/src/app/campaigns/page.tsx`](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/campaigns/page.tsx) (Campaigns)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_ui_shell["App shell<br/>Next.js App Router<br/>[layout.tsx]"]
  node_home_routes["Home pages<br/>Route pages<br/>[page.tsx]"]
  node_campaign_routes["Campaigns<br/>Crowdfunding UI<br/>[page.tsx]"]
  node_proposal_routes["Proposals<br/>Voting UI<br/>[page.tsx]"]
  node_providers(("Providers<br/>Web3 boundary<br/>[providers.tsx]"))
  node_chrome["Chrome<br/>Shared UI<br/>[Navbar.tsx]"]
  node_chain_cfg["Chain config<br/>Address config<br/>[contracts.ts]"]
  node_wagmi_cfg["Wagmi setup<br/>Web3 client<br/>[wagmi.ts]"]
end

subgraph group_contracts["Smart Contracts"]
  node_crowdfunding["Crowdfunding<br/>Solidity core"]
  node_zkvoting["ZKVoting<br/>Solidity core"]
  node_dao_token["DAOToken<br/>ERC20 governance"]
  node_verifier{{"Groth16 verifier<br/>ZK verifier"}}
  node_deploy["Deploy script<br/>Foundry script"]
  node_contract_tests["Foundry tests<br/>Verification"]
end

subgraph group_circuits["Circuits"]
  node_membership_circuit["Membership circuit<br/>Circom circuit<br/>[membership.circom]"]
  node_anonymous_vote_circuit["Vote circuit<br/>Circom circuit"]
end

subgraph group_external["External"]
  node_wallet(("Wallet<br/>User signer"))
  node_sepolia[("Sepolia<br/>Testnet")]
  node_web3_stack["Web3 stack<br/>Libraries"]
end

node_ui_shell -->|"mounts"| node_providers
node_ui_shell -->|"renders"| node_chrome
node_home_routes -->|"navigates"| node_campaign_routes
node_home_routes -->|"navigates"| node_proposal_routes
node_campaign_routes -->|"reads addresses"| node_chain_cfg
node_proposal_routes -->|"reads addresses"| node_chain_cfg
node_providers -->|"installs"| node_wagmi_cfg
node_wagmi_cfg -->|"uses"| node_web3_stack
node_chain_cfg -->|"targets"| node_sepolia
node_wallet -->|"connects"| node_providers
node_wallet -->|"signs tx"| node_sepolia
node_campaign_routes -->|"calls"| node_crowdfunding
node_proposal_routes -->|"calls"| node_zkvoting
node_crowdfunding -->|"verified by"| node_contract_tests
node_zkvoting -->|"verified by"| node_contract_tests
node_crowdfunding -->|"deployed on"| node_sepolia
node_zkvoting -->|"deployed on"| node_sepolia
node_dao_token -->|"governs"| node_zkvoting
node_zkvoting -->|"verifies proof"| node_verifier
node_anonymous_vote_circuit -->|"compiles to"| node_verifier
node_membership_circuit -->|"feeds"| node_anonymous_vote_circuit
node_deploy -->|"deploys"| node_crowdfunding
node_deploy -->|"deploys"| node_zkvoting
node_deploy -->|"deploys"| node_dao_token
node_deploy -->|"writes addresses"| node_chain_cfg

click node_ui_shell "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/layout.tsx"
click node_home_routes "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/page.tsx"
click node_campaign_routes "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/campaigns/page.tsx"
click node_proposal_routes "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/proposals/page.tsx"
click node_providers "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/providers.tsx"
click node_chrome "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/components/Navbar.tsx"
click node_chain_cfg "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/config/contracts.ts"
click node_wagmi_cfg "https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/config/wagmi.ts"
click node_crowdfunding "https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src"
click node_zkvoting "https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src"
click node_dao_token "https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src"
click node_verifier "https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src"
click node_deploy "https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/script"
click node_contract_tests "https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/test"
click node_membership_circuit "https://github.com/alexlee202604-hub/vote-dapp/blob/main/circuits/membership.circom"
click node_anonymous_vote_circuit "https://github.com/alexlee202604-hub/vote-dapp/blob/main/circuits/anonymous_vote.circom"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui_shell,node_home_routes,node_campaign_routes,node_proposal_routes,node_providers,node_chrome,node_chain_cfg,node_wagmi_cfg toneBlue
class node_crowdfunding,node_zkvoting,node_dao_token,node_verifier,node_deploy,node_contract_tests toneAmber
class node_membership_circuit,node_anonymous_vote_circuit toneMint
class node_wallet,node_sepolia,node_web3_stack toneRose
```

## Components

### Frontend

Next.js app, UI routes, and wallet wiring.

- [App shell](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/layout.tsx): Next.js App Router · Global layout and page framework for the dApp. · `frontend/src/app/layout.tsx`
- [Home pages](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/page.tsx): Route pages · Landing and top-level user entry pages. · `frontend/src/app/page.tsx`
- [Campaigns](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/campaigns/page.tsx): Crowdfunding UI · Browse, create, and inspect crowdfunding campaigns. · `frontend/src/app/campaigns/page.tsx`
- [Proposals](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/proposals/page.tsx): Voting UI · Browse, create, and inspect voting proposals. · `frontend/src/app/proposals/page.tsx`
- [Providers](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/app/providers.tsx): Web3 boundary · Mounts wallet and data providers for the app. · `frontend/src/app/providers.tsx`
- [Chrome](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/components/Navbar.tsx): Shared UI · Shared navigation and footer components. · `frontend/src/components/Navbar.tsx`
- [Chain config](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/config/contracts.ts): Address config · Deployed contract addresses and chain wiring. · `frontend/src/config/contracts.ts`
- [Wagmi setup](https://github.com/alexlee202604-hub/vote-dapp/blob/main/frontend/src/config/wagmi.ts): Web3 client · Client-side wallet, chain, and query configuration. · `frontend/src/config/wagmi.ts`

### Smart Contracts

Solidity business logic, deployment, and tests.

- [Crowdfunding](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src): Solidity core · Funding, withdrawal, and refund logic for campaigns. · `contracts/src`
- [ZKVoting](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src): Solidity core · Anonymous proposal voting with proof verification and nullifiers. · `contracts/src`
- [DAOToken](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src): ERC20 governance · Governance token used by the DAO and voting system. · `contracts/src`
- [Groth16 verifier](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/src): ZK verifier · On-chain verifier used by the voting contract. · `contracts/src`
- [Deploy script](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/script): Foundry script · Deployment and address publication for Sepolia. · `contracts/script`
- [Foundry tests](https://github.com/alexlee202604-hub/vote-dapp/tree/main/contracts/test): Verification · Contract test and fuzzing layer for core behaviors. · `contracts/test`

### Circuits

Circom proving logic for anonymous voting.

- [Membership circuit](https://github.com/alexlee202604-hub/vote-dapp/blob/main/circuits/membership.circom): Circom circuit · Proves DAO membership/eligibility for voting. · `circuits/membership.circom`
- [Vote circuit](https://github.com/alexlee202604-hub/vote-dapp/blob/main/circuits/anonymous_vote.circom): Circom circuit · Proves valid anonymous vote payload and eligibility. · `circuits/anonymous_vote.circom`

### External

Wallet, chain, and protocol dependencies.

- **Wallet**: User signer · Browser wallet used to sign transactions and approvals.
- **Sepolia**: Testnet · On-chain execution environment for deployed contracts.
- **Web3 stack**: Libraries · wagmi, viem, and react-query client data layer.

## Connections

- App shell → Providers: mounts · App-wide provider tree is mounted at the root.
- App shell → Chrome: renders · Shared navigation and footer frame the routes.
- Home pages → Campaigns: navigates · Entry pages lead into the crowdfunding flow.
- Home pages → Proposals: navigates · Entry pages lead into the voting flow.
- Campaigns → Chain config: reads addresses · Campaign UI uses deployed contract addresses.
- Proposals → Chain config: reads addresses · Proposal UI uses deployed contract addresses.
- Providers → Wagmi setup: installs · Provider layer wires the client Web3 stack.
- Wagmi setup → Web3 stack: uses · Web3 transport and cache libraries power the frontend.
- Chain config → Sepolia: targets · Configured addresses point to Sepolia deployments.
- Wallet → Providers: connects · User wallet connects through the app provider boundary.
- Wallet → Sepolia: signs tx · Transactions are signed in the browser and sent to chain.
- Campaigns → Crowdfunding: calls · Frontend creates campaigns, contributes, withdraws, and refunds through the contract.
- Proposals → ZKVoting: calls · Frontend submits proposal and voting transactions.
- Crowdfunding → Foundry tests: verified by · Foundry tests validate fundraising state transitions.
- ZKVoting → Foundry tests: verified by · Foundry tests validate voting and replay protection.
- Crowdfunding → Sepolia: deployed on · Primary runtime for campaign execution.
- ZKVoting → Sepolia: deployed on · Primary runtime for proposal voting.
- DAOToken → ZKVoting: governs · Governance token is part of the voting system boundary.
- ZKVoting → Groth16 verifier: verifies proof · Voting contract delegates Groth16 proof checking.
- Vote circuit → Groth16 verifier: compiles to · Circuit output feeds the on-chain verifier.
- Membership circuit → Vote circuit: feeds · Membership proof is an input to anonymous voting.
- Deploy script → Crowdfunding: deploys · Foundry scripts publish contract instances.
- Deploy script → ZKVoting: deploys · Foundry scripts publish contract instances.
- Deploy script → DAOToken: deploys · Foundry scripts publish contract instances.
- Deploy script → Chain config: writes addresses · Deployment output must be synchronized to frontend config.
