Anda
A chat app similar to Discord, built without a web framework: a threaded TLS server, a terminal client, and a JSON line protocol carrying logins, rooms, direct messages and heartbeats.
Overview
Anda is a chat which works with sockerts. The server keeps one reader per connection and one writer thread per client fed by an outbox queue, so two messages can never interleave on the wire. Accounts, tokens and messages live in SQLite; TLS is pinned to a single certificate that the project issues itself instead of a public CA.
client --TLS--> server
reader thread -> parse JSON line
outbox + writer -> one writer per client, no interleaving
heartbeat -> ping / pong / missed ping disconnect
SQLite -> users, tokens, messages
Key features
- Pinned TLSThe client trusts only the project's own certificate, with no CA bundle and no hostname check.
- Passwords + lockoutbcrypt hashes and a sliding window of failed attempts that locks the account.
- Hashed session tokensOnly a SHA-256 fingerprint is stored; the saved login file is 0600 in a 0700 folder.
- Session takeoverA newer login for an account closes the older connection instead of leaving two live.
- HeartbeatsPing/pong with missed ping disconnect and login reply timeouts, so dead links do not hang.
- Rooms + DMsPublic history and per user direct messages from SQLite, with
@mentions.
How it works
- Generate the certificate and key that the server and client share.
- Start
server.py. - Start one or more clients and register or log in.
- Chat in the room or send a direct message; the session token is saved for next time.
python server.py
python client.py
# config.py holds host, port, cert paths and heartbeat timings
# session file lives outside the project, under ~/.config/anda/
Stack
Python 3.13
socket
ssl / TLS
SQLite
bcrypt
threading
queue