Realtime-Chat is a real-time anonymous chat application that lets you create secure, private rooms. It uses WebSockets for real-time messaging and is powered by:
- Backend: FastAPI (Python)
- Frontend: React
- In-memory store: Redis
- Containerization: Docker
- Orchestration: Kubernetes
- Anonymous Chat Room Creation – Generate a room code and share it to start a private conversation.
- Real-Time Messaging – Built with WebSockets for instant communication.
- Auto Reconnection – Automatically reconnects if the WebSocket connection drops.
- Responsive UI – Works seamlessly on desktop and mobile.
- Scalable – Leverages Docker and Kubernetes for horizontal scalability.
- FastAPI – Lightweight, fast, and asynchronous API.
- WebSockets – Real-time communication.
- Redis – Manages state and WebSocket connections.
- React – Interactive and reactive UI.
- Nginx – Web server to serve the frontend.
- Docker – Containerization.
- Kubernetes – Container orchestration.
- GitHub Actions – Automated CI/CD pipeline.
- Docker
- Node.js (v18+)
- Python 3.10+
git clone https://github.com/your-username/realtime-chat.git
cd realtime-chat
cd backend
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
pip install -r requirements.txt
uvicorn main:app --reload --port 8000
The backend will be available at http://localhost:8000
.
cd frontend/chat-frontend
npm install
npm start
The frontend will be available at http://localhost:3000
.
Note: In pure local development mode (no Kubernetes), ensure the frontend’s WebSocket URL is set to `ws://localhost:8000` (or use a proxy). If you’re using NodePort in Minikube, please refer to the Kubernetes section below.
docker-compose up --build
- Frontend:
http://localhost:3000
- Backend (API):
http://localhost:8000
This is another straightforward approach for local development without Kubernetes.
- Install Minikube and kubectl.
- Start Minikube:
minikube start
Use the following commands (or a script) to build and push your Docker images to Docker Hub:
# Example using version "2.0" — increment as needed
docker build -t dvgirotto/my-anonymous-chat-backend:2.0 ./backend
docker push dvgirotto/my-anonymous-chat-backend:2.0
docker build -t dvgirotto/my-anonymous-chat-frontend:2.0 ./frontend
docker push dvgirotto/my-anonymous-chat-frontend:2.0
Inside the k8s/
directory, apply the YAML files:
kubectl apply -f k8s/
- This will create: backend-deployment and backend-service (NodePort) frontend-deployment and frontend-service (LoadBalancer or NodePort) redis-deployment and redis-service (ClusterIP)
Point your Deployment to the new tags (e.g., 2.0):
kubectl set image deployment/backend-deployment \
backend=dvgirotto/my-anonymous-chat-backend:2.0
kubectl set image deployment/frontend-deployment \
frontend=dvgirotto/my-anonymous-chat-frontend:2.0
# Watch the rollout status
kubectl rollout status deployment/backend-deployment
kubectl rollout status deployment/frontend-deployment
Run:
minikube service frontend-service --url
Example output:
http://192.168.49.2:32000
Open http://192.168.49.2:32000
in your browser.
The CI/CD pipeline is configured in .github/workflows/ci-cd.yaml
to:
- Build and Push Docker images (frontend/backend) to Docker Hub.
- Automatic Deployment to Kubernetes after merging to the
main
branch (optional, if you have the appropriate credentials set up).
- Fork this repository.
- Create a new branch:
git checkout -b feature/new-feature
- Commit your changes:
git commit -m "feat: add new feature"
- Push to the branch:
git push origin feature/new-feature
- Open a Pull Request.
This project is licensed under the MIT License. Feel free to modify and use it!