$ cd projects/termchat

termchat

A TeamSpeak-style, channel-based chat: a threaded TCP server backed by SQLite, with a terminal UI, a Tkinter desktop app and a browser client sharing the same channels in real time.

stack
Python, rich, Tkinter, SQLite, WebSocket
repo
github.com/M0rPh39s/termchat ↗
+--------------+--------------------------------------+
|  CHANNELS    |  #general                            |
|  > # general |  [12:00:01] alice: hello everyone    |
|    # random  |  [12:00:12] bob:   hi alice          |
|    # help    |                                      |
|              |                                      |
|  ONLINE (2)  |                                      |
|  * alice     |                                      |
|  * bob       +--------------------------------------+
|              |  > type a message and press Enter    |
+--------------+--------------------------------------+

What it does

  • Accounts. Register and log in; passwords are hashed with PBKDF2-HMAC-SHA256 and a per-user salt. One account, one session at a time.
  • Channels. Ships with #general, #random and #help; create more on the fly.
  • Real time. Messages broadcast instantly to everyone in the channel, the online list updates live, and dropped connections are cleaned up for everyone else.
  • History. Everything is persisted in SQLite; the last 50 messages load when you open a channel.

Three clients, one server

  • Terminal UI built on rich: channel sidebar, online users, per-user colours, keyboard navigation. Needs a Linux/macOS terminal.
  • Desktop GUI in Tkinter. It can host the server itself and packages into a standalone TermChat.exe for Windows, with no Python needed on the target.
  • Browser client, a mobile-friendly web UI served by the same server over HTTP/WebSocket — a fourth transport into the same channels, not a separate chat.

How it’s built

Clients talk to a threaded server (one thread per connection, shared state behind a lock) over TCP using 4-byte length-prefixed JSON frames. The WebSocket handshake and framing (RFC 6455) are implemented on the standard library, so the only third-party dependency is rich, and only for the terminal client.

Component File
Wire protocol termchat/protocol.py
Database termchat/database.py
Server termchat/server.py
TUI client termchat/client.py
GUI client termchat/gui.py
WebSocket framing termchat/ws.py
Browser client termchat/web.py

Running it

git clone https://github.com/M0rPh39s/termchat.git && cd termchat
pip install -r requirements.txt

python run_server.py --host 0.0.0.0 --port 9009 --web-port 8080
python run_client.py --host 127.0.0.1 --port 9009   # or: python run_gui.py

Traffic is plain TCP / HTTP — put it behind a TLS reverse proxy before exposing it to an untrusted network.