Skip to main content

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

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:
  1. Schema Definitions: Zod schemas for type safety
  2. Event Handlers: Reactive event processing
  3. State Management: Materializers for UI state
  4. Error Handling: Graceful error recovery
  5. 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

Check that the server is running and accessible:
Ensure your event data matches the schema:
Remove event listeners when components unmount:

Next Steps

Chat Application

Build a real-time chat application

Todo Sync

Create a collaborative todo list

AI Streaming

Implement AI chat with streaming

Multiplayer Game

Build a real-time multiplayer game