Skip to content

shawnfeds/SignalRChatApp

Repository files navigation

SignalR Chat App

A real-time chat application built with ASP.NET Core and SignalR, designed for local-network use. Features broadcast messaging, private direct messages, multi-room support, typing indicators, and automatic reconnection — all with a polished dark-mode UI.


Tech Stack

.NET SignalR Docker CI License


Features

Feature Detail
Real-time messaging WebSocket-based broadcast via SignalR
Private messages Direct peer-to-peer messaging within a session
Multi-room support Create or join any room by name at login
Typing indicators Live per-user typing state broadcast to the room
Auto-reconnect Exponential back-off reconnection with UI feedback
Morse code encoder Encode / decode your message text before sending
Theme switcher 9 Bootstrap themes + dark/light mode toggle
Docker support Single-image deployment via docker-compose
Structured logging Serilog with console sink for all hub events

Architecture & Design Decisions

Browser (Vanilla JS + SignalR client)
       │
       │  WebSocket / Long-polling (auto-negotiated)
       ▼
ASP.NET Core 10 (MVC + SignalR Hub)
  ├── ChatHub          — connection lifecycle, rooms (Groups), typing, messaging
  ├── HomeController   — serves chat view with username + room context
  ├── LoginController  — serves the login landing page
  └── Serilog          — structured console logging

Key design choices:

  • Session-only messages — No database. Messages exist only for the duration of the browser session. This is intentional for a local-network environment where persistence is not required and simplicity is preferred.
  • Server-side Groups — Rooms are implemented using SignalR's built-in Groups API. Messages are scoped to a group; the server never broadcasts to unintended clients.
  • Thread-safe stateConcurrentDictionary is used for all shared connection state to handle concurrent hub invocations safely.
  • XSS prevention — All user-supplied strings rendered in the browser are escaped via document.createTextNode, not innerHTML.

Getting Started

Prerequisites

Run with dotnet

git clone https://github.com/shawnfeds/SignalRChatApp.git
cd SignalRChatApp
dotnet run

Open your browser at https://localhost:7XXX (port shown in the console).
Enter your name and a room name, then click Join Chat.

Local network: other devices on the same network can connect using your machine's IP address and the app's port.

Run with Docker

docker-compose up --build

App will be available at http://localhost:8080.


How to Use

  1. Join — Enter your name and a room (e.g. General, Team-A). Any room name creates or joins that room.
  2. Broadcast — Leave the recipient as Everyone in room and type your message.
  3. Private message — Select a specific user from the recipient dropdown (shown with 🔒).
  4. Morse code — Click the icon in the compose area to toggle Morse encoding/decoding of your message text before sending.
  5. Switch themes — Use the Theme menu in the header to apply one of 9 Bootstrap themes.

Project Structure

SignalRChatApp/
├── ChatHub.cs              # SignalR hub — rooms, messaging, typing
├── Controllers/
│   ├── HomeController.cs   # Chat page controller
│   └── LoginController.cs  # Login page controller
├── Views/
│   ├── Home/Index.cshtml   # 3-panel chat UI
│   ├── Login/Index.cshtml  # Glassmorphism login card
│   └── Shared/_Layout.cshtml
├── wwwroot/
│   ├── css/site.css        # Custom dark-mode design system
│   └── js/
│       ├── chat.js         # SignalR client — reconnect, typing, rooms
│       ├── morseCode.js    # Morse encode/decode
│       └── theme.js        # Bootstrap theme switcher
├── Program.cs              # App bootstrap + Serilog config
├── Dockerfile              # Multi-stage .NET 10 build
└── docker-compose.yml

CI / CD

GitHub Actions runs on every push and pull request to main:

  • dotnet restore
  • dotnet build --configuration Release
  • docker build (Dockerfile validation)

See .github/workflows/ci.yml.


Roadmap

  • JWT authentication (replace username query string)
  • Message persistence with Entity Framework Core + SQLite
  • Unit tests for ChatHub with Mock<IHubCallerClients>
  • Integration tests via WebApplicationFactory
  • Mobile-responsive sidebar toggle

License

MIT

About

This repository contains a SignalR-based chat application offering real-time messaging with features like broadcasting, private messages, and customizable themes. Messages are session-based, ensuring privacy and data security. Perfect for exploring SignalR capabilities.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors