Back to Rivet

Chat Room (Effect)

examples/chat-room-effect/README.md

2.3.22.9 KB
Original Source

Chat Room (Effect)

Example project demonstrating a real-time chat room built with the Effect SDK for Rivet Actors.

Getting Started

sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/chat-room-effect
npm install
npm run dev

In a separate terminal, run a client against the server:

sh
npm run client      # Effect client
npm run client:raw  # plain RivetKit client

Features

  • Effect-native actors: Define actors with Actor.make and implement them with toLayer, composing actor logic from Effect Layers and services
  • Typed action protocols: Actions are standalone Action.make values with effect/Schema payloads, successes, and errors validated end to end
  • Typed domain errors: MemberNotInRoomError and BannedWordsError flow through the action error channel and are caught by tag on the client
  • Actor-to-actor RPC: The ChatRoom actor calls a separate Moderator actor to screen messages, using the same client API as client-to-actor calls
  • Persistent state and SQLite: Room membership lives in persisted actor state while message history is stored in the actor's SQLite database
  • Scheduling: A welcome message is scheduled after a member joins and dispatched back through the actor's own action

Implementation

The example splits each actor into a public contract and a server-only implementation:

Resources

Read more about actions, state, events, and the Effect quickstart.

License

MIT