Skip to content
/ park Public

A real-time chat system inspired by WhatsApp architecture, built with Go, MQTT for message delivery, WebSocket for client connections

Notifications You must be signed in to change notification settings

YacineMK/park

Repository files navigation

Park - Simple Chat System

A real-time chat system inspired by WhatsApp architecture, using MQTT for message delivery and ScyllaDB for persistence.

Tech Stack

  • 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

Libraries

  • gorilla/websocket - WebSocket implementation
  • eclipse/paho.mqtt.golang - MQTT client
  • go-chi/chi - HTTP router
  • gorm - ORM for PostgreSQL
  • gocql - ScyllaDB driver

How It Works

1. Authentication Flow

  1. User signs up or logs in via REST API
  2. Server generates JWT token and sets it as HTTP-only cookie
  3. Token is used for both REST API and WebSocket authentication

2. WebSocket Connection

  1. Client connects to /ws with JWT cookie
  2. Server validates token and extracts user ID
  3. Server subscribes user to their private MQTT topic (user/{id}/inbox)
  4. Connection stays open for real-time messaging

Project Structure

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

Getting Started

Prerequisites

  • Docker & Docker Compose
  • Go 1.21+ (for local development)

Run with Docker

git clone https://github.com/YacineMK/park.git
cd park
cp .env.example .env
docker-compose up --build

Environment Variables

POSTGRES_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"

License

MIT

About

A real-time chat system inspired by WhatsApp architecture, built with Go, MQTT for message delivery, WebSocket for client connections

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published