This section provides a comprehensive overview of CycleStark's system architecture, including the smart contracts, frontend application, and blockchain infrastructure.
CycleStark is built as a decentralized application (dApp) with three main components:
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Frontend โ โ Smart โ โ Blockchain โ
โ Application โโโโโบโ Contracts โโโโโบโ Infrastructure โ
โ (React) โ โ (Cairo) โ โ (Madara) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
- Location:
/contract/src/ - Language: Cairo 2.0
- Network: Starknet
- Purpose: Core business logic and state management
- Location:
/frontend/src/ - Framework: React 18 + TypeScript
- UI Library: Mantine 7
- Purpose: User interface and interaction layer
- Location:
/madara-app-chain-template/ - Framework: Madara (Starknet-compatible)
- Language: Rust
- Purpose: Local development and testing environment
User Action โ Frontend โ Wallet โ Smart Contract โ Blockchain
โ โ
โโโโโโโโโโโโโโโโ State Update โ Events โโโโโโโโโโโโโโโโ
- User Interaction: User performs action in frontend
- Transaction Creation: Frontend creates transaction data
- Wallet Signing: User approves transaction in wallet
- Contract Execution: Smart contract processes the action
- State Update: Blockchain state is updated
- Event Emission: Contract emits events
- UI Update: Frontend updates based on new state
CycleStark.sol (Main Contract)
โโโ Storage
โ โโโ stark_heroes: Map<HeroID, StarkHero>
โ โโโ stark_collectives: Map<CollectiveID, StarkCollective>
โ โโโ collective_cycles: Map<(CollectiveID, u32), CollectiveCycle>
โ โโโ cycle_contributions: Map<(CollectiveID, CycleID, u32), CycleContribution>
โโโ Interfaces
โ โโโ ICycleStark: Main contract interface
โ โโโ IHelperFunctions: Helper functions interface
โโโ Events
โโโ Hero: Hero registration events
โโโ Collective: Collective creation events
โโโ Cycle: Cycle management events
โโโ Contribute: Contribution events
struct StarkHero {
id: ContractAddress,
escrow: u256,
is_active: bool,
collectives_count: u32,
}struct StarkCollective {
id: CollectiveID,
name: felt252,
rule_1: felt252,
rule_2: felt252,
rule_3: felt252,
hero_count: u32,
cycle_amount: u256,
fine: u256,
cycles_count: u32,
token: TokenAddress,
start_date: u64,
owner: HeroID,
active_cycle: u32,
has_started: bool,
has_ended: bool,
current_hero: HeroID,
next_hero: HeroID,
aim: felt252,
decimals: u32,
symbol: felt252,
}App.tsx
โโโ MainLayout
โ โโโ TopBarNavigation
โ โ โโโ ConnectWalletBtn
โ โ โโโ CustomNavLink
โ โโโ CustomAppShell
โโโ Pages
โ โโโ Home
โ โโโ Collectives
โ โโโ CreateCollective
โ โโโ SingleCollective
โ โ โโโ Heroes
โ โ โโโ Cycles
โ โ โโโ CollectiveInfo
โ โ โโโ Chat
โ โโโ MyCollectives
โโโ Providers
โโโ AppProvider
โโโ CollectiveProvider
- React Context: For global state management
- Local State: Component-specific state
- Contract State: Real-time blockchain state
- Wallet State: Connection and account information
- StarknetKit: Wallet integration
- Mantine: UI components and theming
- React Router: Navigation
- Firebase: Chat functionality
Madara provides a Starknet-compatible development environment with:
- Full RPC Compatibility: Works with all Starknet tooling
- Customizable Parameters: Adjustable transaction fees, step limits
- Local Development: Fast iteration and testing
- Genesis Configuration: Pre-configured accounts and contracts
# Development Network
url = "http://localhost:5050/rpc"
# Testnet Configuration
url = "https://starknet-goerli.infura.io/v3/YOUR_KEY"
# Mainnet Configuration
url = "https://starknet-mainnet.infura.io/v3/YOUR_KEY"- Access Control: Owner-only functions for critical operations
- Input Validation: Comprehensive parameter checking
- Reentrancy Protection: Safe external calls
- State Consistency: Atomic operations
- Event Logging: Complete audit trail
- Wallet Integration: Secure wallet connection
- Transaction Validation: Client-side validation
- Error Handling: Graceful error management
- Input Sanitization: XSS prevention
- HTTPS: Secure communication
- RPC Security: Authenticated API endpoints
- Rate Limiting: DDoS protection
- Monitoring: Real-time security monitoring
- Gas Efficiency: Optimized Cairo code
- Storage Optimization: Efficient data structures
- Batch Operations: Multiple operations in single transaction
- Event Optimization: Minimal event data
- Lazy Loading: Component and route lazy loading
- Caching: API response caching
- Optimization: Bundle size optimization
- CDN: Static asset delivery
- Layer 2: Starknet's L2 scaling
- Batching: Transaction batching
- Caching: RPC response caching
- Load Balancing: Multiple RPC endpoints
- Start Madara: Local blockchain
- Deploy Contracts: Deploy to local network
- Start Frontend: Development server
- Connect Wallet: Connect to local network
- Test: Full integration testing
- Unit Tests: Individual component testing
- Integration Tests: Contract interaction testing
- E2E Tests: Full user flow testing
- Security Tests: Vulnerability assessment
- Contract Deployment: Deploy to testnet/mainnet
- Frontend Build: Production build
- Environment Configuration: Set environment variables
- Deployment: Deploy to hosting platform
- Verification: Post-deployment verification
- Multiple RPC Endpoints: Load balancing
- CDN: Global content delivery
- Database Sharding: Data distribution
- Microservices: Service decomposition
- Contract Optimization: Gas efficiency
- Frontend Optimization: Performance improvements
- Infrastructure Upgrades: Hardware improvements
- Layer 3 Solutions: Additional scaling
- Cross-Chain Integration: Multi-chain support
- Advanced Analytics: Real-time analytics
- Mobile App: Native mobile application
- API Gateway: Public API access
- Cairo 2.0: Latest language features
- Starknet 2.0: Protocol upgrades
- Advanced UI: Enhanced user experience
- AI Integration: Smart recommendations
- Smart Contract Architecture - Detailed contract design
- Frontend Architecture - Frontend system design
- Blockchain Infrastructure - Infrastructure details
- API Reference - Interface documentation