Realtime chat API built with FastAPI, WebSockets and Redis pub/sub.
API available at: https://realtime-chat-production-3725.up.railway.app
Interactive documentation: https://realtime-chat-production-3725.up.railway.app/docs
- Register a user at
/docs - Login and copy the
access_token - Open
test_chat.htmlin two browser tabs - Paste the token in each tab and click Connect
- Start chatting in realtime
Note: This API is hosted on Railway's free tier. The first request may take a few seconds to respond.
- FastAPI — Python web framework
- WebSockets — Realtime bidirectional communication
- Redis — Pub/sub message broker
- PostgreSQL — Message persistence
- SQLAlchemy — ORM
- bcrypt — Password hashing
- python-jose — JWT tokens
- Docker — Containerization
- pytest — Testing
- JWT authentication
- Realtime messaging with WebSockets
- Multiple chat rooms
- Message persistence in PostgreSQL
- Redis pub/sub for message broadcasting
- Docker
- Docker Compose
- Python 3.12+
# Clone the repository
git clone git@github.com:vanDevBett/realtime-chat.git
cd task-manager-api# Create the environment file
cp .env.example .env# Create and activate virtual environment
# Mac / Linux
python3 -m venv venv
source venv/bin/activate
# Windows
python -m venv venv
venv\Scripts\activate# Start the containers
docker compose up --buildAPI available at http://localhost:8000
Interactive documentation at http://localhost:8000/docs
Open test_chat.html in two browser tabs, register two users, paste their tokens and start chatting in realtime.
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /auth/register | Register a new user | No |
| POST | /auth/login | Login and get JWT token | No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /chat/rooms/{room}/messages | Get room message history | No |
| WS | /chat/ws/{room}?token=xxx | Connect to a chat room | JWT |
const ws = new WebSocket('ws://localhost:8000/chat/ws/general?token=YOUR_JWT');
ws.onmessage = (e) => {
const message = JSON.parse(e.data);
console.log(`${message.full_name}: ${message.content}`);
};
ws.send(JSON.stringify({ content: "Hello world" }));pytest tests/ -vapp/
├── api/ # Endpoints and WebSocket handlers
├── core/ # Config, database, security, dependencies
├── models/ # Database models
├── schemas/ # Pydantic schemas
├── services/ # Business logic, Redis and chat services
└── main.py # Entry point