Getting Started

Introduction

What is IOServer and when should you use it?

Introduction

IOServer is a TypeScript framework for building real-time backends. It wraps Fastify (HTTP) and Socket.IO (WebSocket) behind a structured component model that encourages clear separation of concerns.

What it does

  • Combines HTTP and WebSocket in a single server instance
  • Provides five component types — Services, Controllers, Managers, Watchers, and Middlewares — each with a well-defined role
  • Wires components together through a typed AppHandle that gives every component access to shared state (managers) and the send / log utilities
  • Auto-discovers WebSocket event handlers from public methods on Services
  • Maps HTTP routes to Controller methods via JSON route files
  • Ships with production-ready defaults: CORS, sensible error responses, optional SPA fallback

What it does NOT do

  • It does not prescribe your storage layer — bring your own database manager
  • It does not replace Socket.IO or Fastify — you get the full power of both, exposed via appHandle.send and this.appHandle in controllers

Component model at a glance

┌──────────────────────────────────────────────────────────────┐
│                         IOServer                             │
│                                                              │
│   ┌───────────┐   ┌────────────┐   ┌──────────────────────┐ │
│   │  Manager  │   │  Manager   │   │  …                   │ │
│   │ (shared)  │   │ (shared)   │   │                      │ │
│   └─────┬─────┘   └─────┬──────┘   └──────────────────────┘ │
│         │               │                                    │
│         └───────────────┴──── AppHandle ────────────────┐   │
│                                                         │   │
│   ┌──────────────────────┐   ┌──────────────────────┐   │   │
│   │       Service        │   │     Controller       │   │   │
│   │  (WebSocket events)  │   │   (HTTP routes)      │◄──┘   │
│   └──────────────────────┘   └──────────────────────┘       │
│                                                              │
│   ┌──────────────────────┐   ┌──────────────────────┐       │
│   │       Watcher        │   │     Middleware        │       │
│   │  (background tasks)  │   │  (HTTP / WS hooks)   │       │
│   └──────────────────────┘   └──────────────────────┘       │
└──────────────────────────────────────────────────────────────┘
ComponentTransportPurpose
ServiceWebSocketHandles Socket.IO events (one method = one event)
ControllerHTTPHandles Fastify routes (declared in JSON files)
ManagerShared singleton available to all other components
WatcherLong-running background tasks (intervals, polling)
MiddlewareBothRequest/namespace guards, token validation, logging

Technology stack

LayerLibraryVersion
HTTP serverFastifyv5
WebSocketSocket.IOv4
CORS@fastify/corsv10
Static files@fastify/staticv9
LanguageTypeScript≥ 5.0
RuntimeNode.js≥ 18
Copyright © 2026