{"id":19296989,"url":"https://github.com/say8hi/websocket-chat","last_synced_at":"2026-01-31T11:02:13.010Z","repository":{"id":258767390,"uuid":"875256207","full_name":"say8hi/websocket-chat","owner":"say8hi","description":"Realtime chat","archived":false,"fork":false,"pushed_at":"2024-11-04T14:52:56.000Z","size":132,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-01T06:03:04.014Z","etag":null,"topics":["alembic","async","celery","chat","docker","docker-compose","fastapi","nginx","postgresql","python","sqlalchemy","websocket"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/say8hi.png","metadata":{"files":{"readme":".github/README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-19T13:57:57.000Z","updated_at":"2024-11-12T17:41:05.000Z","dependencies_parsed_at":"2025-04-12T05:43:20.703Z","dependency_job_id":null,"html_url":"https://github.com/say8hi/websocket-chat","commit_stats":null,"previous_names":["say8hi/websocket-chat"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/say8hi/websocket-chat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fwebsocket-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fwebsocket-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fwebsocket-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fwebsocket-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/say8hi","download_url":"https://codeload.github.com/say8hi/websocket-chat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/say8hi%2Fwebsocket-chat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28939490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T10:18:23.202Z","status":"ssl_error","status_checked_at":"2026-01-31T10:18:22.693Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alembic","async","celery","chat","docker","docker-compose","fastapi","nginx","postgresql","python","sqlalchemy","websocket"],"created_at":"2024-11-09T23:01:04.741Z","updated_at":"2026-01-31T11:02:12.989Z","avatar_url":"https://github.com/say8hi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chat Application\n![Logo](./logo.jpg)\n\nThis is a real-time chat application built using FastAPI for the backend and React for the frontend. The application supports WebSocket communication for real-time messaging, with PostgreSQL for data storage and Redis for caching.\n\n## Table of Contents\n\n- [Features](#features)\n- [Architecture](#architecture)\n- [Getting Started](#getting-started)\n- [Project Structure](#project-structure)\n- [Environment Variables](#environment-variables)\n- [Docker Setup](#docker-setup)\n- [Usage](#usage)\n- [License](#license)\n\n## Features\n\n- Real-time messaging using WebSockets\n- User registration and authentication\n- Message history retrieval\n- Caching of messages using Redis\n- Telegram bot integration for notifications\n- Migrations with alembic\n\n## Architecture\n\nThe application consists of several components:\n\n- **Backend (FastAPI)**: Handles API requests, manages WebSocket connections, and interacts with the database.\n- **Frontend (NodeJs)**: Provides the user interface for users to send and receive messages.\n- **Database (PostgreSQL)**: Stores user data and chat messages.\n- **Redis**: Caches messages for faster retrieval.\n- **Nginx**: Serves as a reverse proxy for the frontend and backend services.\n- **Celery**: Handles asynchronous tasks, such as sending notifications or processing messages.\n- **Telegram Bot**: Notifies users of new messages or events.\n\n## Getting Started\n\n### Prerequisites\n\n- Docker\n- Docker Compose\n\n### Clone the Repository\n\n```bash\ngit clone https://github.com/say8hi/websocket-chat.git\ncd websocket-chat\n```\n### Setup Environment Variables\n\nRename a `.env.example` to `.env` in the root directory and set the following variables::\n\n```env\n# Postgres\nPOSTGRES_HOST=db\nPOSTGRES_PORT=5432\nPOSTGRES_USER=db_user\nPOSTGRES_PASSWORD=db_pass\nPOSTGRES_DB=db_name\n\n# Redis\nREDIS_HOST=redis\nREDIS_PORT=4030\nREDIS_PASSWORD=redis_pass\n\n# Tg bot\nBOT_TOKEN=bot_token\nADMINS=admin_id,admin_id\nBOT_USERNAME=username_bot\n\n# Secrets\nAUTH_SECRET=secret_key\n```\n\n### Docker Setup\n\nTo run the application using Docker, execute the following command in the project root directory:\n\n```bash\ndocker-compose up -d --build\n```\nThis command will:\n- Build all the services defined in `docker-compose.yml`.\n- Start the backend, frontend, database, Redis cache, Nginx, Celery worker, and Telegram bot.\n\n## Project Structure\n```\n/websocket-chat\n│\n├── backend                        # FastAPI backend code\n│   ├── api                        # API routers for chat and user management\n│   │   ├── chat.py                # Chat-related API endpoints\n│   │   ├── __init__.py            # Package initializer\n│   │   └── users.py               # User-related API endpoints\n│   ├── config.py                  # Application configuration\n│   ├── database                   # Database models and ORM setup\n│   │   ├── database.py            # Database connection logic\n│   │   ├── models.py              # SQLAlchemy models for users and messages\n│   │   └── orm.py                 # Async ORM operations\n│   ├── Dockerfile                 # Dockerfile for the backend\n│   ├── main.py                    # Application entry point\n│   ├── misc                       # Miscellaneous utilities\n│   │   └── connection_manager.py  # WebSocket connection manager\n│   ├── requirements.txt           # Python dependencies\n│   ├── schemas                    # Pydantic models for request and response validation\n│   │   ├── messages.py            # Message-related Pydantic models\n│   │   ├── users.py               # User-related Pydantic models\n│   └── utils                      # Utility functions for authentication and caching\n│       ├── auth.py                # Functions for user authentication\n│       └── cache.py               # Functions for caching with Redis\n│\n├── celery                         # Celery worker code for asynchronous tasks\n│   ├── app.py                     # Celery application setup\n│   ├── tasks.py                   # Task definitions\n│   ├── Dockerfile                 # Dockerfile for the Celery worker\n│   └── requirements.txt           # Python dependencies for Celery\n│\n├── frontend                       # React frontend code\n│   ├── Dockerfile                 # Dockerfile for the frontend\n│   ├── package.json               # Node.js dependencies\n│   ├── public                     # Static files for React\n│   │   ├── index.html             # Main HTML file\n│   │   ├── script.js              # JavaScript entry point\n│   │   └── style.css              # Stylesheet\n│   └── server.js                  # Express server for the frontend\n│\n├── nginx                          # Nginx configuration for reverse proxy\n│   ├── default.conf               # Nginx configuration file\n│   └── Dockerfile                 # Dockerfile for Nginx\n│\n├── tg_bot                         # Telegram bot code\n│   ├── bot.py                     # Main bot logic\n│   ├── config.py                  # Bot configuration\n│   ├── Dockerfile                 # Dockerfile for the bot\n│   ├── filters                    # Filters for processing messages\n│   ├── handlers                   # Handlers for various bot commands\n│   ├── keyboards                  # Custom keyboards for Telegram interactions\n│   ├── middlewares                # Middleware for bot processing\n│   ├── requirements.txt           # Python dependencies for the bot\n│   ├── states                     # State management for bot conversation\n│   └── utils                      # Utility functions for bot operations\n│\n├── migrations                     # Database migration scripts\n│   ├── env.py                     # Migration environment setup\n│   ├── versions                   # Individual migration versions\n│   └── script.py.mako             # Migration script template\n│\n├── alembic.ini                    # Alembic configuration for database migrations\n├── docker-compose.yml             # Docker Compose configuration\n├── README.md                      # Project documentation\n└── .env                           # Environment variables\n```\n## Environment Variables\n\nThe application relies on the following environment variables defined in the `.env` file:\n\n- `POSTGRES_HOST`: Name of the PostgreSQL database service in the `docker-compose.yml`.\n- `POSTGRES_PORT`: Port of the PostgreSQL database service in the `docker-compose.yml`.\n- `POSTGRES_DB`: Name of the PostgreSQL database.\n- `POSTGRES_USER`: PostgreSQL user.\n- `POSTGRES_PASSWORD`: PostgreSQL password.\n- `REDIS_HOST`: Name of the Redis service in the `docker-compose.yml`.\n- `REDIS_PORT`: Port of the Redis service in the `docker-compose.yml`.\n- `REDIS_PASSWORD`: Password for Redis.\n- `BOT_TOKEN`: Bot token from the [@botfather](https://t.me/botfather).\n- `ADMINS`: Telegram ids of admins for the bot.\n- `BOT_USERNAME`: Username of the bot (for creating links like https://t.me/{bot_username}).\n- `AUTH_SECRET`: Secret key for JWT authentication.\n\n## Usage\n\nOnce the services are up and running, you can access the application at:\n- **Nginx**: [http://localhost:80](http://localhost:80)\n\nWithout proxy:\n- **Frontend**: [http://localhost:3000](http://localhost:3000)\n- **Backend API**: [http://localhost:8000](http://localhost:8000)\n\n### Accessing the Database\n\nYou can connect to the PostgreSQL database using a client like pgAdmin or any SQL client using the following credentials:\n\n- **Host**: `localhost`\n- **Port**: `\u003cport_from_the_docker_compose.yml (5432 by default)\u003e`\n- **Database**: `\u003cyour_db_name\u003e`\n- **User**: `\u003cyour_db_user\u003e`\n- **Password**: `\u003cyour_db_password\u003e`\n\n### Interacting with the API\n\nAlso all endpoints can be found here: [http://localhost:8000/docs](http://localhost:8000/docs)\nThe backend API supports several endpoints for user management and messaging. Here are some key endpoints:\n\n#### User Registration\n\n- **Endpoint**: `POST /users/register`\n- **Body**: \n    ```json\n    {\n        \"username\": \"your_username\",\n        \"password\": \"your_password\"\n    }\n    ```\n- **Response**: \n    ```json\n    {\n        \"status\": \"string status\"\n        \"data\": {\n            \"token\": \"jwt token\"\n            \"user_id\": \"user_id\"\n        }\n    }\n    ```\n\n#### User Login\n\n- **Endpoint**: `POST /users/login`\n- **Body**: \n    ```json\n    {\n        \"username\": \"your_username\",\n        \"password\": \"your_password\"\n    }\n    ```\n- **Response**: \n    ```json\n    {\n        \"status\": \"string status\"\n        \"data\": {\n            \"token\": \"jwt token\"\n            \"user_id\": \"user_id\"\n        }\n    }\n    ```\n#### Get all users\n\n- **Endpoint**: `GET /users/`\n- **Headers**:\n  ```json\n  {\n    \"Authorization\": \"Bearer {jwt_token}\",\n  }\n  ```\n- **Body**: \n    ```json\n    {\n        \"username\": \"your_username\",\n        \"password\": \"your_password\"\n    }\n    ```\n- **Response**: \n    ```json\n    {\n      [\n        {\"id\": 1, \"username\": \"username\"...},\n        {\"id\": 2, \"username\": \"username2\"...}\n      ]\n    }\n    ```\n#### Connect telegram account\n\n- **Endpoint**: `POST /users/connect-tg`\n- **Body**: \n    ```json\n      {\n        \"user_id\": 0,\n        \"tg_user_id\": 0\n      }\n    ```\n- **Response**: \n    ```json\n    {\n      \"status\": \"string\",\n      \"data\": {}\n    }\n    ```\n#### Websocket for live-chatting\n- **Endpoint**: `/chat/ws/{sender_id}/{receiver_id}`\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsay8hi%2Fwebsocket-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsay8hi%2Fwebsocket-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsay8hi%2Fwebsocket-chat/lists"}