Skip to content

mohammadbashibdar/Chat-Fastapi-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Real-Time Chat Backend with FastAPI & WebSockets

This is a backend-only real-time chat API built using Python, FastAPI, and WebSockets.
All endpoints are available and testable via Swagger UI.


πŸ”§ Features

  • ⚑ Real-time communication via WebSocket
  • 🧱 Fully backend-based (no frontend required)
  • πŸ“„ Interactive API docs using Swagger (OpenAPI)
  • πŸ‘₯ Multi-user chat logic ready to integrate with any frontend
  • πŸ” User-based room creation, private chat & messaging

πŸ“¦ Tech Stack

  • Python 3.10+
  • FastAPI
  • WebSockets (fastapi.websockets)
  • Uvicorn (ASGI Server)

πŸš€ Getting Started

πŸ”§ Install dependencies

It is recommended to use a virtual environment:

git clone https://github.com/mohammadbashibdar/Chat-Fastapi-.git
cd Chat-Fastapi-
python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
pip install -r requirements.txt

▢️ Run the server

fastapi dev --host 0.0.0.0 app/main.py

Then open http://localhost:8000/docs in your browser.

πŸ”Œ WebSocket Endpoint

ws://localhost:8000/ws/chat/{room_id}

Example message:

{
  "sender_id": 1,
  "room_id": "general",
  "message": "Hello, world!"
}

πŸ“ Project Structure

.
β”œβ”€β”€ main.py
β”œβ”€β”€ models/
β”œβ”€β”€ schemas/
β”œβ”€β”€ services/
β”œβ”€β”€ crud/
β”œβ”€β”€ requirements.txt
└── README.md



πŸ“š API Endpoints

Here are the available endpoints for managing chat rooms and messages:

Method	    Endpoint	                       Description
POST	    /chat/room/create  	               Create Chat Room
PUT	    /chat/room/addMember	       Add Member To Chatroom
DELETE	    /chat/room/removeMember	       Remove Member From Chatroom
POST	    /chat/sendMessage	               Send Message
GET	    /chat/chatRoom	               Get All Chatrooms
GET	    /chat/room/{room_id}/message       Get Messages in Chatroom
GET	    /chat/room/{room_id}/info	       Get Room Info
GET	    /chat/message/{message_id}	       Get Single Message
POST	    /chat/startChatWithUser	       Start One-on-One Chat
GET	    /chat/chatRoomWithUser/{user_id}   Get Private Chatroom With User
GET	    /chat/users/{queryString}	       Search Users by Query


πŸ’‘ Notes

    This is a backend-only implementation. You can connect your own frontend (React, Vue, Flutter, etc.).

    Swagger UI is included for easy interaction with endpoints.

    Authentication & permissions are supported.

    Open for contributions or ideas!

πŸ“« Contact

Made with ❀️ by Mohammad Bashibdar


# Mohammad Bashibdar
# 2025, IRAN

Releases

No releases published

Packages

No packages published

Languages