A realtime command-line chat application built with Python (asyncio) and MongoDB. Messages appear live across all connected clients using MongoDB Change Streams, and old messages auto-expire after 30 minutes using a TTL index.
- ๐ Realtime chat powered by MongoDB Change Streams.
- ๐งโ๐คโ๐ง Public chatroom (
all
) with support for DMs (extendable). - ๐ Auto-delete messages after 30 minutes (TTL index).
- โฑ Shows recent chat history when joining.
- โจ Beautiful CLI output with
rich
. - โก Async + non-blocking input (smooth typing + live updates).
- ๐ค Assisted & scaffolded with AI during development.
- Python (3.9+)
- asyncio โ concurrency
- Motor โ async MongoDB driver
- MongoDB โ database + change streams + TTL
- Rich โ styled CLI output
- python-dotenv โ load
.env
config - AI Assistance โ design & development scaffolding
- Clone this repo:
git clone https://github.com/yourusername/cli-chat-app.git
cd cli-chat-app
- Install dependencies:
pip install motor rich python-dotenv
- Set up environment variables in a
.env
file:
MONGODB_URI=mongodb://localhost:27017
CHAT_DB=chat_app
- Start MongoDB (local or Atlas).
Run the app in multiple terminals (one per user):
python chat_async.py
- Choose a username when prompted.
- Type messages to chat in realtime.
- Use
/quit
orCtrl+C
to exit.
TTL_SECONDS
โ how long messages live (default: 1800 = 30min)RECENT_LIMIT
โ how many past messages to show when joining