Klara is an AI chatbot built for the Polkadot and Kusama governance ecosystem, integrated with Polkassembly. It helps users query on-chain data, explore governance insights, and understand the entire proposal and voting processβall in natural language.
- π§ AI-Powered Governance Assistant: Natural language queries about Polkadot/Kusama governance
- π Web3 Authentication: Secure wallet-based authentication (Polkadot.js, SubWallet, Talisman)
- π¬ Real-time Chat: Token-by-token streaming responses with conversation management
- π³οΈ Governance Data Querying: Access proposals, referenda, voting data, and treasury information
- π Voting Analysis: Deep analysis of voter behavior and governance participation
- πΎ Dual Database Support: Firestore for conversations + PostgreSQL for analytics
- π¨ Beautiful UI: Polkassembly-inspired design with responsive layout
- βοΈ Production Ready: Optimized for serverless deployment
- Node.js 18+
- npm or yarn
- Firebase project (for Firestore)
- PostgreSQL database (optional, for analytics)
- Clone the repository:
git clone <your-repo-url>
cd polkassembly-frontend- Install dependencies:
npm install- Set up environment variables:
# Copy the example env file
cp .env.example .env.local
# Edit .env.local with your configuration- Run the development server:
npm run dev- Open http://localhost:3000 in your browser.
Create a .env.local file with the following variables:
# API Configuration
API_BASE_URL=https://your-klara-api-endpoint.com
POLKASSEMBLY_AI_TOKEN=your_api_token_here
# Firebase Configuration (Required)
NEXT_PUBLIC_FIREBASE_API_KEY=your_firebase_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id
# PostgreSQL Configuration (Optional - for analytics)
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DATABASE=polkassembly
POSTGRES_USER=postgres
POSTGRES_PASSWORD=your_password
POSTGRES_SSL=false
DISABLE_POSTGRES=false
# Application Settings
NODE_ENV=development
CONVERSATION_HISTORY_LIMIT=5
JWT_SECRET=your_jwt_secret_keyFirestore (Required): Used for storing conversations and user data
- Set up a Firebase project and enable Firestore
- Configure the Firebase environment variables
PostgreSQL (Optional): Used for analytics and query logging
- Set up PostgreSQL database
- Tables are automatically created on first run
- Set
DISABLE_POSTGRES=trueto disable PostgreSQL features
- Connect Wallet: Use Polkadot.js, SubWallet, or Talisman to authenticate
- Start Chatting: Ask questions about Polkadot/Kusama governance in natural language
- Manage Conversations: Create new conversations or continue existing ones
- Explore Data: Query proposals, referenda, voting patterns, and treasury information
- "Show me all active referenda on Polkadot"
- "Who voted 'nay' on referendum 300?"
- "List treasury proposals above 100,000 DOT"
- "Find all bounties created in 2024"
- "Show voting power analysis for recent referenda"
src/
βββ app/ # Next.js app directory
β βββ api/ # API routes
β β βββ auth/wallet/ # Wallet authentication
β β βββ chat/ # Chat endpoint with streaming
β β βββ chat-history/ # Chat history retrieval
β β βββ conversations/ # Conversation management
β β βββ conversation-messages/# Message retrieval
β β βββ feedback/ # User feedback collection
β β βββ health/ # Health check endpoint
β β βββ init-user/ # User initialization
β β βββ stats/ # Statistics endpoint
β βββ feedback/ # Feedback page
β βββ guide/ # User guide page
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Main page
βββ components/ # React components
β βββ ChatInterface.tsx # Main chat interface
β βββ ConversationSidebar.tsx # Conversation management
β βββ LoginForm.tsx # Wallet login form
β βββ MessageBubble.tsx # Individual message display
β βββ FeedbackForm.tsx # User feedback form
β βββ Mascot.tsx # AI mascot component
β βββ WalletsUI/ # Wallet UI components
βββ lib/ # Utility functions
β βββ authService.ts # Authentication service
β βββ chatCache.ts # Chat caching
β βββ database.ts # Firestore operations
β βββ postgres.ts # PostgreSQL operations
β βββ firebase.ts # Firebase configuration
β βββ walletService.ts # Wallet integration
βββ hooks/ # Custom React hooks
βββ types/ # TypeScript definitions
βββ chat.ts # Chat-related types
βββ wallet.ts # Wallet-related types
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm run export-conversations- Export conversations from Firestorenpm run analyze-conversations- Analyze conversation datanpm run test-auth- Test wallet authenticationnpm run create-feedback-table- Create PostgreSQL feedback tablenpm run update-feedback-table- Update PostgreSQL feedback table
- New API Endpoints: Add routes in
src/app/api/ - New Components: Add in
src/components/ - Database Operations: Extend
src/lib/database.ts(Firestore) orsrc/lib/postgres.ts(PostgreSQL) - Wallet Integration: Extend
src/lib/walletService.ts - Types: Update
src/types/files
npm run buildThen deploy to Vercel. The application is pre-configured for serverless deployment.
- Set up Firebase project with Firestore
- Configure PostgreSQL database (optional)
- Set all required environment variables
- Deploy to your preferred platform
The application works on any platform that supports Next.js. Ensure all environment variables are properly configured.
- Proposal Lookup: Fetch proposals or referenda by ID or title
- Filter by Type: Supports ReferendumV2, Treasury, Fellowship, Bounty, ChildBounty
- Filter by Network: Switch between Polkadot and Kusama networks
- Status Filtering: Retrieve proposals by status (Deciding, DecisionDepositPlaced, etc.)
- Date-Based Search: Query by specific dates, months, or years
- Text Search: Search in titles or content
- Voter Information: Retrieve details of individual voters and their activity
- Voting Power: Analyze balance and conviction using conviction_vote data
- Delegation Tracking: Identify delegated votes and delegation relationships
- Vote Decisions: Filter by aye, nay, or abstain
- Conviction Analysis: Analyze lock periods and conviction multipliers
- Top Voters: Rank voters by voting power
This project is licensed under the MIT License.