A full-stack real-time chat application built using:
- Python
- FastAPI
- React
- WebSockets
- PostgreSQL
- bcrypt Authentication
This project evolved phase-by-phase from a basic TCP socket server into a modern real-time chat system with authentication, persistent chat history, online user tracking, and responsive frontend support.
- User Registration
- User Login
- Password Hashing with bcrypt
- Duplicate Login Prevention
- PostgreSQL-backed User Storage
- Multi-client real-time messaging
- WebSocket-based communication
- Instant message synchronization
- Online users tracking
- Join/Leave system messages
- PostgreSQL database integration
- Persistent chat history
- Automatic history recovery on reconnect
- React + Vite frontend
- Responsive UI
- Mobile-friendly layout
- Inline authentication messages
- Real-time updates without refresh
- Python
- FastAPI
- WebSockets
- psycopg2
- bcrypt
- React
- Vite
- PostgreSQL
tcp-chat-server/
│
├── client/
├── frontend/
├── server/
├── shared/
├── websocket_server/
│
├── requirements.txt
└── README.md
git clone https://github.com/karthikeya20012007/tcp-chat-server.gitcd tcp-chat-serverpython -m venv venvsource venv/bin/activatevenv\Scripts\activatepip install fastapi uvicorn psycopg2 bcrypt python-multipartCREATE DATABASE tcp_chat;CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);CREATE TABLE messages (
id SERIAL PRIMARY KEY,
sender VARCHAR(50),
content TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Update database credentials inside:
shared/config.py
Example:
DB_HOST = "localhost"
DB_NAME = "tcp_chat"
DB_USER = "postgres"
DB_PASSWORD = "your_password"uvicorn websocket_server.app:app --reload --host 0.0.0.0 --port 8000Backend runs on:
http://localhost:8000
cd frontendnpm installnpm run dev -- --hostFrontend runs on:
http://localhost:5173
Create a new account using:
- Username
- Password
Login using registered credentials.
- Send real-time messages
- View online users
- Receive chat history automatically
- Join from multiple devices on the same network
- JWT Authentication
- Private Chats
- Chat Rooms
- Redis Pub/Sub Scaling
- Docker Deployment
- Message Timestamps
- Typing Indicators
- Media/File Sharing
- Kubernetes Deployment
- End-to-End Encryption
This project demonstrates:
- Socket Programming
- Concurrent Systems
- WebSocket Architecture
- Full-Stack Integration
- Real-Time Systems
- Authentication Systems
- PostgreSQL Persistence
- Frontend/Backend Communication
- Responsive UI Design
Karthikeya