Overview
Agora is built as a modern, scalable web application using Next.js 14, React, TypeScript, and PostgreSQL. The architecture is designed to support multiple DAOs on a single platform through a multi-tenant system with isolated data and configurations.High-Level Architecture
Multi-Tenant Design
Agora’s core architectural pattern is multi-tenancy, allowing multiple DAOs to run on a single codebase and infrastructure while maintaining complete isolation.Tenant Configuration
Each DAO is identified by a tenant namespace (e.g.,ens, optimism, uniswap). The tenant system is implemented in /src/lib/tenant/:
The tenant is determined by the
NEXT_PUBLIC_AGORA_INSTANCE_NAME environment variable.Tenant Components
Each tenant configuration includes:- Contracts
- Token
- UI Configuration
- Database Schema
Blockchain contract addresses and configurations:Contract configurations are defined in
/src/lib/tenant/configs/contracts/.Adding a New Tenant
To add a new DAO to Agora:Create contract configuration
Add a new file in
/src/lib/tenant/configs/contracts/your-dao.ts with governor, token, and other contract addresses.Create UI configuration
Add
/src/lib/tenant/configs/ui/your-dao.ts with branding, colors, and feature toggles.Update factories
Add your DAO namespace to:
TenantContractFactoryin/src/lib/tenant/tenantContractFactory.tsTenantUIFactoryin/src/lib/tenant/tenantUIFactory.tsTenantTokenFactoryin/src/lib/tenant/tenantTokenFactory.ts
Database Architecture
Agora uses PostgreSQL with Prisma ORM for data persistence. The database is organized into multiple schemas:Schema Organization
Dual Database Pattern
Agora separates data into two logical databases:Web2 Database
User-Generated Content
- Delegate statements and profiles
- Forum topics and posts
- User settings and notifications
- Email preferences
Web3 Database
Blockchain-Indexed Data
- Proposals from governor contracts
- Votes from onchain events
- Delegate power calculations
- Token transfers and balances
Key Data Models
Agora’s data models are defined in the Prisma schema (/prisma/schema.prisma):
- Proposals
- Votes
- Delegates
- Delegate Statements
Governance proposals are stored per-tenant:Each tenant schema has its own
proposals table.Views and Materialized Views
For performance, Agora uses PostgreSQL views:- Views: Dynamic queries computed on read (e.g.,
citizens,badgeholders) - Materialized Views: Precomputed results refreshed periodically (e.g., delegate rankings)
Application Structure
Agora follows Next.js 14 App Router conventions:Directory Structure
Key Directories
/src/app
/src/app
Next.js App Router
- File-based routing (no Router configuration)
- Each folder is a route (e.g.,
/proposals→/src/app/proposals) page.tsxfiles define route contentlayout.tsxdefines shared layouts- Server and client components mixed
/src/app/api
/src/app/api
API Routes and Server Functions
- REST API endpoints in
/api/v1/ - Data fetching functions in
/api/common/ - Server actions for mutations
- All data access uses Prisma ORM
- React
cache()wrapper for request deduplication
/src/components
/src/components
React Components
- Organized by feature (Proposals, Delegates, Votes, Forum)
- Mix of
.tsx(TypeScript) and.jsx(JavaScript) - Styled with SCSS modules (
Component.module.scss) - Some use Tailwind utility classes
- Legacy components use Emotion CSS-in-JS
/src/lib
/src/lib
Utilities and Business Logic
tenant/: Multi-tenant configuration systemcontracts/: Contract ABIs, TypeChain types, and interfacesactions/: Server actions for mutationsutils.ts: Shared utility functionstypes.d.ts: TypeScript type definitions
Technology Stack
Frontend Technologies
Next.js 14
React framework with App Router, server components, and API routes. Deployed on Vercel.
React 18
UI library with server and client components, Suspense, and concurrent rendering.
TypeScript
Type-safe JavaScript with comprehensive interfaces and type definitions.
Tailwind CSS
Utility-first CSS framework. Also uses SCSS modules and legacy Emotion styles.
ConnectKit
Wallet connection UI with support for MetaMask, WalletConnect, Coinbase Wallet, etc.
Wagmi & Viem
React hooks and TypeScript library for Ethereum interactions.
Backend Technologies
Prisma ORM
Type-safe database client for PostgreSQL with multi-schema support.
PostgreSQL
Relational database with schemas, views, materialized views, and full-text search.
Ethers.js v6
Ethereum library for contract interactions, TypeChain for type generation.
OpenTelemetry
Distributed tracing, metrics, and observability integration.
External Services
- Blockchain
- Storage & Data
- Communication
- Developer Tools
- Alchemy: Primary RPC provider for Ethereum, Optimism, Base, etc.
- Etherscan: Contract verification and ABI fetching
- Tenderly: Transaction simulation for proposal execution preview
- EAS: Ethereum Attestation Service for delegate verification
Data Flow
Proposal Creation Flow
Voting Flow
Performance Optimizations
Agora implements several performance optimizations:Request Deduplication
Request Deduplication
Uses React Multiple components requesting the same data get cached results.
cache() to deduplicate data fetches within a single request:Materialized Views
Materialized Views
Precomputed database views for expensive queries:
- Delegate rankings and voting power
- Proposal statistics and aggregations
- Refreshed periodically by database triggers
Incremental Static Regeneration
Incremental Static Regeneration
Pages are statically generated and revalidated:Balances static site speed with fresh data.
Server Components
Server Components
Next.js server components fetch data on the server, reducing client bundle size and improving initial load time.
Security Considerations
Security Best Practices
Environment variable separation
NEXT_PUBLIC_*: Safe for browser (API keys, public addresses)- Server-only: Private keys, database URLs, JWT secrets
API authentication
- Use API keys for programmatic access
- JWT tokens for user sessions
- Rate limiting with Redis
Database access
- Read-only connection for web3 data
- Parameterized queries (Prisma prevents SQL injection)
- Row-level security for multi-tenant isolation
Observability
Agora includes comprehensive observability:- OpenTelemetry: Distributed tracing for request flows
- DataDog: Application metrics and alerts (optional)
- Vercel Analytics: Web vitals and performance monitoring
- Prisma Logging: Database query logging in development
Next Steps
Now that you understand Agora’s architecture:Customization Guide
Learn how to customize UI, add features, and extend functionality.
Deployment Guide
Deploy Agora to production with Vercel or your own infrastructure.
API Reference
Explore the REST API for building integrations and tools.
Contributing
Contribute to Agora development on GitHub.