# cjz3899/smartchat architecture

> Architecture diagram of the GitHub repository cjz3899/smartchat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cjz3899/smartchat
- Repository: https://github.com/cjz3899/smartchat

## Overview

SmartChat is a server-side messaging application with chat, contacts and rooms, user access, AI chat, and reusable infrastructure modules. The main user workflow is an API request to send a message, followed by message handling and delivery; room and contact operations provide conversation context, while read state, marks, and recall support message lifecycle features. AI handlers provide a separate capability. The README gives no product details, and most implementation files were not excerpted, so unverified application flows are shown as dashed links rather than asserted calls.

Main entry points: [`smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ChatServiceImpl.java`](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ChatServiceImpl.java) (Chat Service), [`smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java`](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java) (Recall Handler), [`smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ChatController.java`](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ChatController.java) (Chat API), [`smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/handler/ChatAIHandlerFactory.java`](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/handler/ChatAIHandlerFactory.java) (AI Providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Application API"]
  node_chat_api["Chat API"]
  node_contact_api["Contact API"]
  node_room_api["Room API"]
end

subgraph group_chat["Messaging Domain"]
  node_chat_service["Chat Service"]
  node_msg_handlers["Message Handlers"]
  node_recall_handler["Recall Handler"]
  node_chat_store[("Chat Persistence<br/>[MessageDao.java]")]
  node_chat_caches["Chat Caches<br/>[MsgCache.java]"]
  node_message_events["Message Events"]
  node_room_service["Room Service"]
end

subgraph group_identity["Users And Contacts"]
  node_contact_service["Contact Service"]
  node_friend_service["Friend Service<br/>[FriendService.java]"]
  node_user_auth["User Authentication"]
  node_websocket["WebSocket Delivery"]
  node_push_service["Push Service<br/>[PushService.java]"]
end

subgraph group_ai["AI Chat"]
  node_ai_api["AI Service"]
  node_ai_handlers["AI Providers"]
  node_gpt_provider{{"GPT Provider"}}
  node_glm_provider{{"ChatGLM Provider"}}
end

subgraph group_infra["Shared Infrastructure"]
  node_mq["Message Queue"]
  node_rate_control["Rate Control"]
  node_secure_invoke["Reliable Invocation"]
  node_secure_records[("Retry Records")]
end

node_client(("Chat Client"))

node_client -.->|"requests"| node_chat_api
node_chat_api -.->|"delegates"| node_chat_service
node_chat_service -.->|"dispatches"| node_msg_handlers
node_msg_handlers -.->|"persists"| node_chat_store
node_chat_service -.->|"uses rooms"| node_room_service
node_contact_api -.->|"delegates"| node_contact_service
node_room_api -.->|"delegates"| node_room_service
node_client -.->|"authenticates"| node_user_auth
node_chat_service -.->|"uses cache"| node_chat_caches
node_recall_handler -->|"updates"| node_chat_store
node_recall_handler -->|"publishes"| node_message_events
node_recall_handler -->|"reads cache"| node_chat_caches
node_friend_service -.->|"supports contacts"| node_contact_service
node_push_service -->|"produces messages"| node_mq
node_mq -.->|"delivers"| node_websocket
node_ai_api -.->|"selects handler"| node_ai_handlers
node_ai_handlers -.->|"routes"| node_gpt_provider
node_ai_handlers -.->|"routes"| node_glm_provider
node_chat_api -.->|"rate-limits"| node_rate_control
node_secure_invoke -->|"stores retries"| node_secure_records

click node_chat_api "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ChatController.java"
click node_contact_api "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ContactController.java"
click node_room_api "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/RoomController.java"
click node_chat_service "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ChatServiceImpl.java"
click node_msg_handlers "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/MsgHandlerFactory.java"
click node_recall_handler "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java"
click node_chat_store "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/dao/MessageDao.java"
click node_chat_caches "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/cache/MsgCache.java"
click node_message_events "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/common/event/MessageRecallEvent.java"
click node_room_service "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/RoomAppServiceImpl.java"
click node_contact_service "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ContactServiceImpl.java"
click node_friend_service "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/FriendService.java"
click node_user_auth "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/UserAuthService.java"
click node_websocket "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/WebSocketService.java"
click node_push_service "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/impl/PushService.java"
click node_ai_api "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/service/impl/ChatAIServiceImpl.java"
click node_ai_handlers "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/handler/ChatAIHandlerFactory.java"
click node_rate_control "https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/common/service/frequencycontrol/AbstractFrequencyControlService.java"
click node_secure_invoke "https://github.com/cjz3899/smartchat/blob/main/smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/service/SecureInvokeService.java"
click node_secure_records "https://github.com/cjz3899/smartchat/blob/main/smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/dao/SecureInvokeRecordDao.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chat_api,node_contact_api,node_room_api,node_client toneBlue
class node_chat_service,node_msg_handlers,node_recall_handler,node_chat_store,node_chat_caches,node_message_events,node_room_service toneAmber
class node_contact_service,node_friend_service,node_user_auth,node_websocket,node_push_service toneMint
class node_ai_api,node_ai_handlers,node_gpt_provider,node_glm_provider toneRose
class node_mq,node_rate_control,node_secure_invoke,node_secure_records toneIndigo
```

## Components

### Application API

- [Chat API](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ChatController.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ChatController.java`
- [Contact API](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ContactController.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/ContactController.java`
- [Room API](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/RoomController.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/controller/RoomController.java`

### Messaging Domain

- [Chat Service](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ChatServiceImpl.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ChatServiceImpl.java`
- [Message Handlers](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/MsgHandlerFactory.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/MsgHandlerFactory.java`
- [Recall Handler](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java`
- [Chat Persistence](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/dao/MessageDao.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/dao/MessageDao.java`
- [Chat Caches](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/cache/MsgCache.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/cache/MsgCache.java`
- [Message Events](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/common/event/MessageRecallEvent.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/common/event/MessageRecallEvent.java`
- [Room Service](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/RoomAppServiceImpl.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/RoomAppServiceImpl.java`

### Users And Contacts

- [Contact Service](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ContactServiceImpl.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/impl/ContactServiceImpl.java`
- [Friend Service](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/FriendService.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/FriendService.java`
- [User Authentication](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/UserAuthService.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/UserAuthService.java`
- [WebSocket Delivery](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/WebSocketService.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/WebSocketService.java`
- [Push Service](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/impl/PushService.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/impl/PushService.java`

### AI Chat

- [AI Service](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/service/impl/ChatAIServiceImpl.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/service/impl/ChatAIServiceImpl.java`
- [AI Providers](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/handler/ChatAIHandlerFactory.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chatai/handler/ChatAIHandlerFactory.java`
- **GPT Provider**
- **ChatGLM Provider**

### Shared Infrastructure

- **Message Queue**
- [Rate Control](https://github.com/cjz3899/smartchat/blob/main/smartchat-chat-server/src/main/java/com/junzhecai/smartchat/common/service/frequencycontrol/AbstractFrequencyControlService.java): `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/common/service/frequencycontrol/AbstractFrequencyControlService.java`
- [Reliable Invocation](https://github.com/cjz3899/smartchat/blob/main/smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/service/SecureInvokeService.java): `smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/service/SecureInvokeService.java`
- [Retry Records](https://github.com/cjz3899/smartchat/blob/main/smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/dao/SecureInvokeRecordDao.java): `smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/dao/SecureInvokeRecordDao.java`

### Other components

- **Chat Client**

## Connections

- Chat Client → Chat API: requests
- Chat API → Chat Service: delegates
- Chat Service → Message Handlers: dispatches
- Message Handlers → Chat Persistence: persists
- Chat Service → Room Service: uses rooms
- Contact API → Contact Service: delegates
- Room API → Room Service: delegates
- Chat Client → User Authentication: authenticates
- Chat Service → Chat Caches: uses cache
- Recall Handler → Chat Persistence: updates (evidence: `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java`)
- Recall Handler → Message Events: publishes (evidence: `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java`)
- Recall Handler → Chat Caches: reads cache (evidence: `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/chat/service/strategy/msg/RecallMsgHandler.java`)
- Friend Service → Contact Service: supports contacts
- Push Service → Message Queue: produces messages (evidence: `smartchat-chat-server/src/main/java/com/junzhecai/smartchat/user/service/impl/PushService.java`)
- Message Queue → WebSocket Delivery: delivers
- AI Service → AI Providers: selects handler
- AI Providers → GPT Provider: routes
- AI Providers → ChatGLM Provider: routes
- Chat API → Rate Control: rate-limits
- Reliable Invocation → Retry Records: stores retries (evidence: `smartchat-tools/smartchat-transaction/src/main/java/com/junzhecai/smartchat/transaction/service/SecureInvokeService.java`)
