Learnixo
All Projects
Backendintermediate View on GitHub

ChatStream

Real-time group chat with SignalR — rooms, presence, message history, typing indicators

2–3 hours to set up8 technologies4 guided steps

About This Project

A production real-time chat system built with ASP.NET Core SignalR. Features group chat rooms, online presence tracking, typing indicators, message history with cursor pagination, message delivery acknowledgement, and Redis backplane for horizontal scaling. Shows the correct patterns for multi-server SignalR deployments.

What You'll Learn

Build a typed SignalR hub with strongly-typed client contracts
Track presence with Redis sorted sets and heartbeat expiry
Configure the Redis backplane for multi-instance deployments
Implement cursor pagination for message history
Handle reconnection and missed message replay correctly

Key Features

Typed SignalR hub: IChatClient interface for strongly-typed client calls
Room-based group messaging — join/leave with member count broadcast
Online presence via Redis sorted sets with heartbeat expiry
Typing indicator: debounced client event, broadcast to room members
Message history with cursor-based pagination (no offset pagination)
Message delivery acknowledgement — client confirms receipt
MessagePack binary protocol — 30–40% smaller payload than JSON
Redis backplane — works correctly with multiple API instances
JWT authentication on WebSocket upgrade request
Reconnection logic: client replays missed messages using last-seen message ID

Project Structure

directory tree
ChatStream/
├── src/
│   ├── ChatStream.Api/           # SignalR hub, REST endpoints, DI
│   ├── ChatStream.Application/   # Message commands, presence service
│   ├── ChatStream.Domain/        # Room, Message, Participant entities
│   └── ChatStream.Infrastructure/ # EF Core, Redis presence, backplane
├── tests/
│   └── ChatStream.Integration/   # Hub integration tests with TestServer
├── test-client/
│   └── index.html                # Browser-based test client
└── docker-compose.yml

Setup Guide

1

Clone and start infrastructure

Start PostgreSQL and Redis via Docker Compose.

bash
git clone https://github.com/asmanasir/ChatStream.git
cd ChatStream
docker-compose up -d
2

Run migrations and seed rooms

Create the messages schema and seed two default chat rooms.

bash
dotnet ef database update
dotnet run --project src/ChatStream.Api -- --seed

Running the Project

1

Run the API

Start the API. Connect to /hubs/chat with a SignalR client.

bash
dotnet run --project src/ChatStream.Api
2

Connect with the test client

Open the included HTML test client to send and receive messages.

javascript
# Open test client in browser
open http://localhost:5000/test-client

# Or connect via the @microsoft/signalr JS client:
const conn = new HubConnectionBuilder()
  .withUrl("/hubs/chat?access_token=<jwt>")
  .withHubProtocol(new MessagePackHubProtocol())
  .withAutomaticReconnect()
  .build();
await conn.start();
await conn.invoke("JoinRoom", "general");

Project Info

CategoryBackend
Difficultyintermediate
Setup time2–3 hours to set up
Technologies8 tools

Tech Stack

ASP.NET Core (.NET 9)SignalRRedis (backplane + presence)EF CorePostgreSQLJWTMessagePackDocker

Prerequisites

  • .NET 9 SDK installed
  • Docker Desktop installed
  • Basic understanding of WebSockets or SignalR
View Source on GitHub
L

Learnixo

Project Author

Most SignalR tutorials run on a single server and break the moment you add a second instance. ChatStream starts with the Redis backplane and shows the presence, typing, and reconnection patterns that actually work in production.