Skip to content

SwiftChat is a lightweight real-time chat application built using FastAPI for the backend and HTML, CSS, and JavaScript for the frontend. It allows users to register, log in, select chat rooms, and send/receive messages.

Notifications You must be signed in to change notification settings

itzsudipta/SwiftChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ SwiftChat

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.

โœจ Features

  • ๐Ÿ” 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

๐Ÿ› ๏ธ Tech Stack

๐Ÿ–ฅ๏ธ Backend Technologies

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

๐ŸŽจ Frontend Technologies

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

โ˜๏ธ Infrastructure & Deployment

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

๐Ÿ›ก๏ธ Security & Performance

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

๐Ÿ—๏ธ Architecture Overview

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]
Loading

๐Ÿ“ Project Structure

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

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+
  • PostgreSQL database (or Neon account)

Local Development

  1. Clone the repository

    git clone <your-repo-url>
    cd SwiftChat
  2. Install dependencies

    pip install -r requirements.txt
  3. Set up environment variables

    cp .env.example .env
    # Edit .env with your database credentials
  4. Run the application

    uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
  5. Access the application

    • Open your browser to http://localhost:8000
    • Register a new account or login
    • Start chatting!

๐ŸŒ Deployment (Render)

Backend + Frontend (Single Service)

  1. Push to GitHub

    git add .
    git commit -m "Ready for deployment"
    git push origin main
  2. 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
  3. Environment Variables

    DATABASE_URL=postgresql://your-neon-db-url
    JWT_SECRET=your-super-secret-jwt-key
    ENVIRONMENT=production
    DEBUG=False
    
  4. Access your deployed app

    • Frontend: https://your-app.onrender.com/
    • API Docs: https://your-app.onrender.com/docs

๐Ÿ”ง API Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - User login

Chat

  • GET /chat/messages/{room_id} - Get chat history
  • POST /chat/messages/ - Send message
  • WS /ws/chat/{room_id} - WebSocket connection

System

  • GET /health - Health check
  • GET /docs - API documentation

๐ŸŽฎ Usage

  1. Register a new account with username, email, and password
  2. Login with your credentials
  3. Enter a room ID (any number) to join a chat room
  4. Start messaging - messages are delivered in real-time
  5. View history - previous messages are loaded automatically

๐Ÿ”’ Security Features

  • Password Hashing with bcrypt
  • JWT Token Authentication
  • CORS Protection
  • SQL Injection Prevention with SQLAlchemy ORM
  • Environment Variable Security

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • 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

About

SwiftChat is a lightweight real-time chat application built using FastAPI for the backend and HTML, CSS, and JavaScript for the frontend. It allows users to register, log in, select chat rooms, and send/receive messages.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors