Skip to content

mikhailofff/simple-chat-fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Real-Time Chat Application

A modern, real-time chat application built with React, FastAPI, and WebSocket technology. Features user authentication, real-time messaging, and online user tracking.

πŸš€ Features

  • Real-time messaging with WebSocket connections
  • User authentication using custom JWT
  • Online user tracking and user list
  • Responsive design with modern UI
  • System messages for user join/leave notifications

πŸ› οΈ Tech Stack

Frontend

  • React 19 - Modern React with hooks
  • Vite - Fast build tool and dev server
  • JWT - Authentication and user management

Backend

  • FastAPI - Modern Python web framework
  • SQLAlchemy - Database ORM
  • PostgreSQL - Primary database
  • Redis - Caching and session management
  • WebSocket - Real-time bidirectional communication
  • Alembic - Database migrations
  • fastapi-limiter - Rate limiting backed by Redis

πŸ–ΌοΈ Screenshots

image

πŸš€ Quick Start with Docker

Prerequisites

  • Docker and Docker Compose installed
  • JWT for authentication

Installation

  1. Clone the repository

    git clone https://github.com/mikhailofff/simple-chat-fastapi.git
    cd simple-chat-fastapi
  2. Set up environment variables

    Copy the example environment files and configure them:

    cp backend/src/.env.example backend/src/.env

    Then edit .env file with your actual values.

  3. Start the application

    docker compose up --build
  4. Access the application

Stopping the application

docker compose down

πŸ”§ Development

Project Structure

simple-chat-fastapi/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app.py               # FastAPI application (lifespan, middleware, routers)
β”‚   β”‚   β”œβ”€β”€ routes/              # API routes (e.g., chat endpoints, WebSocket)
β”‚   β”‚   β”œβ”€β”€ database/            # DB engine, sessions, CRUD helpers, models
β”‚   β”‚   β”‚   β”œβ”€β”€ models/          # SQLAlchemy models
β”‚   β”‚   β”œβ”€β”€ core/                # Core utilities (e.g., Redis client)
β”‚   β”‚   β”œβ”€β”€ schemas/             # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ dependencies.py      # FastAPI dependencies (auth helpers, etc.)
β”‚   β”‚   β”œβ”€β”€ config.py            # Settings and config
β”‚   β”‚   β”œβ”€β”€ utils.py             # JWT utilities and helpers
β”‚   β”‚   β”œβ”€β”€ .env.example         # Environment variables template
β”‚   β”‚   └── .env                 # Your environment variables (not in git)
β”‚   β”œβ”€β”€ migrations/              # Alembic migration scripts
β”‚   β”œβ”€β”€ logging_config.ini       # Centralized Python logging configuration
β”‚   β”œβ”€β”€ server.py                # ASGI app export; loads logging config
β”‚   └── Dockerfile               # Backend container
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/         # React components
β”‚   β”‚   β”œβ”€β”€ pages/              # Page components
β”‚   β”‚   └── hooks/              # Custom React hooks
β”‚   β”œβ”€β”€ package.json            # Node.js dependencies
β”‚   └── Dockerfile              # Frontend container
└── docker-compose.yaml         # Multi-container setup

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -m 'Add feature'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request

πŸ“ License

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


Happy Chatting! πŸŽ‰