This project is evolving from a high-performance C++ WebServer into a CLI Instant Messaging (IM) System. The goal is to build a robust, scalable backend using modern C++ standards (C++20) and industry-proven technologies.
- Language: C++20
- Network Model: Linux Epoll (Reactor Pattern)
- Protocol: Google Protobuf (Binary Serialization)
- Database Layer: sqlpp11 (Modern C++ EDSL for SQL - In Transition)
- Concurrency: Thread Pool & MySQL Connection Pool
- Logging: Custom Asynchronous Logging (support for Spdlog format)
- Build System: CMake (Presets) + Vcpkg
- Toolchain: clangd + compile_commands.json
/
├── proto/ # Protocol definitions (.proto files)
├── server/
│ └── src/ # Core Backend Logic
│ ├── main.cpp # Entry point
│ ├── buffer/ # Custom I/O buffer management
│ ├── dao/ # Data Access Objects (Database logic)
│ ├── service/ # Business logic layer (Auth, Chat, Friend, Push, etc.)
│ ├── core/ # Webserver & Epoller (Reactor core)
│ ├── pool/ # ThreadPool & SqlConnPool
│ ├── http/ # HTTP protocol handling (legacy)
│ ├── log/ # Async logging system
│ ├── timer/ # Heap-based timer for timeouts
│ ├── util/ # Utilities (UUID, Token, etc.)
│ └── CMakeLists.txt
├── resources/ # Static assets (HTML, JS, CSS)
├── test/ # Unit tests & Benchmarking
├── build/ # Build artifacts (generated pb files)
├── .devcontainer/ # VS Code DevContainer config
├── vcpkg.json # Dependency management
├── CMakePresets.json # Build presets configuration
└── docker-compose.yml # Multi-container orchestration
After updating the proto files, the project needs to be re-compiled to generate the C++ models.
- Password Encryption: Replace plaintext storage with bcrypt/Argon2 + salt
- JWT Secret Management: Move hardcoded secret to environment variable
- Heartbeat Mechanism: Implement client-server keepalive (PING/PONG)
- Message ID Generator: Implement Snowflake algorithm for distributed unique IDs
- User Online Status: In-memory status map (Partially implemented via
PushService)
- P2P Message Send/Receive: Implement
CMD_P2P_MSG_REQ/CMD_P2P_MSG_PUSH - Message Persistence: Store messages in MySQL/MongoDB
- Message ACK Confirmation: Implement
MessageAcklogic for delivery guarantee - Offline Message Storage: Create offline message table and pull mechanism
- Message Retry: Exponential backoff retry for failed deliveries
- Friend Request Flow: Request → Accept/Reject → Notification
- Friend List: Retrieve friend list
- Friend Management: Remove friend
- User Profile: Status message
- Block User: Implement user blocking functionality
- Master-Slave Reactor: Evolve from single Reactor to multi-Reactor pattern
- Redis Integration: Session management, user routing, online status
- Message Queue: Integrate Kafka/RabbitMQ for async processing
- Multi-Node Deployment: Stateless server + message routing layer
- Load Balancing: Consistent hashing for user-server mapping
- Rate Limiting: Token bucket / Sliding window algorithm
- Circuit Breaker: Graceful degradation under high load
- Monitoring: Prometheus metrics + Grafana dashboards
- Distributed Tracing: Jaeger/Zipkin integration
- Stress Testing: Benchmark with webbench / wrk / custom tools
- Configuration Center: etcd/consul for dynamic config
- User Registration (Protobuf)
- User Login with JWT Token
- Protocol auto-detection (HTTP/Protobuf)
- MySQL Connection Pool
- Thread Pool
- Async Logging System
- Heap-based Timer for Connection Timeout
- Real-time Push Notifications (PushService)
- Friend System (Req/Resp/Push)
This project is configured with a DevContainer. This is the preferred way to develop, as it provides a pre-configured environment with all dependencies (C++20, CMake, Vcpkg, MySQL, etc.).
- Install Docker Desktop.
- Install VS Code and the Dev Containers extension.
- Open this folder in VS Code.
- Click "Reopen in Container" when prompted (or use the command palette:
Dev Containers: Reopen in Container).
Build:
cmake --preset release
cmake --build build/releasecmake --preset debug
cmake --build build/debugEvery time the sql files are changed, the project needs to be re-compiled to generate the C++ models.
Run Server & Test:
./build/debug/server/src/server
./build/release/server/src/server
# Test Auth
python3 tests/test_auth.py [username] [password]
# Test Friend System (including Push)
python3 tests/test_friend.py
# Test P2P Message System
python3 tests/test_message.py
# Run Client (FTXUI)
./build/debug/client/client
./build/release/client/client
# If you want to use db visualization with scylla, run the following commands in devcontainer terminal
apt-get update
apt install openjdk-21-jdkIf you just want to run the server without setting up a development environment:
docker-compose up --buildCode Formatting: Using Google Style for C++: PascalCase for class names and function names, snake_case for variable names.
find server/src tests -name "*.h" -o -name "*.cpp" | xargs clang-format -iNote: The server currently listens on port 1316.