# keisoft.chat.server
**Repository Path**: keisoft/keisoft.chat.server
## Basic Information
- **Project Name**: keisoft.chat.server
- **Description**: 通信是管道,业务是大脑: 一种优雅的 .NET 即时通讯系统。ommunication is the pipeline, business is the brain: An elegant .NET instant messaging system.
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 1
- **Created**: 2026-08-30
- **Last Updated**: 2026-09-28
## Categories & Tags
**Categories**: Uncategorized
**Tags**: IM, 即时通讯, 聊天应用, 微服务
## README
KeiChat — A Distributed Instant Messaging System with Complete Separation of Communication and Business Logic
"Communication is the pipeline, business is the brain" — A layered, decoupled distributed architecture
**English** | [简体中文](README.md)
---
## 📖 Project Introduction
**KeiChat** is a communication system solution that has undergone years of iteration and has been validated in production environments. The project started in **2018**, initially serving as the core engine of an enterprise's internal communication tool, supporting the reliable delivery of massive volumes of messages and complex business scenarios. It is not an architectural design achieved overnight; rather, it is a mature solution refined through multiple refactorings alongside business growth and technological evolution.
In terms of architectural design, this project strictly adheres to the principle of **"separation between the business domain and real-time communication (the communication foundation)"**. Infrastructure concerns such as persistent connection management and message routing are completely decoupled from the core business domain models. The communication foundation is a self-developed, high-performance instant messaging engine focused on solving the hardcore problems of high-concurrency persistent connection management and real-time message routing — benchmarked against communication-foundation capabilities that support tens of millions of concurrent online users. The business domain layer, on the other hand, is a complete social business matrix built on the .NET 9 microservices architecture, covering the full spectrum of scenarios including user relationship chains, group-based social networking, content ecosystem, and security risk control.
This layered architecture enables us to achieve the following — the communication layer pursues ultimate stability and low latency, while the business layer maintains an agile product iteration pace. The two collaborate in a loosely coupled manner through event-driven mechanisms, which not only safeguards the overall system SLA but also reserves ample architectural flexibility for future feature expansion. Based on this principle, the entire backend system is split into two independent source code repositories:
- 📐 **Business Domain (this repository)**: Serving as the system's **business layer**, it consists of 8 .NET 9 WebAPI microservices responsible for all complex business logic and data persistence, including users, relationship chains, content, files, and security auditing. The business layer can iterate flexibly without affecting the stability of persistent connections.
- 📡 **Communication Foundation (https://gitee.com/keisoft/keisoft.im)**: Serving as the system's **access layer**, it focuses on maintaining massive numbers of TCP persistent connections, heartbeat keep-alive, message reception, and routing/forwarding, without any business logic mixed in.
> KeiChat System Architecture Diagram

---
## ✨ Microservices Overview
- 🔑 **Captcha Service**: Captcha sending, security verification, and anti-abuse protection.
- 🙍♂️ **User Service**: Registration and login, profile editing, password reset, status synchronization.
- 👨👧 **Friend Relationship Service**: Search, friend requests, accept/reject, friend list management, friend info management, blacklist management.
- 👨👩👧 **Group Service**: Create groups, invite/remove members, mute group members, assign administrators, permission control, publish group announcements, edit group info.
- ⭐ **Personal Favorites Service**: Favorite messages/Images/links management, stickers, content retrieval.
- 🌈 **Moments Service**: Post publishing, likes, comments, timeline aggregation.
- 📁 **File Service**: Upload, transcoding, and object-storage distribution of Images, videos, and documents.
- 🛡️ **Risk Control Service**: Sensitive-word interception and filtering for message content and Moments content.
---
## 📈 Stress Test Report of Business Modules

---
## 🖥️ Admin Console Feature Overview
- 📊 **Dashboard**: Real-time statistics of total users, online user count, and message throughput.
- 🙍♂️ **User Management**: View user info, ban/unban/delete accounts.
- 👨👩👧 **Group Management**: View group info, ban groups that violate policies.
- 🛡️ **Risk Control Management**: Sensitive word library, interception log records, violating content traceability and cleanup.
- ⚙️ **System Management**: Client list, certificate list, system notifications, system administrators.
---
## 🖼️ Selected Admin Console Screenshots



---
## 🛠️ Tech Stack
- **Development Framework**: .NET 9
- **Architecture Pattern**: Microservices
- **Service Communication**: RESTful API, TCP Socket (communication foundation)
- **Data Storage**: MySQL or SQL Server
- **Cache**: Redis
- **Object Storage**: MinIO
- **Reverse Proxy**: Nginx
- **Containerization**: Docker, Docker Compose
----
## 🧪 Development Environment Requirements
- Windows 10/11
- Visual Studio 2022+
---
## 🚀 One-Click Deployment (Docker Compose)
#### 1. Quick Start
- 📦 Install [Docker](https://www.docker.com/) and [Docker Compose](https://docs.docker.com/compose/)
- 💡 Make sure the default `TCP communication service` port `18168` is not occupied (you can also specify a different port in docker-compose.yml).
- ⚠️ Before deployment, you must modify the following configurations in `docker-compose.yml`:
| Configuration Item | Service | Description |
| ------------------------------- | ------------------------- | ------------------------------------ |
| `EmailOptions__SmtpServer` | keisoft-chat-captcha | Set the mail server address |
| `EmailOptions__SenderEmail` | keisoft-chat-captcha | Set the sender email address |
| `EmailOptions__SenderName` | keisoft-chat-captcha | Set the sender display name |
| `EmailOptions__SmtpUsername` | keisoft-chat-captcha | Set the mail server username |
| `EmailOptions__SmtpPassword` | keisoft-chat-captcha | Set the mail server password |
| `BrowseUrl` | keisoft-chat-picture-file | Set the image file preview URL |
| `BrowseUrl` | keisoft-chat-video-file | Set the video file preview URL |
| `BrowseUrl` | keisoft-chat-common-file | Set the general file preview URL |
```bash
# 1. Clone the repository
git clone https://gitee.com/keisoft/keisoft.chat.server.git
cd Keisoft.Chat.Server
# 2. Start all services with one command (run in background)
docker compose up -d
```
#### 2. Nginx Configuration (`nginx.conf`)
- Modify the domain names or certificates in configuration files such as `Gateways/Keisoft.Chat.Gatewa.nginx.conf`, `Keisoft.Chat.Admin.App/nginx.conf`, and `Files/minio-preview-nginx.conf`, then include them in `nginx.conf`.
```nginx
http
{
# General API: 200 requests per second, burst 400 (sufficient for normal high concurrency)
limit_req_zone $binary_remote_addr zone=api_general:20m rate=200r/s;
# Concurrent connection limit: max 30 simultaneous connections per IP
limit_conn_zone $binary_remote_addr zone=api_conn:10m;
# MinIO cache pool
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=minio_cache:100m
inactive=24h max_size=10g use_temp_path=off;
# MinIO download rate limiting: 10 requests per second per IP
limit_req_zone $binary_remote_addr zone=minio_download:10m rate=10r/s;
# MinIO connection limit: max 20 concurrent connections per IP
limit_conn_zone $binary_remote_addr zone=minio_conn:10m;
server
{
listen 888;
# ... omitted
}
# ... omitted
# Load all KeiChat configuration files
include /www/wwwroot/Keisoft.Chat/Gateways/Keisoft.Chat.Gatewa.nginx.conf;
include /www/wwwroot/Keisoft.Chat/Keisoft.Chat.Admin.App/nginx.conf;
include /www/wwwroot/Keisoft.Chat/Files/Minio.Preview.nginx.conf;
}
```
#### 3. [Deploy the Keisoft.IM Solution](https://gitee.com/keisoft/keisoft.im)
#### 4. Verification
- Open a browser and visit the admin console address after deployment: http://xxx.xxx.xxx.xxx:6800 or the domain bound in `Keisoft.Chat.Admin.App/nginx.conf`.
1. Administrator account: admin
2. Administrator password: abc123
3. If the business gateway or the communication gateway is bound with an SSL/TLS certificate, you need to import the certificate under `System Management / Certificate List`. The client adopts **Certificate Pinning** technology: the client embeds the server's public key fingerprint and performs a strict consistency check during the TLS handshake phase. This completely eliminates HTTPS man-in-the-middle (MITM) packet capture and traffic decryption based on user-installed custom CA certificates, significantly raising the security level of the communication link.
- Set the client's business gateway address to the domain bound in `Keisoft.Chat/Gateways/Keisoft.Chat.Gatewa.nginx.conf`.
- Set the client's communication gateway address to the domain bound in `Keisoft.IM/Keisoft.IM.Http/nginx.conf` ([Code Repository](https://gitee.com/keisoft/keisoft.im)).
```c#
// Chat Server Address.
AppSettings.SetGateway("https://demo-chat.example.com");
// Files Server Address.
AppSettings.SetUploadFileGateway("https://demo-chat.example.com/upload-file");
AppSettings.SetUploadVideoGateway("https://demo-chat.example.com/upload-video");
AppSettings.SetUploadPictureGateway("https://demo-chat.example.com/upload-image");
AppSettings.SetUploadAudioGateway("https://demo-chat.example.com/upload-audio");
AppSettings.SetUploadMergeGateway("https://demo-chat.example.com/upload-merge");
// IM Server Address.
AppSettings.SetIMServerHost("ims://demo-im.example.com");
```
---
## ⚖️ Terms of Use and Disclaimer
**1. Legal Use**: The use of this system is subject to the following conditions: You confirm and agree to use this system solely for lawful purposes and to comply with all applicable laws and regulations, including but not limited to the relevant laws of your jurisdiction, the place where the conduct occurs, and the place of intended impact. You shall not use this system to engage in any activity that infringes upon the lawful rights and interests of others, violates legal provisions, or endangers network security.
> If you violate any of the above conditions, this license terminates immediately, and you must immediately cease using this system and delete all related copies. Any legal liability arising from your breach of this statement shall be borne solely by you, and the project maintainer reserves the right to pursue legal liability.
**2. Open Source Nature**: This project is provided in open source form for the purposes of learning, research, and technical exchange. The developer makes no express or implied warranty as to the functional completeness, security, stability, or fitness of this system for any purpose.
**3. No Warranty**: To the maximum extent permitted by law, the developer shall not be liable for any direct, indirect, incidental, special, or consequential damages arising out of the use of or inability to use this system, including but not limited to data loss, business interruption, or other commercial damages.
**4. Assumption of Risk**: You understand and agree that all risks arising from the use of this system shall be borne by you, including but not limited to system vulnerabilities, third-party dependency risks, and operating environment risks.
**5. Intellectual Property**: The intellectual property rights of this system and its related code and documentation are owned by the **original author**. Without written permission, this system shall not be used for commercial purposes, nor arbitrarily modified or redistributed.
---
## 💬 Technical Exchange Group
Welcome to join the KeiChat technical exchange group to discuss **.NET, WPF, Avalonia, Xamarin, WebRTC, real-time audio & video communication, instant messaging architecture, multi-process design** and other topics 👇

- **QQ Group Number**: 283798566
- **How to Join**: Scan the QR code, or search the group number on QQ to apply
- **Discussion Topics**: .NET, C#, real-time audio & video communication, instant messaging architecture, project issue discussions
> 💡 Friends who do not have QQ can also leave a message under GitHub Issues to communicate.
---
## 📄 License
MIT License
---
⭐ If KeiChat helps you learn instant messaging, feel free to Star and support it!