Technical Reference & Protocols

Specifications & schemas

Formal definitions of WireChat's JSON payload protocol, SQLite database tables, and customizable configuration properties.

WebSocket JSON Protocol

A detailed mapping of every packet type sent back and forth between client and server.

AUTH

Authentication Packets

Clients must authenticate before sending chat messages or performing commands.

Client Login Request
{
  "type": "login",
  "username": "alice",
  "password": "secret"
}
Server Auth Success Response
{
  "type": "auth_success",
  "username": "alice"
}
CHAT

Messaging Packets

Used for client messaging inside channels and private Direct Messages (DMs).

Client Chat Message
{
  "type": "message",
  "content": "Hello tech room!"
}
Server Chat Broadcast
{
  "type": "message",
  "username": "alice",
  "room": "tech",
  "content": "Hello tech room!",
  "timestamp": 1715901243100
}
DATA

Metadata & Query Packets

Emitted in response to command queries like `/rooms` or `/history`.

Server Room List Response
{
  "type": "rooms_list",
  "rooms": [
    {
      "name": "general",
      "description": "General",
      "users": 4
    }
  ]
}
Server Chat History Response
{
  "type": "history",
  "messages": [
    {
      "username": "alice",
      "room": "tech",
      "content": "Hey there",
      "timestamp": 1715901243000
    }
  ]
}

SQLite Database Schema

Structure of the database tables created automatically in chat.db.

SQL Table Definitions

-- Table: users (Stores user account credentials)
CREATE TABLE IF NOT EXISTS users (
  username TEXT PRIMARY KEY,
  password TEXT -- Argon2id secure hash
);

-- Table: messages (Stores chat room histories)
CREATE TABLE IF NOT EXISTS messages (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  room TEXT,
  sender TEXT,
  content TEXT,
  timestamp INTEGER -- Unix Epoch milliseconds
);

Configuration Guide

WireChat utilizes a centralized configuration file at shared/config.js. Modify settings there to adjust network, database, validation rules, or default limits globally.

Setting / Variable config.js Key Description
Port network.port Sets the listening port for the WebSocket server and the target port for TUI clients (default: 5051).
Host network.host Sets the listening address and connection target host (default: 127.0.0.1).
Database Path database.filename The SQLite filename located in the root of the project workspace (default: chat.db).
Default Room defaults.defaultRoom The auto-joined chat room upon successful login (default: general).
History Limit defaults.historyLimit The default message count returned by /history (default: 50).
Validation Constraints validation Globally configures username limits (min/max length) and message character bounds (default: 500 chars).