How crossoverjie/cim works
Project Type & Purpose
• Type: A modular, full‑stack distributed IM system, composed of multiple Spring Boot microservices and a lightweight CLI client.
• Purpose: Provide an extensible instant‑messaging framework (CIM) with built‑in routing, service registration/discovery, client SDK, and CLI client.
File Structure
• Top‑level modules (Maven subprojects):
– cim-common: shared data structures, ProtoBuf definitions, routing algorithms, MetaStore abstractions.
– cim-client-sdk: Java client SDK exposing APIs for connection, reconnect logic, event handling.
– cim-client: Spring Boot CLI client app using the SDK, handles user input/commands.
– cim-rout-api & cim-server-api: API definitions (VOs, interfaces) for route and server services.
– cim-forward-route: “Route” service—login, routing logic, user management, uses Redis cache.
– cim-server: “IM Server” service—Netty server for persistent connections, message push, heartbeat.
– cim-integration-test: integration tests wiring up route + server + client SDK.
• Infrastructure/config:
– script/…: build & deploy scripts.
– .github/workflows: CI runs Maven tests & build.
– application.yaml files per service.
– Dependencies on Zookeeper (MetaStore), Redis, Netty, Protobuf.
Derive Key Architecture from README
• Services register/discover via MetaStore (Zookeeper).
• Route‐service subscribes to MetaStore to get IM server list and caches in Redis.
• Client logs in via Route (HTTP/REST), then opens Netty socket to an IM server (selected via Route).
• Messages from Client→Route→IM server→Client.
Main Components & Their Relationships
a. Components:
1. CLI Client (cim-client)
2. Client SDK (cim-client-sdk)
3. Route Service (cim-forward-route)
4. IM Server (cim-server)
5. MetaStore (Zookeeper)
6. Redis cache (user info in Route)
7. Shared library (cim-common)
b. Interactions / Data Flow:
1. IM Server → registers itself with MetaStore on startup.
2. Route Service → subscribes to MetaStore to watch changes in server list.
3. CLI Client → HTTP Login → Route Service → stores session, returns server info.
4. CLI Client → opens Netty TCP connection → IM Server (via Client SDK)
5. CLI Client → send message → first to Route Service (JSON/HTTP or via SDK + REST)
then Route picks a server (consistent hashing/algorithm from cim‑common)
→ forwards to IM Server over HTTP or direct RPC → pushes to target Client via Netty.
6. Heartbeats and reconnection managed by SDK (ReconnectManager, BackoffStrategy).
c. Architectural Patterns:
• Modular microservices (Spring Boot per module).
• Registry/Discovery via MetaStore (Zookeeper).
• Caching/persistence of user sessions in Redis for Route.
• Netty pipeline on IM Server + Client for binary ProtoBuf payloads.
• Dynamic proxy & RPC abstraction in cim-common.
d. Key Technologies:
• Spring Boot 3.x (each module)
• Netty (network I/O)
• Protocol Buffers (.proto in cim-common)
• Zookeeper (MetaStore)
• Redis (Route cache)
• Maven multi-module structure
• Java 17
• Swagger/OpenAPI (config in each service)