SwiftChat is a modern real-time chat application built with FastAPI, WebSockets, and Neon PostgreSQL.
Features JWT authentication, live messaging, chat room management, and persistent chat history.
- 🔐 User Authentication - Secure registration and login with JWT tokens
- 💬 Real-time Messaging - Instant messaging with WebSocket connections
- 🏠 Chat Rooms - Create and join different chat rooms
- 📱 Responsive UI - Clean, modern interface that works on all devices
- 💾 Message Persistence - Chat history stored in PostgreSQL database
- 🚀 Single-Service Deployment - Frontend and backend served together
- 🔒 Secure - Password hashing with bcrypt and JWT token authentication
| Technology | Purpose | Features |
|---|---|---|
| 🐍 FastAPI | Web Framework | High-performance async API, Auto-documentation, Type hints |
| 🗄️ SQLAlchemy | Database ORM | Advanced querying, Relationship mapping, Migration support |
| 🐘 PostgreSQL (Neon) | Cloud Database | Serverless, Auto-scaling, High availability |
| ⚡ WebSockets | Real-time Communication | Bi-directional, Low latency, Event-driven |
| 🔐 JWT | Authentication | Stateless, Secure, Token-based auth |
| 🛡️ bcrypt | Password Security | Adaptive hashing, Salt generation, Brute-force resistant |
| 🔧 Uvicorn | ASGI Server | High performance, Production ready, Hot reload |
| 📦 Pydantic | Data Validation | Type validation, Serialization, Auto-documentation |
| Technology | Purpose | Features |
|---|---|---|
| 🌐 HTML5 | Structure | Semantic markup, Accessibility, Modern standards |
| 🎨 CSS3 | Styling | Flexbox/Grid, Animations, Responsive design |
| ⚡ Vanilla JavaScript | Interactivity | WebSocket client, Async/await, DOM manipulation |
| 📱 Responsive Design | Mobile Support | Adaptive layouts, Touch-friendly, Cross-browser |
| Technology | Purpose | Features |
|---|---|---|
| 🚀 Render | Hosting Platform | Free tier, Auto-deploy, HTTPS, Global CDN |
| 🌍 Neon | Database Hosting | Serverless PostgreSQL, Branching, Auto-scaling |
| 🔄 Git | Version Control | Distributed, Branching, Collaboration |
| 🐙 GitHub | Code Repository | CI/CD integration, Issue tracking, Pull requests |
| Feature | Implementation | Benefit |
|---|---|---|
| 🔒 CORS Protection | FastAPI Middleware | Cross-origin security |
| 🛡️ SQL Injection Prevention | SQLAlchemy ORM | Parameterized queries |
| 🔐 Environment Variables | python-dotenv | Secure configuration |
| ⚡ Async Architecture | FastAPI + Uvicorn | High concurrency |
| 🚀 Static File Serving | FastAPI StaticFiles | Optimized delivery |
graph TB
A[👤 User Browser] --> B[🌐 Frontend HTML/CSS/JS]
B --> C[⚡ WebSocket Connection]
B --> D[🔗 REST API Calls]
C --> E[🖥️ FastAPI Backend]
D --> E
E --> F[🗄️ SQLAlchemy ORM]
F --> G[🐘 PostgreSQL Database]
E --> H[🔐 JWT Authentication]
E --> I[🛡️ Security Middleware]
SwiftChat/
├── app/
│ ├── __init__.py
│ ├── main.py # FastAPI app with static serving
│ ├── config.py # Environment configuration
│ ├── database.py # Database connection
│ ├── models.py # SQLAlchemy models
│ ├── schemas.py # Pydantic schemas
│ ├── websocket.py # WebSocket handling
│ └── routes/
│ ├── auth.py # Authentication endpoints
│ └── chat.py # Chat endpoints
├── frontend/
│ ├── login.html # Login page
│ ├── register.html # Registration page
│ ├── chat.html # Chat interface
│ └── styles.css # Shared styles
├── requirements.txt # Python dependencies
├── .env # Environment variables
└── README.md
- Python 3.8+
- PostgreSQL database (or Neon account)
-
Clone the repository
git clone <your-repo-url> cd SwiftChat
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env with your database credentials -
Run the application
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
-
Access the application
- Open your browser to
http://localhost:8000 - Register a new account or login
- Start chatting!
- Open your browser to
-
Push to GitHub
git add . git commit -m "Ready for deployment" git push origin main
-
Create Render Web Service
- Connect your GitHub repository
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn app.main:app --host 0.0.0.0 --port $PORT
-
Environment Variables
DATABASE_URL=postgresql://your-neon-db-url JWT_SECRET=your-super-secret-jwt-key ENVIRONMENT=production DEBUG=False -
Access your deployed app
- Frontend:
https://your-app.onrender.com/ - API Docs:
https://your-app.onrender.com/docs
- Frontend:
POST /auth/register- Register new userPOST /auth/login- User login
GET /chat/messages/{room_id}- Get chat historyPOST /chat/messages/- Send messageWS /ws/chat/{room_id}- WebSocket connection
GET /health- Health checkGET /docs- API documentation
- Register a new account with username, email, and password
- Login with your credentials
- Enter a room ID (any number) to join a chat room
- Start messaging - messages are delivered in real-time
- View history - previous messages are loaded automatically
- Password Hashing with bcrypt
- JWT Token Authentication
- CORS Protection
- SQL Injection Prevention with SQLAlchemy ORM
- Environment Variable Security
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI for the excellent web framework
- Neon for managed PostgreSQL hosting
- Render for easy deployment platform
Built with ❤️ by [Sudipta Sarkar]
Live Demo: SwiftChat on Render