A simple messenger application built using FastAPI (backend), React (frontend), and Aiogram (Telegram bot). The application allows users to register, send/receive messages in real-time, and receive notifications through a Telegram bot when they are offline.
-
User Registration and Authentication:
- Users can register new accounts.
- Authentication and authorization are handled through FastAPI for secure access to the API.
-
Sending and Receiving Messages:
- Users can send and receive messages in real time via WebSocket.
- Message delivery and retrieval occur instantly.
-
Message History:
- All messages are saved in the database.
- Users can access the history of their conversations with others.
-
Telegram Bot Notifications:
- A simple Telegram bot built with Aiogram is used to notify users about new messages if they are offline.
-
Web Interface:
- A basic web page created with React allows users to interact with the service.
- The web page supports sending and receiving messages in real time.
-
Docker Compose for Easy Setup:
- The project is fully containerized using Docker Compose, making it easy to run and test.
src/
├── backend/ # FastAPI backend for handling API requests
├── frontend/ # React frontend for the web interface
└── telegram_bot/ # Aiogram-based Telegram bot for notifications
The backend is built using FastAPI and exposes a set of APIs for user registration, authentication, sending/receiving messages, and retrieving message history.
API Documentation:
Once the backend is running, the full API documentation is available at /api/docs
(Swagger UI) or /api/redoc
(ReDoc).
The frontend is built using React. It provides a simple interface for registering, logging in, and sending/receiving messages.
The Telegram bot, built using Aiogram, sends notifications to users if they are offline when new messages are received.
The application uses a PostgreSQL database to store:
- User data (registration/authentication details)
- Message history
This project uses Docker Compose to orchestrate the backend, frontend, database, and Telegram bot. Ensure you have Docker and Docker Compose installed.
-
Clone the repository:
git clone https://github.com/witelokk/messenger cd messenger
-
Build and run the application: Run the following command in the project root directory to start all services:
POSTGRES_USERNAME=... POSTGRES_PASSWORD=... BOT_TOKEN=... BOT_USERNAME=... docker-compose up --build
This command will start:
- FastAPI backend at
http://0.0.0.0:80/api
- React frontend at
http://0.0.0.0:80/
- PostgreSQL database
- Redis instance
- Telegram bot
- FastAPI backend at
-
Setup Telegram Bot:
- Create a bot on Telegram using BotFather and get the API token.
- Add the token to the
.env
file in thesrc/telegram_bot
folder. - The bot will notify users of any new messages when they are offline.
-
Sessions:
POST /sessions/
: Login, returns a session token.
-
Users:
POST /users/
: Register a new user.GET /users/username/{username}
: Get user by username (auth required).GET /users/{user_id}
: Get user by ID (auth required).DELETE /users/{user_id}
: Delete user by ID (auth required).
-
Messages:
POST /messages/
: Send a message (auth required).GET /messages/to/{to_id}
: Get messages sent to a specific user (auth required).
-
Chats:
GET /chats/
: Get a list of chats (auth required).
-
WebSocket:
GET /websocket
: Real-time messaging via WebSocket (auth required).
-
Telegram:
POST /tg_key
: Create a Telegram integration key (auth required).
For more details, see /api/docs
.
To run individual components outside of Docker (e.g., for development):
- Navigate to the backend directory:
cd src/backend
- Install dependencies using Poetry:
poetry install
- Setup .env (see .env.example)
- Start the FastAPI development server:
poetry run uvicorn app.main:app --reload
- Navigate to
src/frontend
. - Install dependencies:
npm install
- Setup .env (see .env.example)
- Start the React app:
npm start
- Navigate to the bot directory:
cd src/telegram_bot
- Install dependencies using Poetry:
poetry install
- Setup .env (see .env.example)
- Start the Telegram bot:
poetry run python bot.py