Secure terminal-based chat application for real-time communication
Project description
TerminalChat
A modern terminal-based real-time chat system using WebSockets with FastAPI backend and robust error handling.
โจ Features
- ๐ Real-time messaging via WebSockets
- ๐ Channel-based chat with unique room codes
- ๐ Automatic reconnection with exponential backoff
- ๐ SSL/TLS support for secure connections
- ๐ฑ Cross-platform terminal client
- โก Low latency communication
- ๐ก๏ธ Robust error handling
- ๐ฏ Easy deployment on cloud platforms
๐ Quick Start
Option 1: Install from PyPI (Recommended)
pip install terminalchat
terminalchat
Option 2: Install from Source
git clone https://github.com/iamRahul21/terminalchat.git
cd terminalchat
pip install .
terminalchat
๐ฅ๏ธ Running Your Own Server
Local Development
cd terminalchat-server
pip install -r requirements.txt
python main.py
Server will start on http://localhost:8000
Using Docker (Optional)
cd terminalchat-server
docker build -t terminalchat-server .
docker run -p 8000:8000 terminalchat-server
Deploy to Render.com
- Fork this repository
- Create a new Web Service on Render
- Connect your repository
- Set the root directory to
terminalchat-server - Use build command:
pip install -r requirements.txt - Use start command:
python main.py - Set environment variables if needed
๐ฎ How to Use
- Start the client: Run
terminalchatcommand - Choose server: Enter server address or use default
- Join/Create channel:
- Type
newto create a new channel (gets a 6-character code) - Enter existing code to join a channel
- Type
- Set username: Enter your display name
- Start chatting: Type messages and press Enter
- Exit: Type
quit,exit, or pressCtrl+C
๐ Configuration Options
Environment Variables
TERMINALCHAT_SERVER: Default server address (default:terminalchat-server-1.onrender.com:443)
Server Configuration
The server supports the following endpoints:
GET /: Server status and statisticsGET /health: Health check endpointWebSocket /ws/{channel_code}: Chat WebSocket connection
๐ ๏ธ API Documentation
WebSocket Protocol
- Connection:
ws://server/ws/{channel_code}orwss://server/ws/{channel_code} - Message Format:
username: message_content - Join Notification:
๐ข username joined the chat - Leave Notification:
๐ด username left the chat
REST Endpoints
GET /: Returns server status, active channels, and connection countGET /health: Returns health status for monitoring
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโ WebSocket โโโโโโโโโโโโโโโโโโโ
โ Terminal โโโโโโโโโโโโโโโโโโโบโ FastAPI โ
โ Client โ /ws/{code} โ Server โ
โ (Python) โ โ (Python) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โข Reconnection โ โ โข Channel Mgmt โ
โ โข Error Handle โ โ โข Broadcasting โ
โ โข User Input โ โ โข User Trackingโ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
๐ง Development
Prerequisites
- Python 3.8+
- pip
Setting up Development Environment
# Clone the repository
git clone https://github.com/iamRahul21/terminalchat.git
cd terminalchat
# Install in development mode
pip install -e .
# Install server dependencies
cd terminalchat-server
pip install -r requirements.txt
Running Tests
# Install test dependencies
pip install pytest pytest-asyncio
# Run tests
pytest
Project Structure
terminalchat/
โโโ terminalchat/ # Client package
โ โโโ __init__.py
โ โโโ __main__.py
โ โโโ client.py # Main client logic
โ โโโ main.py
โโโ websocket_server/ # Alternative server (legacy)
โโโ pyproject.toml # Package configuration
โโโ setup.py # Setup script
โโโ README.md
terminalchat-server/ # Main server
โโโ main.py # FastAPI server
โโโ requirements.txt
โโโ README.md
๐ Troubleshooting
Common Issues
Connection Failed
- Check if server URL is correct
- Verify internet connection
- Try using
localhost:8000for local development
Reconnection Issues
- Client automatically retries up to 5 times
- Check server logs for connection issues
- Verify WebSocket support in your network
Messages Not Appearing
- Ensure you're in the same channel
- Check if username contains special characters
- Try refreshing the connection
Debug Mode
Set logging level for debugging:
export PYTHONPATH="."
python -c "import logging; logging.basicConfig(level=logging.DEBUG); from terminalchat.client import run_client; run_client()"
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐จโ๐ป Author
Rahul Deka - iamRahul21
๐ Acknowledgments
- FastAPI for the excellent WebSocket support
- The Python websockets library for robust WebSocket client implementation
- The open-source community for inspiration and tools
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gupsup-1.0.0.tar.gz.
File metadata
- Download URL: gupsup-1.0.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec524905af802ba62c953f9b0ae9849b671605abc5f8529226fbf49bef102838
|
|
| MD5 |
0e9afa223993c2284feef97be05c541f
|
|
| BLAKE2b-256 |
f7b8b0f8b65c37c3d8f4dc7e291db7ac7ca8192eec2adf9edad3f2eb1a530369
|
File details
Details for the file gupsup-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gupsup-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a666623e374879c19b695ad782ce7158e10f5e2e9ed4a7984736f57cfbdc31a4
|
|
| MD5 |
99b693d952b70a4f902e5acc3dba9b09
|
|
| BLAKE2b-256 |
ade2b3d9773fd55eda90930a58dfb041f04206dceddad42c4f9a4ef53bc39135
|