Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DCS

DCS is an event-driven, horizontally-scalable real-time chat server written in Go. It supports 1:1 direct messages and group chat rooms, fans out messages across multiple server instances using Redis pub/sub, persists messages to PostgreSQL, and tracks user presence.

architecture

Quickstart (dev)

The repository includes a docker-compose.yml that brings up Redis and Postgres for local development. From the repository root run:

docker-compose up -d

Create the database schema:

psql "postgres://admin:admin@localhost:5432/dcs" -f schema.sql

Run server (try multiple with different addr):

go run ./cmd/gateway -addr :5000

Configuration

The gateway accepts the following flags (see cmd/gateway/main.go):

  • -addr : HTTP service address (default :5000)
  • -redis : Redis address for pub/sub (default localhost:6379)
  • -pg : Postgres connection URL (default postgres://admin:admin@localhost:5432/dcs)

API

WebSocket endpoint:

ws://localhost:5000/ws?user=alice

Presence (HTTP) endpoint:

http://localhost:5000/presence?user=alice

Message format (JSON):

  1. Direct message (DM)
{
    "type": "msg",
    "from_user_id": "alice",
    "to_user_id": "bob",
    "room_id": "",
    "body": "welcome"
}
  1. Group chat message
{
    "type": "msg",
    "from_user_id": "alice",
    "to_user_id": "",
    "room_id": "photon",
    "body": "welcome to photon community"
}

Supported type values: msg, join, leave.

Message format for join and leave group chat room(JSON):

{
    "type": "join",
    "from_user_id": "alice",
    "room_id": "photon"
}

Database

Schema is provided in schema.sql. It creates a messages table and indexes used for efficient room and DM queries. Apply it with psql as shown above.

Roadmap

  • JWT auth (replacing ?user=)
  • Missed message replay on reconnect
  • Multi node docker compose deployment

About

Distributed chat server, websocket scaled via redis pub/sub

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages