SecureChat is a real-time chat application built using FastAPI and WebSockets.
It enables multiple users to connect, send messages, files instantly, and handle connections securely.
-
FastAPI – Handles the web interface and user session management.
-
WebSockets – Enables real-time communication between users.
-
HTML/CSS/Javascript - Acts as the websocket client.
-
Flask-SQLAlchemy – Manages user database and authentication.
-
Flask-Bcrypt – Securely hashes user passwords.
-
SSL/TLS Encryption – Secures WebSocket communication.
-
SQLite – Lightweight database for user authentication.
-
Quill Editor & Emoji Picker - Provides rich text formatting and emoji support.
-
Render - Hosting FastAPI, templates and Websocket server.
-
CockroachDB - Database storage service that uses PostgreSQL structure.
-
UptimeRobot - Uptime monitoring service.
-
VirusTotal - Scanning file uplaod for malware.
-
Firebase - Hosting uploaded files for each chat.
The application is available at: 🔗 https://securechat-oe69.onrender.com/home
The WebSocket server runs at: 🔗 wss://securechat-oe69.onrender.com/ws
Render dashboard for deployed server:
Database tables:
UptimeRobot Dashboard:
VirusTotal APIs used:
Firebase bucket:
- Users must sign up before logging in.
- Passwords are securely hashed with Flask-Bcrypt.
- Only authenticated users can participate in the chat.
- Equipped with brute-force protection
- SSL/TLS Encryption ensures all WebSocket messages are protected.
- Uses wss:// for secure communication.
- Messages are broadcast to all connected users in real-time.
- New users can create/join private & group chats upon connecting.
- Enable chat with all connected users with a default general chat room.
- Users can leave the app.
- Users are reconnected in case of interruptions.
- Heartbeat mechanism to maintain persistent connections.
-
Render
- The FastAPI app and PostgreSQL‐compatible CockroachDB are both hosted on Render.com.
- Every push to
maintriggers an automatic build & deploy. - All secrets (e.g.
DATABASE_URL,SECRET_KEY,VIRUSTOTAL_API_KEY) are stored in Render’s Environment settings.
-
Database Setup
- We use SQLAlchemy’s
Base.metadata.create_all()on startup to automatically create any missing tables (user,message,log, etc.). - Connection string is read from
DATABASE_URL. Example:postgresql://<user>:<pass>@<host>:26257/securechat?sslmode=require
- We use SQLAlchemy’s
- Prevents spamming by limiting messages per user & login requests.
- UptimeRobot is used to ping backend and ensure it's online
- Provides list of online users to select from for private and group chat.
- Users can view and select their active chats.
- Seamlessly switch between conversations without leaving the application with session chat history.
- User lists shows green and red dot for each user to indicate online and offline presence.
- Current open chat shows typing indicators for the user who is typing in the chat.
- All chats have file upload/download options.
- File uploads are first scanned with VirusTotal APIs for malware before transmission at client-side
- Files are encrypted before upload to cloud storage & decrypted upon download.
- Uploaded files are hosted on Firebase per chat id.
- Custom Auth token is issued to the authenticated user upon login to the server for Firebase Authentication. The user is signed out from Firebase after logging out from the chat page.
- Firebase bucket rule allows read & write only from authenticated users.
- Send emojis in chat with the Unicode emoji picker.
- Text formatting features such as bold, italics, underline, strikethrough, headings, superscript/subscript, bullets/numbering list, change font color & text highlight.
- Each session of user conversation is logged with timestamp in txt format in logs folder of the root directory. Example chat_general_chat_session_2025-03-20_07-44-57.
- Blobs stored on the server are encrypted. The server cannot decrypt messages.
- Chat messages are end-to-end encrypted.
- ECDH (Elliptic Curve Diffie-Hellman) is used for key exchange and AES-GCM for message encryption
- Private chats: Each user generates an ECDH key pair. The sender and receiver exchange public keys to derive a shared symmetric key, which is used to encrypt and decrypt messages.
- Group Chats: A group symmetric key is encrypted with each recipient's public key and shared with the group. Each recipient then uses their private key to decrypt the group key and can encrypt/decrypt messages using it.
- File Encryption: Files are encrypted before being uploaded to Firebase using AES-GCM and are only accessible by the intended recipient(s) after decryption.
/SecureChat
│── main.py # Main Python server file
│── requirements.txt # Dependency list
│── .gitignore # Ensures sensitive files are not pushed to Git
│── /client # HTML templates
│ ├── index.html # Signup/Login page
│ ├── chat.html # Chat interface
│ ├── base.html # Base html file
│ ├──/static/css # CSS files
│ ├── style.css # Styling for UI
│── README.md # Instructions for running the project
│── Dockerfile # For docker image
│── render.yaml # Render deployment file
│── User Guide - Group 23.pdf # User Guide for setup & running the project



