A FastAPI-based real-time chat server built with MySQL and Redis, deployed on Railway. The platform supports JWT-based authentication, WebSocket connections, and a scalable backend architecture.
This system enables: JWT Authentication for secure user access Real-time messaging between users MySQL database for persistent storage Redis for caching and session management Railway deployment with auto-deploy from GitHub
This project demonstrates backend architecture, WebSocket integration, async database management, and cloud deployment.
Technology - Purpose
Python FastAPI - Web Framework MySQL - Relational Database | Redis - Caching / Session Management Uvicorn - ASGI Server Pydantic Settings - Environment Variable Management JWT Authentication Railway - Cloud Deployment
chat-server/ │── app/ │ │── main.py ← FastAPI app entry point │ │── config.py ← Settings & environment variables │ │── database.py ← DB connection pool │ │── models.py ← Database models │ │── routes/ ← API route handlers │ └── utils/ ← Helper functions │── requirements.txt │── Dockerfile └── README.md
- JWT-based login
- Token expiry management
- Secure password hashing
- Real-time messaging
- User-to-user communication
- Message persistence in MySQL
- Session caching
- Fast data retrieval
- Reduced DB load
- Hosted on Railway
- Auto-deploy on GitHub push
- MySQL service linked via Railway Variables
git clone https://github.com/appadilokesh04-source/chat-server.git cd chat-server
pip install -r requirements.txt
Create a .env file in the root directory:
DB_HOST=localhost DB_PORT=3306 DB_USER=root DB_PASSWORD=yourpassword DB_NAME=chatdb SECRET_KEY=your_secret_key ACCESS_TOKEN_EXPIRE_MINUTES=60 REDIS_HOST=localhost REDIS_PORT=6379
uvicorn app.main:app --reload
App runs on: http://127.0.0.1:8000
Once running, visit:
| Page | URL |
|---|---|
| Swagger UI | http://127.0.0.1:8000/docs |
| ReDoc | http://127.0.0.1:8000/redoc |
git add . git commit -m "your message" git push origin main
- Go to Railway dashboard → New Service → Database → MySQL
DB_HOST=${{MySQL.MYSQLHOST}} DB_PORT=${{MySQL.MYSQLPORT}} DB_USER=${{MySQL.MYSQLUSER}} DB_PASSWORD=${{MySQL.MYSQLPASSWORD}} DB_NAME=${{MySQL.MYSQLDATABASE}}
- Go to Settings → Networking → Generate Domain
- FastAPI async routing
- JWT authentication
- MySQL connection pooling
- Redis caching
- Pydantic settings & validation
- Environment-based configuration
- Cloud deployment with Railway
Lokesh Appadi
Backend Developer | DevOps Engineer