Explore step-by-step messaging flows, WebSocket packet payloads, CLI outputs, and SQLite database schemas.
How a new user registers, hashes passwords via argon2, and logs in securely.
The user issues the registration command from the input box. The client validates it and pushes a registration packet.
// Inside the TUI Client input field
/register alice supersecurepassword
The server receives a register JSON packet, generates a secure argon2 hash, and saves it in the SQLite database.
{
"type": "register",
"username": "alice",
"password": "supersecurepassword"
}
SELECT * FROM users;
┌──────────┬──────────────────────────────┐
│ username │ password (Argon2 Hash) │
├──────────┼──────────────────────────────┤
│ alice │ $argon2id$v=19$m=65536,t=3...│
└──────────┴──────────────────────────────┘
Once registered, the user logs in. The server verifies the password, maps the user to the websocket connection, and auto-joins the user to the general chat room.
How rooms are created dynamically and how messages are broadcast in real time.
A user can spin up a custom room at runtime with an optional description using /create-room.
/create-room tech "Technical discussions and logs"
{
"type": "command",
"command": "create-room",
"name": "tech",
"description": "Technical discussions"
}
{
"type": "system",
"content": "Room 'tech' created/updated."
}
Switching rooms leaves the previous room, joins the new one, and notifies other room members in real time.
/join tech
Sending peer-to-peer messages privately over the network.
A user types a DM using /dm <target> <msg>. The server finds the socket connected to the target and routes the message exclusively to them.
/dm bob Hey bob, did you check the SQLite logs?
The server intercept matches the target "bob" against the active users list and emits a private `dm` packet.
{
"type": "command",
"command": "dm",
"target": "bob",
"content": "Hey bob, check logs."
}
{
"type": "dm",
"from": "alice",
"content": "Hey bob, check logs.",
"timestamp": 1715901243100
}
Bob receives the DM, styled in magenta to clearly distinguish it from public room messages.
SQLite backed persistent logs showing chronologically sorted historical messages.
Users who join a room or need context can pull historical messages using `/history` with a custom limit.
/history 3
The server runs a SQL query on chat.db, formats the records, and replies with a history collection.
SELECT sender, content, timestamp
FROM messages
WHERE room = 'tech'
ORDER BY timestamp DESC
LIMIT 3;
{
"type": "history",
"messages": [
{"username":"bob","content":"test"...},
{"username":"alice","content":"hi"...}
]
}
The TUI client reverses the fetched array so history prints in order (oldest to newest), flanked by gray boundary markers.