Architecture
System Overview
Referandium is built on a modern, scalable architecture leveraging the Solana blockchain and Web3 technologies.
Technology Stack
Frontend Layer
βββββββββββββββββββββββββββββββββββββββ
β Next.js 14 App Router β
β ββββββββββββ ββββββββββββββββββββ β
β β React 18 β β Tailwind CSS β β
β ββββββββββββ ββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββ€
β β Solana Wallet Adapter β
β ββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββKey Components:
- Next.js 14: Server-side rendering and routing
- React 18: Component-based UI architecture
- Tailwind CSS: Utility-first styling framework
- TypeScript: Type-safe development
Blockchain Layer
βββββββββββββββββββββββββββββββββββββββ
β Solana Blockchain β
β ββββββββββββββββββββββββββββββββββββ€
β β @solana/web3.js β
β β @solana/wallet-adapter β
β ββββββββββββββββββββββββββββββββββββ
β Mainnet-Beta β
βββββββββββββββββββββββββββββββββββββββIntegration:
- Wallet Connection: Multi-wallet support (Phantom, Solflare, etc.)
- Transaction Signing: Client-side transaction creation
- SOL Transfers: Real-time on-chain payments
Smart Contracts (Anchor Programs)
Deployed on Solana Devnet:
1. Market Escrow Program
Address: Aby8pc1zLWbKUPgPzgh4ntbkTsbPaZWb6FyuxSwtkR8e
Purpose:
- Escrow SOL signals for markets
- Calculate and distribute yield
- Manage user signal accounts
- Automated withdrawal on market close
Key Instructions:
initialize_platform: Setup escrow platformcreate_market: Create new market escrow accountdeposit_signal: Lock SOL for YES/NO signalset_yield: Admin sets yield for distributionclose_market: Close market and enable withdrawalswithdraw: Users claim principal + yield shareadmin_withdraw_buyback: Platform withdraws buyback portion
2. Gookie Auction Program
Address: 3VkzfA6GU6VhMdEnYRJywLLEQ454B9gmQoNh4ycVFFS5
Purpose:
- Manage Gookie NFT auctions
- Lock RFRM tokens for bids
- Mint NFT to winner
- Handle auction lifecycle
Key Instructions:
initialize_platform: Setup auction platformcreate_auction: Create new Gookie auctionplace_bid: Lock RFRM and place bidclose_auction: End auction, determine winnermint_gookie_nft: Mint NFT to auction winner
3. Learning Subscription Program
Address: FUTVzQF86UckN9KhyuRajM4xRsYS62f24hTbJqGkZxed
Purpose:
- Lock RFRM for Learning Hub access
- Verify active subscriptions
- Handle subscription cancellation
- Return locked tokens on cancel
Key Instructions:
initialize_platform: Setup subscription platformsubscribe: Lock RFRM tokens for accesscancel_subscription: Unlock tokens and end accessverify_access: Check if user has active subscription
Token Used:
- RFRM Token:
8248ZQSM717buZAkWFRbsLEcgetSArqbpbkX638Vpump
Database Layer
βββββββββββββββββββββββββββββββββββββββ
β Supabase (PostgreSQL) β
β ββββββββββββββββββββββββββββββββββββ€
β β Markets & Votes β
β β Gookies & Bids β
β β Users & Profiles β
β β Comments & Activity β
β ββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββFeatures:
- Row-Level Security (RLS) policies
- Real-time subscriptions
- Automatic vote aggregation triggers
- Indexed queries for performance
Data Models
Markets System
interface Market {
id: string
question: string
description: string
category: string
market_type: 'binary' | 'multiple_choice'
end_date: Date
yes_pool: number
no_pool: number
total_volume: number
status: 'active' | 'closed' | 'resolved'
}
interface Vote {
id: string
market_id: string
user_wallet: string
vote_direction: 'yes' | 'no'
amount_sol: number
created_at: Date
}Gookies Auction System
interface Gookie {
id: string
title: string
description: string
image_url: string
starting_bid: number
current_highest_bid: number
highest_bidder_wallet: string | null
end_time: Date
status: 'active' | 'closed'
}
interface GookieBid {
id: string
gookie_id: string
user_wallet: string
bid_amount: number
created_at: Date
}Request Flow
Market Voting Flow
User Action
β
1. Connect Wallet (Solana Wallet Adapter)
β
2. Select Market & Vote Direction
β
3. Enter SOL Amount
β
4. Submit Vote (Insert to Supabase)
β
5. Database Trigger Updates Market Stats
β
6. UI Updates with New PercentagesGookies Bidding Flow
User Action
β
1. Connect Wallet
β
2. View Gookie Details
β
3. Enter Bid Amount
β
4. Validate Wallet Balance
β
5. Create SOL Transfer Transaction
β
6. Sign & Send to Blockchain
β
7. Wait for Confirmation
β
8. Insert Bid Record to Supabase
β
9. Update Highest Bid if Applicable
β
10. Real-time UI UpdateSecurity Architecture
Wallet Security
- Client-Side Signing: Private keys never leave user's wallet
- Transaction Verification: All transactions verified on Solana network
- No Custody: Platform never holds user funds
Database Security
- Row-Level Security: User data protected with Supabase RLS
- Read-Only Public Access: Markets and auctions publicly readable
- Authenticated Writes: Votes and bids require wallet signature
- SQL Injection Prevention: Parameterized queries via Supabase client
API Security
- CORS Configuration: Restricted origins
- Rate Limiting: Protection against spam (planned)
- Input Validation: All user inputs sanitized
Performance Optimizations
Frontend
- Server-Side Rendering: Fast initial page loads
- Image Optimization: Next.js automatic image optimization
- Code Splitting: Lazy loading for unused code
- Caching: Strategic use of React Query for data caching
Database
- Indexed Queries: All foreign keys and frequently queried fields indexed
- Materialized Views: Pre-computed statistics (planned)
- Connection Pooling: Efficient database connection management
Blockchain
- Transaction Batching: Group multiple operations when possible
- Optimized RPC Calls: Minimize on-chain queries
- Local State Management: Cache wallet balance and transaction status
Deployment Architecture
βββββββββββββββββββββββββββββββββββββββ
β Vercel Edge Network β
β ββββββββββββββββββββββββββββββββββββ€
β β Next.js Application β
β β Static Assets (CDN) β
β ββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ
β Supabase Cloud β
β PostgreSQL Database + Realtime β
βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββ
β Solana Mainnet-Beta β
β RPC Nodes + Blockchain State β
βββββββββββββββββββββββββββββββββββββββMonitoring & Analytics
Application Monitoring
- Error Tracking: Real-time error logging
- Performance Metrics: Page load times and Core Web Vitals
- User Analytics: Anonymized usage patterns
Blockchain Monitoring
- Transaction Status: Real-time tx confirmation tracking
- Network Health: Monitor Solana RPC availability
- Gas Optimization: Track and optimize SOL transaction costs
Future Enhancements
Scalability
- Redis caching layer
- GraphQL API for complex queries
- Microservices architecture for high-traffic features
Features
- WebSocket real-time updates
- Advanced charting with historical data
- Mobile app (React Native)
- Multi-language support
Architecture is continuously evolving to meet platform needs.