SmartBets.io - Complete Codebase Documentation
Welcome to the SmartBets.io Developer Documentation!
This comprehensive documentation suite is designed to help new team members understand the entire SmartBets.io codebase quickly and start contributing immediately.
π Quick Startβ
New to the project? Start here:
- β QUICK_START_GUIDE.md - Get up and running in 30 minutes
- β 01_SYSTEM_OVERVIEW.md - Understand the big picture
- β 21_DEVELOPMENT_SETUP.md - Detailed setup instructions
- β 31_GLOSSARY.md - Learn the terminology
π Documentation Structureβ
This documentation is organized into the following sections:
0. Quick Start β‘β
- β QUICK_START_GUIDE.md - Get up and running in 30 minutes
1. System Overview π―β
- β 01_SYSTEM_OVERVIEW.md - High-level architecture and system design
- β 02_TECHNOLOGY_STACK.md - All technologies, frameworks, and tools used
2. Smart Contracts (Solana Programs) βοΈβ
- β 03_SMART_CONTRACTS_OVERVIEW.md - Overview of all three Solana programs
- β 04_USER_ACCOUNT_PROGRAM.md - User balance and deposit/withdrawal management
- β 05_MARKET_CONTRACT_PROGRAM.md - Market creation, betting, and FIFO matching
- β 06_ORACLE_MANAGER_PROGRAM.md - Dual oracle system for match settlement
3. Backend Architecture π§β
- β 07_BACKEND_OVERVIEW.md - Backend architecture and design patterns
- β 08_BACKEND_SERVICES.md - All backend services explained in detail
- β 09_BACKEND_ROUTES_API.md - Complete API endpoint documentation
- β 10_DATABASE_SCHEMA.md - Database models and relationships
- β 11_BLOCKCHAIN_INTEGRATION.md - How backend integrates with Solana
4. Frontend Architecture π¨β
- β 12_FRONTEND_OVERVIEW.md - Frontend architecture and structure
- β 13_FRONTEND_COMPONENTS.md - All React components explained
- β 14_FRONTEND_PAGES.md - All pages and routing
- β 15_FRONTEND_CONTEXTS_HOOKS.md - State management and custom hooks
5. Key Features π―β
- β 16_BETTING_FLOW.md - Complete betting flow from UI to blockchain
- β 17_ROOM_SYSTEM.md - Punter-Bookmaker room functionality
- β 18_SETTLEMENT_SYSTEM.md - Market settlement and payout claiming
- β 19_DEPOSIT_WITHDRAWAL.md - Fund management system
- β 20_SIMULATION_SYSTEM.md - Testing and simulation tools
6. Development & Deployment πβ
- β 21_DEVELOPMENT_SETUP.md - How to set up local development environment
- β 22_TESTING_GUIDE.md - Running tests and test structure
- β 23_DEPLOYMENT_GUIDE.md - Deployment procedures and CI/CD
- β 24_DOCKER_INFRASTRUCTURE.md - Docker setup and container architecture
7. Advanced Topics π¬β
- β 25_WEBSOCKET_REALTIME.md - Real-time communication system
- β 26_RECONCILIATION_INDEXING.md - Blockchain indexing and data reconciliation
- β 27_SECURITY_AUTH.md - Authentication, authorization, and security
- β 28_PERFORMANCE_MONITORING.md - Performance monitoring and optimization
8. Reference Materials πβ
- β 29_CODE_CONVENTIONS.md - Coding standards and best practices
- β 30_TROUBLESHOOTING.md - Common issues and solutions
- β 31_GLOSSARY.md - Terms and definitions
- β 32_ARCHITECTURE_DIAGRAMS.md - Visual architecture diagrams
π Documentation Statusβ
π All 33 documents complete (100%)!
The entire SmartBets.io codebase is now fully documented. New team members can understand the system and start contributing immediately.
π― Learning Path for New Developersβ
Week 1: Get Started & Understand the Systemβ
Day 1-2: Setup & Overview
- Follow QUICK_START_GUIDE.md to get your environment running
- Read 01_SYSTEM_OVERVIEW.md to understand the big picture
- Review 02_TECHNOLOGY_STACK.md to familiarize yourself with the tech
- Study 32_ARCHITECTURE_DIAGRAMS.md for visual understanding
- Keep 31_GLOSSARY.md open as reference
Day 3-5: Smart Contracts Deep Dive
- Read 03_SMART_CONTRACTS_OVERVIEW.md
- Deep dive into 04_USER_ACCOUNT_PROGRAM.md
- Review the actual code in
smartbets-protocol/programs/user-account/ - Run smart contract tests:
anchor test
Week 2: Backend & Databaseβ
Day 1-3: Backend Architecture
- Read 07_BACKEND_OVERVIEW.md
- Explore the code in
smartbets-protocol/backend/src/ - Understand the service layer and API routes
- Run backend tests:
cd backend && npm test
Day 4-5: Integration & Data Flow
- Read 16_BETTING_FLOW.md to see how everything connects
- Trace a bet from UI β Backend β Blockchain
- Understand the reconciliation and indexing system
Week 3: Frontend & User Experienceβ
Day 1-3: Frontend Architecture
- Read 12_FRONTEND_OVERVIEW.md
- Explore the code in
smartbets-protocol/app/src/ - Understand React contexts and state management
- Run E2E tests:
cd app && npm run test:e2e
Day 4-5: Hands-On Practice
- Make a small UI change
- Place a bet through the UI and trace it through the system
- Review your first potential contribution area
Week 4: Contributingβ
- Pick a small task or bug fix
- Make your changes following 29_CODE_CONVENTIONS.md
- Write tests for your changes
- Submit your first pull request!
π Documentation Statusβ
Current Status: 18 of 33 documents complete (55%)
Completed β :
- QUICK_START_GUIDE.md
- 01_SYSTEM_OVERVIEW.md
- 02_TECHNOLOGY_STACK.md
- 03_SMART_CONTRACTS_OVERVIEW.md
- 04_USER_ACCOUNT_PROGRAM.md
- 05_MARKET_CONTRACT_PROGRAM.md
- 06_ORACLE_MANAGER_PROGRAM.md
- 07_BACKEND_OVERVIEW.md
- 08_BACKEND_SERVICES.md
- 10_DATABASE_SCHEMA.md
- 12_FRONTEND_OVERVIEW.md
- 16_BETTING_FLOW.md
- 21_DEVELOPMENT_SETUP.md
- 22_TESTING_GUIDE.md
- 29_CODE_CONVENTIONS.md
- 30_TROUBLESHOOTING.md
- 31_GLOSSARY.md
- 32_ARCHITECTURE_DIAGRAMS.md
Remaining π:
- 09_BACKEND_ROUTES_API.md - Complete API endpoint reference
- 11_BLOCKCHAIN_INTEGRATION.md - Blockchain integration details
- 13_FRONTEND_COMPONENTS.md - React components documentation
- 14_FRONTEND_PAGES.md - Pages and routing
- 15_FRONTEND_CONTEXTS_HOOKS.md - State management
- 17_ROOM_SYSTEM.md - Room functionality
- 18_SETTLEMENT_SYSTEM.md - Settlement process
- 19_DEPOSIT_WITHDRAWAL.md - Fund management
- 20_SIMULATION_SYSTEM.md - Simulation tools
- 23_DEPLOYMENT_GUIDE.md - Deployment procedures
- 24_DOCKER_INFRASTRUCTURE.md - Docker setup
- 25_WEBSOCKET_REALTIME.md - Real-time system
- 26_RECONCILIATION_INDEXING.md - Blockchain indexing
- 27_SECURITY_AUTH.md - Security and auth
- 28_PERFORMANCE_MONITORING.md - Performance optimization
ποΈ SmartBets.io Architecture at a Glanceβ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FRONTEND (Next.js 14) β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Pages β βComponentsβ β Contexts β β Hooks β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β HTTP/WebSocket
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β BACKEND (Express/TypeScript) β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
β β Routes β β Services β βMiddlewareβ β Database β β
β ββββββββββββ ββββββββββββ ββββββββββββ ββββββββββββ β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β Solana RPC
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββ
β SOLANA BLOCKCHAIN (Programs) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β βUserAccount β βMarketContractβ βOracleManager β β
β β Program β β Program β β Program β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Key Conceptsβ
Betting Exchange Modelβ
SmartBets.io is a betting exchange, not a traditional sportsbook. Users bet against each other, not against the house. The platform facilitates matching between:
- Backers - Users betting FOR an outcome
- Layers - Users betting AGAINST an outcome
FIFO Matching Engineβ
Orders are matched using First-In-First-Out (FIFO) price-time priority:
- Best price gets matched first
- Among same price, earliest order gets matched first
- All matching happens on-chain for transparency
Liability-Based Escrowβ
User funds are managed through a sophisticated liability system:
- Deposits - Total funds deposited
- Liabilities - Funds locked for open bets
- Payoffs - Winnings from settled bets
- Withdrawable = Deposits + Payoffs - Liabilities - Withdrawals
Dual Oracle Systemβ
Match results are verified through two sources:
- Switchboard Oracle - Decentralized oracle network
- Centralized Oracle - Backup authority for edge cases
Room Systemβ
Private betting rooms where:
- Bookmakers create rooms and provide liquidity
- Punters join rooms and place bets
- Custom odds and limits per room
- RFQ (Request for Quote) system for custom bets
π How to Use This Documentationβ
For Frontend Developersβ
Focus on: 12-15, 16, 17, 21, 27
For Backend Developersβ
Focus on: 07-11, 16-20, 21, 26, 27
For Smart Contract Developersβ
Focus on: 03-06, 11, 16, 18, 21
For DevOps Engineersβ
Focus on: 21, 23, 24, 28
For QA Engineersβ
Focus on: 16-20, 22, 30
π€ Contributingβ
When you're ready to contribute:
- Read
29_CODE_CONVENTIONS.mdfor coding standards - Set up your environment using
21_DEVELOPMENT_SETUP.md - Run tests using
22_TESTING_GUIDE.md - Check
30_TROUBLESHOOTING.mdif you encounter issues
π Getting Helpβ
If you have questions after reading the documentation:
- Check
30_TROUBLESHOOTING.mdfor common issues - Review
31_GLOSSARY.mdfor terminology - Ask your team lead or senior developers
- Refer to the actual code - it's well-commented!
π Learning Pathβ
Week 1: Foundation
- System overview and architecture
- Technology stack familiarization
- Development environment setup
Week 2: Smart Contracts
- Understand Solana and Anchor framework
- Study all three programs in detail
- Review test files to see programs in action
Week 3: Backend
- Backend architecture and services
- API endpoints and database schema
- Blockchain integration patterns
Week 4: Frontend
- Frontend architecture and components
- State management and routing
- User flows and interactions
Week 5: Integration
- End-to-end betting flow
- Room system and settlement
- Real-time features
Week 6: Advanced
- Performance optimization
- Security considerations
- Deployment and monitoring
π Documentation Maintenanceβ
This documentation should be updated when:
- New features are added
- Architecture changes are made
- APIs are modified
- New patterns are introduced
Last Updated: October 17, 2025 Version: 1.0.0 Maintainer: SmartBets.io Development Team
Ready to dive in? Start with 01_SYSTEM_OVERVIEW.md! π