Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Shashank0032/Chat-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Redis Pub/Sub Chat (FastAPI + WebSockets)

Real-time chat with group room and 1-to-1 DMs, built using FastAPI + WebSockets, Redis pub/sub (for fan-out & presence), and PostgreSQL (for message history). Frontend is plain HTML/CSS/JS with Jinja templates. Dockerized for easy local runs; CI/CD-friendly for cloud deploys.

Live demo: https://chat-with-randoms.onrender.com/


✨ Features

  • πŸšͺ Registration (18+), globally unique username (inline β€œname taken” warning)
  • πŸ‘₯ Online presence synced via Redis (works across instances)
  • πŸ’¬ General room + Direct Messages (DMs)
  • πŸ“š Message history persisted in Postgres
  • πŸ”” Unread badges (red counters) for rooms/DMs
  • ♻️ Local cache per conversation (so messages persist when switching tabs)
  • 🐳 Dockerized; one command local up via Compose
  • πŸ” Auto-deploy ready (link repo to host = redeploy on every push)

🧭 Architecture

FastAPI (WebSockets) β”œβ”€ Manages WS connections per instance β”œβ”€ Publishes to Redis channels (messages & presence) └─ Subscribes to Redis to fan-out to local sockets

Redis (Upstash in prod) β”œβ”€ Channels: chat_messages:* , user_status_channel └─ Keys: online_users_set (presence), user_profiles (nameβ†’profile)

PostgreSQL (Render in prod) └─ Stores message history


πŸ—‚ Project Structure

. β”œβ”€ backend/ β”‚ β”œβ”€ main.py # FastAPI app (WS, Redis pub/sub, DB) β”‚ β”œβ”€ Dockerfile # Container image for backend β”‚ β”œβ”€ requirements.txt β”‚ └─ static/ # Frontend (templates + CSS) β”‚ β”œβ”€ index.html # registration page β”‚ β”œβ”€ chat.html # chat UI + client logic β”‚ └─ style.css β”œβ”€ docker-compose.yml # local dev (backend + redis + postgres) └─ init_db.sql # schema for messages table & index


πŸš€ Run Locally (Docker Compose)

Prereqs

  • Docker Desktop (or Docker + Docker Compose)
  • Ports 8000, 6379, 5432 available

Steps

# 1) clone
git clone <your-repo-url>
cd <your-repo>

# 2) start services
docker compose up --build

.

πŸ”Œ Endpoints GET / β€” registration page POST /register β€” saves cookie, redirects to /chat GET /chat β€” chat UI GET /messages/{room_id}?limit=50 β€” recent messages (room or DM roomId) GET /online_users β€” currently online users GET /api/name_available?name=... β€” username availability WS /ws/{user_id} β€” WebSocket channel

πŸ™Œ Credits FastAPI Uvicorn Redis(Upstash in production) PostgreSQL Docker

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published