A real-time chat system inspired by WhatsApp architecture, using MQTT for message delivery and ScyllaDB for persistence.
- Go - Backend language
- MQTT (Mosquitto) - Real-time message broker
- WebSocket - Client-server bidirectional communication
- ScyllaDB - High-performance NoSQL for message storage
- PostgreSQL - Relational database for users and groups
- JWT - Token-based authentication
- Docker - Containerization
gorilla/websocket- WebSocket implementationeclipse/paho.mqtt.golang- MQTT clientgo-chi/chi- HTTP routergorm- ORM for PostgreSQLgocql- ScyllaDB driver
- User signs up or logs in via REST API
- Server generates JWT token and sets it as HTTP-only cookie
- Token is used for both REST API and WebSocket authentication
- Client connects to
/wswith JWT cookie - Server validates token and extracts user ID
- Server subscribes user to their private MQTT topic (
user/{id}/inbox) - Connection stays open for real-time messaging
park/
├── cmd/api/main.go # Application entry point
├── internal/
│ ├── api/
│ │ ├── server.go # HTTP server and routes
│ │ ├── handlers/ # Request handlers
│ │ │ ├── user_handler.go # Auth endpoints
│ │ │ ├── group_handler.go # Group CRUD
│ │ │ └── chat_handler.go # Chat logic
│ │ └── middleware/ # Auth, JSON middleware
│ ├── models/ # Data models
│ ├── repository/ # Database operations
│ ├── realtime/
│ │ ├── mqtt.go # MQTT client
│ │ ├── ws.go # WebSocket handler
│ │ └── ws_middleware.go # WebSocket auth
│ ├── storage/ # Database connections
│ └── utils/ # JWT, hashing utilities
├── pkg/types/ # Shared types
├── docker-compose.yml
└── mosquitto/mosquitto.conf
- Docker & Docker Compose
- Go 1.21+ (for local development)
git clone https://github.com/YacineMK/park.git
cd park
cp .env.example .env
docker-compose up --buildPOSTGRES_DSN="host=pg user=parkuser password=parkpassword dbname=parkdb port=5432 sslmode=disable"
SCYLLA_KEYSPACE="park_keyspace"
SCYLLA_CLUSTER_IP="scylla"
PORT="8080"
JWT_SECRET="your_secret_key"
MQTT_BROKER="tcp://mqtt:1883"MIT