Overview
This section provides practical examples demonstrating how to use kSync in real-world applications. Each example includes complete, runnable code with explanations.Chat Application
Real-time chat with typing indicators and presence
Todo Sync
Collaborative todo list with offline support
AI Streaming
AI chat with streaming responses and presence
Multiplayer Game
Real-time multiplayer game with 100+ players
Running Examples
All examples are included in the kSync repository and can be run locally:Prerequisites
Basic Examples
- Chat App
- Sync Demo
- AI Streaming
Next.js Game Example
Example Categories
🚀 Getting Started
Perfect for beginners learning kSync fundamentals:- Basic Chat: Simple message sending and receiving
- Schema Validation: Type-safe event handling
- Local Storage: Offline-first development
- Event Listeners: Reactive UI updates
🔄 Real-Time Sync
Examples demonstrating multi-client synchronization:- Todo Sync: Collaborative task management
- Presence Tracking: User online/offline status
- Conflict Resolution: Handling concurrent edits
- Connection Management: Reconnection and error handling
🤖 AI Integration
AI-powered applications with streaming:- Streaming Chat: Word-by-word AI responses
- Presence Updates: Real-time typing indicators
- Error Handling: Graceful failure management
- Performance: Efficient streaming protocols
🎮 Advanced Use Cases
Complex applications showcasing kSync’s capabilities:- Multiplayer Games: 100+ concurrent players
- Real-Time Collaboration: Document editing
- IoT Dashboards: Sensor data streaming
- Financial Trading: Real-time price updates
Code Structure
Each example follows a consistent structure:Example Template
Each example includes:- Schema Definitions: Zod schemas for type safety
- Event Handlers: Reactive event processing
- State Management: Materializers for UI state
- Error Handling: Graceful error recovery
- Performance: Optimizations and best practices
Interactive Demos
Try these examples in your browser:Live Chat Demo
Real-time chat application with multiple users
Todo Sync Demo
Collaborative todo list with offline support
Game Demo
Multiplayer game with real-time movement
AI Chat Demo
AI chat with streaming responses
Learning Path
Follow this recommended learning path:1. Start with Basics
2. Add Real-Time Sync
3. Implement State Management
4. Add Advanced Features
Common Patterns
Event-Driven Architecture
Optimistic Updates
Offline Support
Performance Tips
Event Batching
Memory Management
Connection Efficiency
Troubleshooting
Common Issues
Events not syncing
Events not syncing
Check that the server is running and accessible:
Schema validation errors
Schema validation errors
Ensure your event data matches the schema:
Memory leaks
Memory leaks
Remove event listeners when components unmount:

