Skip to content

A scalable, production-ready real-time chat application built with Go backend and JavaScript frontend. Features include real-time messaging, user authentication, comprehensive monitoring, and high availability support.

License

Notifications You must be signed in to change notification settings

AlmirSai/Real-time-Chat-Application

Repository files navigation

Real-time Chat Application

A scalable, production-ready real-time chat application built with Go backend and JavaScript frontend. Features include real-time messaging, user authentication, comprehensive monitoring, and high availability support.

Features

  • Real-time messaging with WebSocket support
  • User authentication and authorization with JWT
  • Message persistence with PostgreSQL
  • High-performance caching with Redis
  • Prometheus metrics and monitoring
  • Docker containerization
  • Kubernetes deployment support
  • Load balancing with Nginx
  • Comprehensive test coverage

Prerequisites

  • Docker
  • Docker Compose
  • Go 1.19 or later (for local development without Docker)
  • Node.js (for local development without Docker)

Quick Start with Docker

  1. Clone the repository

  2. Set up environment variables:

    cd backend
    cp .env.example .env
  3. Start all services:

    make dev

    This will:

    • Build all containers
    • Start PostgreSQL database
    • Start Redis server
    • Launch Backend API server
    • Serve Frontend application
  4. Access the application:

Development

Local Development with Docker

# Install all dependencies
make install-deps

# Start development environment
make dev

# View logs
make logs

# Restart services
make restart

# Run tests
make test

# Run linting
make lint

Development without Docker

  1. Install and start PostgreSQL and Redis locally

  2. Set up environment variables in backend:

    cd backend
    cp .env.example .env
    # Edit .env file with your local configuration
  3. Start the backend server:

    cd backend
    go run cmd/server/main.go
  4. Serve the frontend:

    cd frontend
    npm install
    npm run dev

Production Deployment

Container Registry Setup

  1. Configure container registry credentials
  2. Update deployment configurations in k8s/base/

Kubernetes Deployment

# Deploy to Kubernetes
kubectl apply -k k8s/base

# Check deployment status
kubectl get pods

# View logs
kubectl logs -f deployment/chat-app

Manual Deployment

# Build for production
make prod-build

# Deploy to production
make prod-deploy

# Rollback to previous version
make prod-rollback

Monitoring and Maintenance

Health Checks

  • /health - Application health status
  • /metrics - Prometheus metrics
  • /ready - Kubernetes readiness probe

Logging

# View production logs
make prod-logs

# Check service status
make prod-status

Performance Testing

The project includes k6 load tests and Jupyter notebooks for analysis:

# Run load tests
k6 run tests/load_test_suite.js

# Start Jupyter notebook for analysis
make jupyter
# Access at http://localhost:8888

API Documentation

Authentication

  • POST /api/register - Register a new user

    • Request: {"username": string, "password": string, "email": string}
    • Response: {"token": string}
  • POST /api/login - Login and get JWT token

    • Request: {"username": string, "password": string}
    • Response: {"token": string}

Real-time Communication

  • WS /ws - WebSocket endpoint for real-time chat
    • Authentication: Bearer token in WebSocket handshake
    • Message format: {"type": string, "content": string, "recipient": string}

Monitoring

  • GET /metrics - Prometheus metrics endpoint
  • GET /health - Health check endpoint
  • GET /ready - Readiness probe endpoint

Architecture

Backend

  • Go with Gorilla WebSocket for real-time communication
  • JWT authentication
  • Prometheus metrics collection
  • Structured logging with correlation IDs
  • Rate limiting and circuit breakers

Frontend

  • Vanilla JavaScript
  • Real-time WebSocket client
  • Metrics dashboard
  • Responsive design

Infrastructure

  • PostgreSQL for persistent storage
  • Redis for caching and pub/sub
  • Nginx for load balancing and static file serving
  • Docker containers for consistent environments
  • Health checks for all services
  • Kubernetes for orchestration

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A scalable, production-ready real-time chat application built with Go backend and JavaScript frontend. Features include real-time messaging, user authentication, comprehensive monitoring, and high availability support.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published