Skip to content

A feature-rich terminal-based chat system with private messaging, group chats, and persistent chat history. Built with Python sockets and supports real-time one-to-one conversations, group collaboration, continuous chat mode, and auto-saved message logs. Perfect for learning about networking, authentication, and multi-user systems.

Notifications You must be signed in to change notification settings

Tejeswar001/chat-app-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chat Application

A feature-rich terminal-based chat application with support for one-to-one messaging, group chats, chat history, and continuous chat mode.

Features

✨ Authentication

  • User registration and login
  • Secure password hashing (SHA-256)
  • Session-based authentication with tokens

πŸ’¬ Private Messaging

  • Send direct messages to users
  • Continuous chat mode for seamless conversations
  • Real-time message delivery
  • Chat history saved automatically

πŸ‘₯ Group Chat

  • Create and manage groups
  • Join/leave groups
  • Send messages to all group members
  • Group chat history

πŸ“ Chat History

  • Automatic saving of all conversations
  • History stored in text files
  • Organized by conversation

🎨 Interactive CLI

  • Colorful terminal interface
  • Real-time message notifications
  • Multiple chat modes
  • Help system

Installation

  1. Clone or download the repository
  2. Navigate to the project directory:
    cd chat-app
  3. Create a virtual environment (optional but recommended):
    python -m venv .venv
    source .venv/bin/activate  # On Linux/Mac
    # or
    .venv\Scripts\activate  # On Windows

Running the Application

Start the Server

cd /home/tej/chat-app
PYTHONPATH=/home/tej/chat-app python server/server.py

The server will start listening on port 5000.

Start the Client

In a new terminal:

cd /home/tej/chat-app
PYTHONPATH=/home/tej/chat-app python client/client.py

You can run multiple clients to simulate different users.

Usage Guide

Authentication Commands

Register a new account:

> register
Username: alice
Password: mypassword

Login:

> login
Username: alice
Password: mypassword

Private Messaging

Send a single message:

> send bob Hello Bob!

Enter continuous chat mode with a user:

> chat bob
@bob > Hello!
@bob > How are you?
@bob > /exit

In continuous chat mode:

  • Just type your message and press Enter
  • Type /exit to leave continuous chat mode
  • The prompt shows @username > to indicate you're chatting with that user

Group Chat

Create a new group:

> create developers

Join an existing group:

> join developers

Send a message to a group:

> gsend developers Hello everyone!

Enter continuous group chat:

> gchat developers
#developers > Good morning team!
#developers > Anyone available?
#developers > /exit

List your groups:

> groups

View group members:

> members developers

Leave a group:

> leave developers

Other Commands

Show help:

> help

Exit the application:

> quit

or

> exit

Chat History

All conversations are automatically saved to text files in the chat_history/ directory:

  • One-to-one chats: chat_history/user1:user2.txt
  • Group chats: chat_history/group_groupname.txt

Example history file content:

Chat History: alice and bob
============================================================

[2026-01-28 14:30:15] alice -> bob
  Hello Bob!

[2026-01-28 14:30:22] bob -> alice
  Hi Alice!

Architecture

Project Structure

chat-app/
β”œβ”€β”€ client/
β”‚   └── client.py          # Client application
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ server.py          # Main server
β”‚   β”œβ”€β”€ auth.py            # Authentication logic
β”‚   β”œβ”€β”€ session.py         # Session management
β”‚   β”œβ”€β”€ router.py          # Message routing
β”‚   β”œβ”€β”€ groups.py          # Group management
β”‚   └── history.py         # Chat history storage
β”œβ”€β”€ shared/
β”‚   └── protocol.py        # Communication protocol
β”œβ”€β”€ chat_history/          # Saved chat logs (auto-created)
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ DATA_STRUCTURES.md     # Data structures documentation
└── README.md             # This file

Key Components

  • Server: Handles multiple clients, routes messages, manages authentication
  • Client: Terminal UI for user interaction
  • Protocol: JSON-based message format
  • History: Persistent storage of all conversations
  • Groups: Multi-user chat rooms

Data Structures

For detailed documentation of all data structures used in the application, see DATA_STRUCTURES.md.

Example Session

User Alice

$ python client/client.py
╔═══════════════════════════════════════╗
β•‘     Chat Application v2.0             β•‘
β•‘  Now with Groups & Continuous Chat!   β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
βœ“ Connected to server

Guest > register
Username: alice
Password: ***
βœ“ Registration successful! You can now login.

Guest > login
Username: alice
Password: ***
βœ“ Logged in successfully!

alice > create developers
βœ“ Group 'developers' created successfully!

alice > chat bob
Entered chat with bob. Type /exit to leave.
@bob > Hey Bob, want to join the developers group?
[14:35:10] You: Hey Bob, want to join the developers group?
[14:35:23] bob: Sure! How do I join?
@bob > Just type: join developers
[14:35:30] You: Just type: join developers
@bob > /exit
Exited continuous chat mode

alice > gchat developers
Entered group chat: developers. Type /exit to leave.
#developers > Welcome to the team!
[14:36:15] You: Welcome to the team!
[14:36:20] [developers] bob: Thanks! Happy to be here.
#developers > /exit

User Bob

$ python client/client.py
βœ“ Connected to server

Guest > register
Username: bob
Password: ***

Guest > login
Username: bob
Password: ***
βœ“ Logged in successfully!

[14:35:10] alice: Hey Bob, want to join the developers group?

bob > send alice Sure! How do I join?

[14:35:30] alice: Just type: join developers

bob > join developers
βœ“ Joined group 'developers'!

[14:36:15] [developers] alice: Welcome to the team!

bob > gsend developers Thanks! Happy to be here.

Protocol

The application uses a JSON-based protocol over TCP sockets. Messages are newline-delimited JSON objects.

Message Types

  • AUTH: Authentication (register, login)
  • CHAT: Private messages
  • GROUP: Group operations and messages
  • SYSTEM: Server responses and notifications

For complete protocol documentation, see DATA_STRUCTURES.md.

Security Note

⚠️ This is a demonstration project. The current implementation:

  • Uses SHA-256 for password hashing (single hash, no salt)
  • Transmits messages in plaintext
  • Stores passwords in memory

For production use, you should:

  • Use proper password hashing (bcrypt, argon2)
  • Implement TLS/SSL for encrypted communication
  • Use a proper database for persistence
  • Add input validation and sanitization
  • Implement rate limiting
  • Add proper error handling

Future Enhancements

  • File transfer support
  • End-to-end encryption
  • Message read receipts
  • User presence indicators
  • Database persistence (SQLite/PostgreSQL)
  • Web-based client
  • Voice/video chat
  • Message search functionality
  • User profiles and avatars

License

This project is for educational purposes.

Contributing

Feel free to fork and enhance the project!

About

A feature-rich terminal-based chat system with private messaging, group chats, and persistent chat history. Built with Python sockets and supports real-time one-to-one conversations, group collaboration, continuous chat mode, and auto-saved message logs. Perfect for learning about networking, authentication, and multi-user systems.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages