$ show crossoverJie/cim
CIM (Cross-platform Instant Messaging) is a production-grade, modular instant messaging framework built with Java 17, Spring Boot 3.3, and Netty. It provides a complete IM solution including a Netty-based server (cim-server) for handling client connections and message forwarding, a routing server (cim-forward-route) for message routing, user login/offline management, and a client SDK (cim-client-sdk) for building custom clients. The system uses Zookeeper for service discovery, Redis for caching and session management, and optionally MySQL for offline message persistence. It supports group chat, private chat, offline messages, delayed messages, emoji, AI mode, and a built-in command system. The architecture is microservice-oriented with clear separation of concerns, and the codebase demonstrates strong engineering practices including consistent hashing for server selection, a custom ring buffer wheel for delayed tasks, a dynamic HTTP proxy for RPC calls, and a trie-based prefix search. The project includes comprehensive unit and integration tests, Docker support, and CI/CD pipelines.
The LLM identified 4 files worth highlighting for reuse:
A high-performance, thread-safe ring buffer wheel for scheduling delayed tasks. It uses a power-of-2 sized circular buffer, bitwise modulo for indexing, and supports task cancellation. The implementation is self-contained (only depends on standard Java and Lombok) and can be extracted as a standalone delay-task scheduler. It demonstrates non-obvious skill in lock-free design and efficient cycle calculation.
A dynamic proxy-based HTTP RPC client that converts interface method calls into RESTful HTTP requests using OkHttp. It handles serialization, deserialization of generic types (including nested generics like BaseResponse<Set<CIMUserInfo>>), and supports both GET and POST methods via annotations. While it imports several internal utility classes, the pattern of using Java Proxy and annotations for RPC is highly reusable and demonstrates advanced reflection and proxy techniques.
An abstract implementation of consistent hashing with MD5-based hash computation and virtual node support. It provides a template method pattern for adding nodes, sorting, and selecting the first node. Concrete implementations (TreeMapConsistentHash and SortArrayMapConsistentHash) demonstrate different data structure choices. This component is self-contained within cim-common and can be reused in any distributed system requiring consistent hashing for load balancing.
A clean interface for backoff strategies with a default method for executing the backoff. The accompanying RandomBackoff implementation provides a simple random backoff between 3-10 seconds. This is a minimal, isolated pattern that can be extracted and reused in any retry logic across different projects.