A real-time 1:1 chat app built with FastAPI, PostgreSQL, and React.
Supports online presence, WebSocket messaging, and graceful disconnects — all with zero authentication or chat history.
- 💬 Real-time messaging via WebSocket
- 👥 Live presence tracking (who's online)
- ⌨️ Typing indicators and message status
- 🎨 Professional UI with Material-UI
- 🔄 Auto-reconnection with exponential backoff
- 📱 Responsive design for all devices
- 🛡️ Rate limiting protection against spam
- 📊 Real-time metrics and performance monitoring
- 🧪 Comprehensive testing with pytest
- 🚀 CI/CD pipeline with GitHub Actions
- 🐳 Production-ready Docker deployment
🚀 Try it now! Open multiple browser tabs to test real-time chat:
# Start the app
make up
# Open in browser
open http://localhost:3000┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │ │ Backend │ │ Database │
│ (React) │ │ (FastAPI) │ │ (PostgreSQL) │
│ │ │ │ │ │
│ • ChatPane │ │ • REST API │ │ • users_online │
│ • OnlineUsers │ │ • WebSocket │ │ • chat_messages │
│ • Material-UI │ │ • Presence │ │ • user_sessions │
│ • Zustand Store │ │ • SQLAlchemy │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
📖 Full Architecture Documentation
- FastAPI - Modern, fast web framework for building APIs
- PostgreSQL - Reliable, open-source database
- SQLAlchemy - SQL toolkit and ORM
- Alembic - Database migration tool
- WebSockets - Real-time communication
- Uvicorn - ASGI server
- React 18 - UI library
- TypeScript - Type-safe JavaScript
- Vite - Fast build tool
- Material-UI - Professional UI components
- Zustand - State management
- Black - Python code formatter
- Ruff - Fast Python linter
- ESLint - JavaScript/TypeScript linter
- Prettier - Code formatter
- Docker - Containerization
- Pytest - Testing framework
- GitHub Actions - CI/CD automation
- Python 3.12+
- Node.js 18+
- PostgreSQL (Neon recommended)
- Docker & Docker Compose
-
Clone and setup
git clone <repository-url> cd fastchat-app cp env.example .env # Edit .env with your DATABASE_URL
-
Start with Docker
make up
-
Open in browser
- Frontend: http://localhost:3000
- API Docs: http://localhost:8000/docs
-
Test the app
python scripts/manual_test.py
-
Clone the repository:
git clone <repository-url> cd fastchat-app
-
Set up environment variables:
cp env.example .env # Edit .env with your DATABASE_URL and other settings -
Start all services:
make up
-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
The project includes a comprehensive Makefile for easy Docker operations:
# Start services
make up
# Stop services
make down
# View logs
make logs
make logs-backend
make logs-frontend
# Build images
make build
make build-backend
make build-frontend
# Database operations
make migrate
make migrate-up
make migrate-down
# Testing
make test
make test-frontend
make lint
# Maintenance
make clean
make prune
make shell-backend
make shell-frontend
# Status
make status
make health
# Show all available commands
make help-
Create a Neon database:
- Go to Neon Console
- Sign up/Login and create a new project
- Copy your connection string
-
Set up environment variables:
cp env.example .env # Edit .env and add your Neon DATABASE_URL
-
Create and activate virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run database migrations:
cd backend alembic upgrade head -
Run the backend:
cd backend uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Install dependencies:
cd frontend npm install -
Start development server:
npm run dev
# Backend tests
cd backend
pytest tests/ -v --cov=app --cov-report=html
# Run specific test categories
pytest tests/test_api.py -v # API endpoint tests
pytest tests/test_websocket.py -v # WebSocket integration tests
pytest tests/test_rate_limiting.py -v # Rate limiting tests
pytest tests/test_metrics.py -v # Metrics collection tests
# Frontend tests
cd frontend
npm test- Python: Run
black .to format code,ruff check .to lint - Frontend: Run
npm run lintto lint,npm run formatto format
- Message Rate: 60 messages per minute per user
- Typing Indicators: 10 per minute per user
- Ping Messages: 30 per minute per user
- Automatic Cleanup: Old timestamps cleaned every 5 minutes
- Connection Tracking: Total, active, and peak connections
- Message Analytics: Counts by type and processing times
- Error Monitoring: Error rates and types
- Performance Metrics: Messages per second, connections per minute
- Time-based Stats: Hourly and daily aggregations
- Unit Tests: API endpoints, WebSocket handlers, rate limiting
- Integration Tests: WebSocket communication, message flow
- Mock Testing: Isolated component testing with mock WebSockets
- Coverage Reporting: HTML coverage reports with pytest-cov
cd backend
alembic revision --autogenerate -m "Description"
alembic upgrade head| Endpoint | Method | Description |
|---|---|---|
GET /health |
GET | Health check endpoint |
GET /health/db |
GET | Database connectivity check |
POST /presence/heartbeat |
POST | Update user presence |
GET /presence/online |
GET | Get online users list |
GET /metrics/ |
GET | Application metrics |
GET /metrics/user/{id} |
GET | User-specific metrics |
GET /metrics/hourly |
GET | Hourly statistics |
GET /metrics/daily |
GET | Daily statistics |
GET /docs |
GET | Interactive API documentation |
FastChat uses WebSocket for real-time communication:
- Connection:
ws://localhost:8000/ws - Message Format: JSON
- Protocol: WebSocket Protocol Documentation
HELLO- Establish user identityMSG- Send/receive chat messagesTYPING- Typing indicatorsPRESENCE- Online users updatesERROR- Error handling
# Test API endpoints
curl http://localhost:8000/health
curl http://localhost:8000/presence/online
# Test WebSocket (using wscat)
wscat -c ws://localhost:8000/ws
{"type":"HELLO","data":{"user_id":"test-123","display_name":"Test User"}}fastchat-app/
├── backend/ # FastAPI backend
│ ├── app/
│ │ ├── main.py # FastAPI application
│ │ └── routers/ # API route handlers
│ └── Dockerfile
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── App.tsx # Main app component
│ │ └── main.tsx # Entry point
│ └── Dockerfile
├── infra/ # Infrastructure
│ └── docker-compose.yml # Docker services
├── .github/ # GitHub Actions
│ └── workflows/ # CI/CD pipelines
└── docs/ # Documentation
- No persistent authentication - Users are identified by UUID only
- No message history - Messages are not stored in database
- No file sharing - Text messages only
- No group chats - 1:1 conversations only
- No message encryption - Messages are not end-to-end encrypted
- No offline support - Requires active connection
- User authentication with JWT
- Message persistence and history
- File and image sharing
- Group chat support
- Message encryption
- Offline message queuing
- Push notifications
- User profiles and avatars
- ✅ WebSocket error handling improved with comprehensive error recovery
- ✅ UUID serialization issues resolved in backend
- ✅ Comprehensive test coverage implemented (37 tests passing)
- ✅ Rate limiting implementation completed
- ✅ Robust error recovery mechanisms in place
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting (
make lint) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow the existing code style (Black for Python, Prettier for JS/TS)
- Add tests for new features
- Update documentation for API changes
- Ensure Docker builds work correctly
This project is licensed under the MIT License - see the LICENSE file for details.