Skip to main content

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

  1. Fork this repository
  2. Create a new Web Service on Render
  3. Connect your repository
  4. Set the root directory to terminalchat-server
  5. Use build command: pip install -r requirements.txt
  6. Use start command: python main.py
  7. Set environment variables if needed

๐ŸŽฎ How to Use

  1. Start the client: Run terminalchat command
  2. Choose server: Enter server address or use default
  3. Join/Create channel:
    • Type new to create a new channel (gets a 6-character code)
    • Enter existing code to join a channel
  4. Set username: Enter your display name
  5. Start chatting: Type messages and press Enter
  6. Exit: Type quit, exit, or press Ctrl+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 statistics
  • GET /health: Health check endpoint
  • WebSocket /ws/{channel_code}: Chat WebSocket connection

๐Ÿ› ๏ธ API Documentation

WebSocket Protocol

  • Connection: ws://server/ws/{channel_code} or wss://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 count
  • GET /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:8000 for 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

gupsup-1.0.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gupsup-1.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

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

Hashes for gupsup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ec524905af802ba62c953f9b0ae9849b671605abc5f8529226fbf49bef102838
MD5 0e9afa223993c2284feef97be05c541f
BLAKE2b-256 f7b8b0f8b65c37c3d8f4dc7e291db7ac7ca8192eec2adf9edad3f2eb1a530369

See more details on using hashes here.

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

Hashes for gupsup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a666623e374879c19b695ad782ce7158e10f5e2e9ed4a7984736f57cfbdc31a4
MD5 99b693d952b70a4f902e5acc3dba9b09
BLAKE2b-256 ade2b3d9773fd55eda90930a58dfb041f04206dceddad42c4f9a4ef53bc39135

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page