This is a backend-only real-time chat API built using Python, FastAPI, and WebSockets.
All endpoints are available and testable via Swagger UI.
- β‘ 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
- Python 3.10+
- FastAPI
- WebSockets (
fastapi.websockets
) - Uvicorn (ASGI Server)
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