Getting Started with Dialogue
This guide covers installation, basic setup, and your first real-time application using Dialogue.
1. Overview
Dialogue is an event-based realtime communication library built on Socket.IO and Hono. It supports both Bun and Node.js runtimes, auto-detecting which to use. It provides a simple, type-safe API for building real-time applications like chat, notifications, live dashboards, multiplayer games, and IoT systems.
1.1 Key Features
- Config-first with dynamic rooms: Define common rooms upfront, create others at runtime
- Event-centric: Events are first-class citizens with optional Zod schema validation
- Type-safe: Full TypeScript support with inferred types from schemas
- Bounded rooms: Optional
maxSizefor predictable scaling - Unified mental model: Backend and frontend share similar APIs
2. Installation
Install Dialogue and zod:
:::tabs
@tab Bun
@tab npm
@tab pnpm
:::
Dialogue supports both Bun and Node.js runtimes. The runtime is auto-detected by default, or you can set it explicitly via the runtime config option.
3. Quick Start
3.1 Define Events
Create a configuration file to define your events and rooms:
Dynamic Room Creation
While config-first is recommended, you can also create rooms dynamically at runtime:
Recommendation: Use predefined rooms for ~80% of your use cases (known room types), and dynamic creation for ~20% (user-generated content, temporary sessions).
3.2 Start the Server
Run with Bun:
Or with Node.js (using tsx or ts-node):
Dialogue auto-detects the runtime. To set it explicitly, pass runtime: "bun" or runtime: "node" in your createDialogue() config. See the Configuration Guide for details.
3.3 Trigger Events from Backend
You can trigger events from anywhere in your backend code:
3.4 Connect from Frontend
4. Project Structure
Here's the recommended structure for a Dialogue application:
This is a minimal, focused view showing only application code. The Dialogue library itself is installed as dependencies and doesn't appear in your project structure.
5. Next Steps
- Read the Configuration Guide for detailed configuration options
- Explore the Backend API for server-side features
- Learn about the Client API for frontend integration
- See Examples for complete use-case implementations
This documentation reflects the current implementation and is subject to evolution. Contributions and feedback are welcome.