FoxTalk
Docs/SDK layering

SDK layering

The FoxTalk client uses a three-layer architecture: the UI only renders state, business logic lives in app-layer services, and the SDK handles protocol + local DB. This mirrors the original iOS app, which makes cross-platform comparison straightforward.

Responsibilities at a glance:

UI layer
Widget / page / navigation / animation. Reads app-layer data; holds no business state.
App layer
Business models / services / local cache / KV persistence. The only bridge between UI and SDK.
IM SDK layer
TCP / WebSocket connection / protocol codec / SQLite local DB (wukongimfluttersdk).

UI never calls the SDK directly

The UI layer must not import wukongimfluttersdk — it always goes through an app-layer service. Two concrete benefits:

  • Easier testing: services accept mocks, so widget tests don't need a real IM connection.
  • Swappable protocol: replacing WuKongIM with another IM stack only changes service implementations — the UI stays put.
Example: chat_screen_page pulls history via WukongImService.loadMessages(channelId, channelType, limit, beforeSeq) instead of calling WKIM.shared.messageManager directly.

Three roles in the app layer

The app layer isn't a single file — it's three collaborating roles:

Gateway
Public interface (e.g. ChatImGateway / ChatSocialGateway) consumed by the UI.
Service
Gateway implementation, holding in-memory cache and stream broadcasts (e.g. WukongImService).
Repository / DAO
App-layer persistence (e.g. lib/src/db/friend_request_db.dart), called by services.

IM SDK layer responsibilities

wukongimfluttersdk owns the long-lived IM connection and the local SQLite. The base app touches WKIM.shared.* only inside app-layer services — the UI never reaches it:

  • WKIM.shared.conversationManager — local conversation table
  • WKIM.shared.channelManager — channel / group / user profile table
  • WKIM.shared.messageManager — message history + paging
  • WKIM.shared.channelMembersManager — group members table
  • WKIM.shared.cmdManager — business CMD pushes (pinned / moments / RTC etc.)
last updated · 2026-06