# bluexsx/box-im architecture

> Architecture diagram of the GitHub repository bluexsx/box-im, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bluexsx/box-im
- Repository: https://github.com/bluexsx/box-im

## Overview

##### Project type and purpose
- This is a full-stack, WeChat-like instant-messaging system (“盒子IM”) supporting web (Vue), mobile (uniapp) and Java SDK clients.
- Core modules:
- im-web (Vue web client)
- im-uniapp (cross-platform mobile/hybrid client)
- im-platform (Spring Boot business API service)
- im-server (Netty-based message push service)
- im-client (Java SDK to push messages into im-server)
- im-common (shared library)
- DB scripts under db/

##### File-structure indicators
- Top-level directories map to independent deployable modules (microservices + front-ends).
- im-platform and im-server are Spring Boot JARs with their own configurations, controllers, services, mappers.
- im-web and im-uniapp are separate front-end codebases.
- Redis and MinIO configs appear in im-platform; Netty code under im-server.

##### Key README insights
- Front-ends talk HTTP to im-platform for business data (login, friends, groups, file uploads).
- im-platform uses im-client SDK to deliver messages to im-server.
- im-server is cluster-aware, uses Redis lists and a “im:unread:${serverId}” queue scheme for cross-node delivery.
- Persistence: MySQL (im_platform DB).
- File storage: MinIO.
- Real-time push: WebSocket / TCP (Netty).

- Clients (blue rectangles):
- Web browser (Vue im-web)
- Mobile/hybrid app (uniapp im-uniapp)
- Java backend clients (im-client SDK)
- im-platform cluster (multiple Spring Boot instances behind HTTP LB)
- im-server cluster (multiple Netty WS/TCP servers behind TCP/WS LB)
- MySQL
- Redis (pub/sub + lists)
- MinIO (object storage)
- Optional Load Balancer (Nginx or TCP/WS LB)

1. Clients → HTTP LB → im-platform: REST/HTTP for business operations.
2. im-platform → MySQL: persist user/groups/messages.
3. im-platform → MinIO: upload/download files.
4. im-platform → Redis: caching, locking, pub/sub, queue writes (im-client SDK posts to Redis list).
5. im-server ↔ Redis:
- Pushers (im-platform/im-client) write to per-server Redis lists (“im:unread:${serverId}”).
- im-server pool polls its own list to fetch messages for connected users.
- Redis also holds user→server mapping for live connections.
6. Clients ↔ im-server: persistent WebSocket/TCP connections; Netty handles protocol encoding/decoding and dispatches to processors.

c. Architectural patterns & principles
- Separation of concerns: business API vs. real-time push.
- Microservices-style modules enabling independent scaling (im-platform vs. im-server).
- Event-driven messaging via Redis lists for cross-node coordination.
- Spring Boot + Netty for reactive, non-blocking I/O.
- Clustered Redis for high availability.
- Horizontal scalability: multiple im-platform and im-server instances behind load balancers.

d. Technologies & frameworks
- Front-end: Vue.js, uniapp (h5/app/miniprogram), WebSocket/TCP clients delivered via JavaScript or im-client SDK.
- Backend: Java 17, Spring Boot 3.x, MyBatis mappers, Spring AOP (annotations for locks, repeat submits, online checks), RedisTemplate, MinIO Java client.
- Messaging: Netty (custom protocol over WS/TCP), Redis as message queue and connection registry.
- Storage: MySQL 8.x, MinIO.

##### Detail level
- Redis roles: caching vs. message queue vs. connection registry.
- Im-client SDK as part of im-platform’s message-push pipeline.
- If desired, break out im-common as a library dependency for back-ends but not as a runtime component.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Web["Web Browser (im-web)"]:::frontend
        Mobile["Mobile/Hybrid App (im-uniapp)"]:::frontend
        JavaSDK["Java SDK Client (im-client)"]:::frontend
    end

    %% API Layer
    HTTP_LB["HTTP Load Balancer"]:::infra
    subgraph "Business API Layer"
        direction TB
        Platform["im-platform"]:::api
    end

    %% Messaging Layer
    WSTCP_LB["WS/TCP Load Balancer"]:::infra
    subgraph "Real-Time Messaging Layer"
        direction TB
        Server["im-server"]:::messaging
    end

    %% Data & Infrastructure
    subgraph "Data & Infrastructure"
        direction TB
        MySQL["MySQL"]:::data
        Redis["Redis (pub/sub, lists)"]:::data
        MinIO["MinIO"]:::data
        DBScripts["DB Scripts"]:::data
    end

    %% Shared Library
    CommonLib["im-common (Shared Library)"]:::lib

    %% Clients to API
    Web -->|"HTTP/REST"| HTTP_LB
    Mobile -->|"HTTP/REST"| HTTP_LB
    HTTP_LB -->|"HTTP/REST"| Platform

    %% API interactions
    Platform -->|"JDBC"| MySQL
    Platform -->|"MinIO Client API"| MinIO
    Platform -->|"Cache/Lock/Queue"| Redis
    Platform -->|"uses"| CommonLib
    Platform -->|"invokes"| JavaSDK

    %% Real-time push pipeline
    JavaSDK -->|"push message"| Redis
    Redis -->|"poll messages"| Server
    WSTCP_LB -->|"WS/TCP"| Server
    Web -->|"WebSocket/TCP"| WSTCP_LB
    Mobile -->|"WebSocket/TCP"| WSTCP_LB

    %% DB Scripts location
    DBScripts

    %% Click events
    click Web "https://github.com/bluexsx/box-im/tree/master/im-web/"
    click Mobile "https://github.com/bluexsx/box-im/tree/master/im-uniapp/"
    click Platform "https://github.com/bluexsx/box-im/tree/master/im-platform/"
    click Server "https://github.com/bluexsx/box-im/tree/master/im-server/"
    click JavaSDK "https://github.com/bluexsx/box-im/tree/master/im-client/"
    click CommonLib "https://github.com/bluexsx/box-im/tree/master/im-common/"
    click DBScripts "https://github.com/bluexsx/box-im/tree/master/db/"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#007BFF,color:#000
    classDef api fill:#DFF4D8,stroke:#28A745,color:#000
    classDef messaging fill:#F0D9FF,stroke:#6F42C1,color:#000
    classDef data fill:#FFE8B3,stroke:#F0AD4E,color:#000
    classDef infra fill:#E2E3E5,stroke:#6C757D,color:#000
    classDef lib fill:#F8F9FA,stroke:#343A40,color:#000
```
