How alexlee202604-hub/vote-dapp works
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: src ZKVoting · script Deploy script · contracts.ts Chain config · page.tsx Campaigns
Components 19
Frontend
Next.js app, UI routes, and wallet wiring.
- App shell · Global layout and page framework for the dApp.
frontend/src/app/layout.tsx - Home pages · Landing and top-level user entry pages.
frontend/src/app/page.tsx - Campaigns · Browse, create, and inspect crowdfunding campaigns.
frontend/src/app/campaigns/page.tsx - Proposals · Browse, create, and inspect voting proposals.
frontend/src/app/proposals/page.tsx - Providers · Mounts wallet and data providers for the app.
frontend/src/app/providers.tsx - Chrome · Shared navigation and footer components.
frontend/src/components/Navbar.tsx - Chain config · Deployed contract addresses and chain wiring.
frontend/src/config/contracts.ts - Wagmi setup · Client-side wallet, chain, and query configuration.
frontend/src/config/wagmi.ts
Smart Contracts
Solidity business logic, deployment, and tests.
- Crowdfunding · Funding, withdrawal, and refund logic for campaigns.
contracts/src - ZKVoting · Anonymous proposal voting with proof verification and nullifiers.
contracts/src - DAOToken · Governance token used by the DAO and voting system.
contracts/src - Groth16 verifier · On-chain verifier used by the voting contract.
contracts/src - Deploy script · Deployment and address publication for Sepolia.
contracts/script - Foundry tests · Contract test and fuzzing layer for core behaviors.
contracts/test
Circuits
Circom proving logic for anonymous voting.
- Membership circuit · Proves DAO membership/eligibility for voting.
circuits/membership.circom - Vote circuit · Proves valid anonymous vote payload and eligibility.
circuits/anonymous_vote.circom
External
Wallet, chain, and protocol dependencies.
- Wallet · Browser wallet used to sign transactions and approvals.
- Sepolia · On-chain execution environment for deployed contracts.
- Web3 stack · wagmi, viem, and react-query client data layer.
Connections 25
- 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.