DotNetChatServer is a backend for a real time chat application built with ASP.NET Core Minimal APIs.
It handles authentication, user management, message flow, online presence, and long polling updates with a concurrency safe in memory architecture. The project highlights backend engineering techniques such as structured endpoint design, session based security, efficient message delivery, and lock protected data stores.
Note: You may find the complete group project repo (including the frontend client written in C# with Raylib CS) here: CSharp-Raylib-Chat-App.
• Session based authentication token system
• Login and registration flows
• Role based authorization through admin flags
• Automatic token regeneration on login
• Message creation with server generated IDs
• Message history retrieval
• Long polling update channel with efficient wake up notifications
• Admin controlled message clearing
• Full user lifecycle: create, update, delete
• Username management with conflict detection
• Real time presence tracking using heartbeat and activity timestamps
• Admin elevation support
• ReaderWriterLockSlim protected stores
• Asynchronous log writer with file rotation
• Task based long poll notifier
• Clear separation of concerns across endpoints, stores, and services
• Strong OpenAPI and Scalar UI integration
• Interactive API reference available at /scalar
• Custom OpenAPI transformer that describes routes, schemas, and security
• Local development on a clean endpoint structure using Minimal APIs
| Area | Technology |
|---|---|
| Framework | .NET 9, ASP.NET Core Minimal API |
| Documentation | OpenAPI, Scalar UI |
| Concurrency | ReaderWriterLockSlim, TaskCompletionSource |
| Logging | Asynchronous log writer with rotation |
| Data Models | Custom DTOs and in memory stores |
| Deployment Ready | Configurable ports, environment based appsettings |
DotNetChatServer
├── ChatServer
│ ├── Auth
│ ├── Configuration
│ ├── Endpoints
│ ├── Logger
│ ├── Models
│ ├── Services
│ └── Store
└── Shared
├── DTOs
└── Shared.csproj
ChatServer Contains the backend logic, endpoint definitions, stores, and utilities.
Shared Contains DTOs shared between server and possible clients.
All API routes are documented visually at
/scalar (Scalar UI)
and programmatically at
/openapi/v1.json.
• POST /auth/login
• POST /auth/register
• GET /users – list usernames
• POST /users/update – update username and optionally password
• POST /users/delete – remove user
• GET /users/status – list online states
• POST /users/heartbeat – update presence
• POST /messages/send – create message
• GET /messages/history – full or limited history
• GET /messages/updates – long polling endpoint
• POST /messages/clear – admin clear
• GET /system/health – health check for uptime monitors
The server avoids constant polling by pairing:
MessageNotifier Stores a list of TaskCompletionSources that represent waiting clients.
MessageStore.Add Signals all pending long pollers through the notifier.
/messages/updates
Awaits notification or a 25 second timeout.
This creates an efficient real time pipeline for clients.
Both the message store and user store inherit from ConcurrentStoreBase, which wraps all reads and writes in ReaderWriterLockSlim. This ensures:
• Unlimited parallel reads
• Exclusive writes
• Safe multi threaded access
• Clean isolation of locking logic
The custom logger writes asynchronously using a queue. Capabilities include:
• File rotation
• Severity filtering
• Graceful shutdown
• Structured timestamped lines
Logs are stored in the /logs directory.
Run the server on port 5201:
dotnet run --project ChatServer
Navigate to:
• http://localhost:5201/scalar for the interactive API • http://localhost:5201/openapi/v1.json for the raw JSON schema