Bidirectional Real-Time Dataflow

Clients send edit operations and AI assist requests to a FastAPI WebSocket server, which manages connections per document. The server broadcasts changes bidirectionally: user edits sync instantly across all participants, while Claude's streaming API delivers response tokens one delta at a time to every connected client. This setup supports concurrent editing by multiple users without a central text authority, enabling seamless collaboration where one user types while the AI responds for all.

Conflict-Free Sync with Per-Document CRDT

Use a lightweight CRDT (Conflict-Free Replicated Data Type) scoped to each document to merge concurrent text edits from multiple users without coordination or conflicts. Clients apply operations locally and send them to the server, which replicates the merged state back—ensuring everyone sees the same document version instantly, even during high concurrency.

Streaming AI Responses and Per-User Limits

Integrate Claude's streaming API on the server to generate AI-assisted writing, fanning out each token delta via WebSockets to all room participants as it arrives. Prevent abuse with a token-bucket rate limiter per user, enforcing individual rate limits and cost ceilings so one user's heavy usage doesn't disrupt the shared session. This minimal stack—WebSockets, CRDT, streaming, rate limiting—scales to production without exotic dependencies.