This is the backend server for the Fluent Secure Chat App, built using FastAPI. It powers real-time, end-to-end encrypted messaging over WebSockets, handles JWT-based authentication, and manages user/message data with a clean, scalable architecture.
- π End-to-End Encryption Support (RSA Key Exchange using Android Keystore)
- π JWT Authentication (Access + Refresh Tokens)
- π Token Refresh Mechanism
- π§βπ€βπ§ User Registration, Login, and Search
- π© Message Storage and Retrieval
- π Real-Time Messaging via WebSockets
- π¦ Modular FastAPI Router Setup
- π CORS and Secure Headers Configured
- π SQLite / PostgreSQL support
.
βββ main.py # FastAPI application entry point
βββ database.py # Database setup and connection
βββ requirements.txt # Python dependencies
βββ alembic/ # DB migrations folder
β βββ env.py
β βββ script.py.mako
β βββ versions/
β βββ README
βββ core/ # Core logic (encryption, chat hub, auth utils)
β βββ authentication.py
β βββ chatHub.py
β βββ encryption.py
β βββ __init__.py
βββ crud/ # Database interaction layer
β βββ MessageCrud.py
β βββ __init__.py
βββ models/ # SQLAlchemy ORM models
β βββ Attachment.py
β βββ Message.py
β βββ User.py
β βββ __init__.py
βββ schemas/ # Pydantic request/response models
β βββ AttachmentSchema.py
β βββ MessageSchema.py
β βββ TokenSchema.py
β βββ UserSchema.py
β βββ PartnerSchema.py
β βββ __init__.py
βββ routes/ # FastAPI route handlers
β βββ authRoutes.py
β βββ messageRoutes.py
β βββ __init__.py
βββ websocket/ # (Currently empty, reserved for WebSocket logic)
βββ venv/ # Python virtual environment (excluded from version control)
- π Register/Login β Get Access + Refresh Tokens
- π Use Access Token for protected endpoints
- β»οΈ Use
/refresh
to get new tokens when expired - π¬ Authenticate WebSocket with token:
/chat/ws?token=...
- Clients connect using token auth (
?token=...
) - Messages are encrypted on the client before sending
- Server stores encrypted message (no decryption happens server-side)
- Messages are relayed in real-time to the receiver if online
git clone https://github.com/jishnu70/fluent-fastapi-backend.git
cd fluent-fastapi-backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload
Server will run at http://127.0.0.1:8000
Method | Endpoint | Description |
---|---|---|
POST | /auth/register |
Register new user |
POST | /auth/login |
Login and get JWT tokens |
POST | /auth/refresh |
Refresh expired tokens |
GET | /users/search?query= |
Search for users |
GET | /chat/all_messages |
Get all messages with partner |
WS | /chat/ws?token= |
WebSocket for real-time chat |
- FastAPI (Python)
- SQLAlchemy (ORM)
- JWT (Authentication)
- PostgreSQL (Database)
- WebSockets (Real-time messaging)
- β Expire old messages (auto-delete after X days)
- πΌοΈ Media support (images, audio)
- π² Push notification integration (FCM)
- π Switch to PostgreSQL for production
- π‘οΈ Rate-limiting and IP-based blocking
Use Postman or websocat:
websocat "ws://localhost:8000/chat/ws?token=YOUR_ACCESS_TOKEN"