> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture & Data Flow

> How the CometChat iOS UI Kit v6 is layered — CometChatCore, CometChatSwiftUI and CometChatUIKit — and how data flows from the Chat SDK through stores to the screen.

> [accordion] AI Integration Quick Reference
>
> ```json theme={null}
> {
>   "package": "https://github.com/cometchat/cometchat-uikit-ios.git from 6.0.0-beta.1 — SPM, iOS 18, Swift 6",
>   "products": {
>     "CometChatCore": "value types, stores, SDK mapping, events, theme assets, strings — no SwiftUI, no UIKit",
>     "CometChatSwiftUI": "SwiftUI toolkit over the Core stores; callbacks speak SDK types",
>     "CometChatUIKit": "native UIKit toolkit over the same Core stores"
>   },
>   "stores": "ConversationsStore, UsersStore, GroupsStore, GroupMembersStore, MessageHeaderStore, MessageListStore, MessageComposerStore, SearchStore, PinnedMessagesStore, SavedMessagesStore, CometChatThreadHeaderStore …",
>   "inject": "store: (SwiftUI) / init(conversationsStore:), init(usersStore:), init(groupsStore:), set(store:) (UIKit); init(seeded:) for previews",
>   "events": "CometChatEvents — one bus; the UIKit buses are views of it"
> }
> ```

The iOS v6 Kit is one Swift package with three products — `CometChatCore`, `CometChatSwiftUI`
and `CometChatUIKit`. An app adds one toolkit; `CometChatCore` and the Chat SDK come with it.

## Module Structure

```
                  ┌───────────────────────────┐      ┌───────────────────────────┐
  your app ─────▶ │ CometChatSwiftUI          │  or  │ CometChatUIKit            │ ◀───── your app
                  │ SwiftUI toolkit           │      │ native UIKit toolkit      │
                  └────────────┬──────────────┘      └─────────────┬─────────────┘
                               │                                   │
                  ┌────────────▼───────────────────────────────────▼─────────────┐
                  │ CometChatCore — value types · stores · mapping · events ·     │
                  │ theme assets · strings                                        │
                  └────────────┬─────────────────────────────────────────────────┘
                               │
                  ┌────────────▼──────────────┐
                  │ CometChatSDK (Chat SDK 4.x) · CometChatCallsSDK                │
                  └───────────────────────────┘
```

| Product | Depends on | What it is |
| - | - | - |
| `CometChatCore` | Chat SDK, Calls SDK | Value types (`ChatConversation`, `ChatUser`, `ChatMessage` …), the stores that fetch and listen, SDK-to-value mapping, the event bus, `CometChatSession`, localized strings and image assets. No SwiftUI, no UIKit. |
| `CometChatSwiftUI` | Core, Chat SDK | The SwiftUI toolkit: each component owns a Core store and renders its state. Re-exports `CometChatCore`. |
| `CometChatUIKit` | Core, Chat SDK | A native UIKit toolkit — `UIViewController`s, `UITableView`s, cells, delegates — over the same Core stores. A peer of the SwiftUI toolkit, not a wrapper. Re-exports `CometChatCore`. |

An app adds **one** toolkit — `CometChatSwiftUI` or `CometChatUIKit`. Both declare components
with the same names (`CometChatConversations`, `CometChatMessageList` …), so one Swift file
cannot import both.

```swift theme={null}
// SwiftUI app
import CometChatSwiftUI      // + CometChatCore, re-exported
import CometChatSDK          // when you use SDK types: User, Group, BaseMessage

// UIKit app
import CometChatUIKit        // + CometChatCore, re-exported
import CometChatSDK
```

## The Layers

| Layer | Lives in | Holds |
| - | - | - |
| **SDK** | `CometChatSDK` | network calls, sockets, SDK model classes |
| **Store** | `CometChatCore` | one `@MainActor @Observable` store per component: fetching, pagination, SDK listeners, the Kit's event bus, merge rules — published as a state value |
| **Toolkit** | `CometChatSwiftUI` / `CometChatUIKit` | the component you place: owns a store, renders its state, turns taps into store calls and your callbacks |

Both toolkits read the same stores, so they cannot disagree about **what** to show — only how
it is drawn.

### Value types

Stores publish **value types**, not SDK objects: `ConversationsState.populated(entries, hasMore:)`,
`ChatConversation`, `ChatUser`, `ChatGroup`, `ChatMessage`. They are `Sendable`, so they can
leave an SDK callback queue under Swift 6.
The store keeps the SDK objects alongside, keyed by id, so the toolkits' **callbacks hand you SDK
types** — `onItemClick` gives you a `CometChatSDK.Conversation` you can pass to the rest of your
app.

### State

Each store's `state` is an enum of what the screen can show. The conversations list's:

| Case | Shows |
| - | - |
| `.loading` | the shimmer |
| `.populated(entries, hasMore:)` | the rows |
| `.paginating(entries)` | the rows and a footer spinner |
| `.empty` / `.searchEmpty(query:)` | the empty state |
| `.error(_:)` | the error state, with Retry |

### Behaviour hooks: policies

A store takes a **policy** — a value of closures, swappable without subclassing:

```swift theme={null}
let policy = ConversationsPolicy(
    shouldUpdateForCustomMessage: { message in message.type == "meeting" },
    isThreadedMessage: { $0.parentMessageId > 0 }
)
let store = ConversationsStore(policy: policy)
_ = store
```

`MessageListPolicy`, `MessageOptionsPolicy` (who may edit, delete, report, message privately)
and others follow the same shape. Stores are also non-`final`, for anything a policy does not
cover.

## Data Flow: End to End

### Fetching conversations

1. The component appears and asks its store to fetch.
2. The store builds the SDK request (yours, if you passed a request builder) and fetches a page.
3. The SDK answers on its own queue. The store maps the result to value types there, then hops
   to the main actor.
4. The store publishes `.populated(entries, hasMore:)`; the toolkit renders it.
5. Scrolling to the end fetches the next page — `.paginating`, then `.populated` again.

### Real-time updates

1. The store registers SDK listeners under a unique id, and removes them when it goes.
2. A message, receipt, typing indicator or presence change arrives from the SDK.
3. The store applies its merge rule — move the row to the top, bump the unread count, show
   typing — and publishes a new state.

### This user's own actions

The SDK does not tell the Kit what this user did. So the component that acts announces it on
`CometChatEvents`, and every other store listening updates:

1. The user deletes a conversation in `CometChatConversations`.
2. The store calls the SDK; on success it removes the row and emits `conversationDeleted`.
3. Any other store showing that conversation hears the event and updates.

Actions taken on **your** screens must be announced by you — see [Events](https://www.cometchat.com/docs/ui-kit/ios/v6/events.md).

## Events (Cross-Component Communication)

There is one bus, `CometChatEvents`, with seven families: message, user, group, conversation,
call, UI and thread. SwiftUI listens with view modifiers (`.onCometChatUserBlocked { … }`) or
`AsyncStream`s (`CometChatEvents.userEvents`); UIKit has per-family buses and listener protocols
(`CometChatUserEvents`, `CometChatUserEventListener`), which are views of the same bus. Delivery
is on the main actor, in order.

## Component-Level Overrides

### Override points

| What | SwiftUI | UIKit |
| - | - | - |
| Seed or share a store | `store:` | `init(conversationsStore:)`, `init(usersStore:)`, `init(groupsStore:)`, `set(store:)` |
| Change the request | `conversationsRequestBuilder:`, `usersRequestBuilder:` … | `set(conversationsRequestBuilder:)`, `set(userRequestBuilder:)` … |
| Change behaviour | a policy on the store | a policy on the store; `open` override points on the controller |
| Change a part of the view | slot parameters and modifiers | `set(…View:)` slots, `listItemCellClass` |

### 1. Inject a store

> [tab] SwiftUI
>
> ```swift InjectedStore.swift theme={null}
> import SwiftUI
> import CometChatSwiftUI
>
> struct InjectedStore: View {
>     @State private var store = ConversationsStore(pageSize: 50)
>
>     var body: some View {
>         CometChatConversations(store: store)
>     }
> }
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let store = ConversationsStore(pageSize: 50)
> let conversations = CometChatConversations(conversationsStore: store)
> ```

### 2. Seed a store for previews and tests

A seeded store fetches nothing and registers no listeners:

> [tab] SwiftUI
>
> ```swift theme={null}
> #Preview {
>     CometChatConversations(store: ConversationsStore(seeded: .empty))
> }
> ```

> [tab] UIKit
>
> ```swift theme={null}
> let preview = CometChatConversations(conversationsStore: ConversationsStore(seeded: .empty))
> ```

Stores also take `events:` — pass `CometChatEvents()` for an isolated bus, so a test hears only
its own events.

## Component ↔ Store Mapping

| Component | Store |
| - | - |
| `CometChatConversations` | `ConversationsStore` |
| `CometChatUsers` | `UsersStore` |
| `CometChatGroups` | `GroupsStore` |
| `CometChatGroupMembers` | `GroupMembersStore` |
| `CometChatMessageHeader` | `MessageHeaderStore` |
| `CometChatMessageList` | `MessageListStore` |
| `CometChatMessageComposer` | `MessageComposerStore` |
| `CometChatThreadHeader` | `CometChatThreadHeaderStore` |
| `CometChatSearch` | `SearchStore` |
| `CometChatPinnedMessages` | `PinnedMessagesStore` |
| `CometChatSavedMessages` | `SavedMessagesStore` |

## Related

> [card] [Overview](https://www.cometchat.com/docs/ui-kit/ios/v6/overview.md)
>
> Choosing a toolkit

> [card] [Events](https://www.cometchat.com/docs/ui-kit/ios/v6/events.md)
>
> The event bus in full

> [card] [Methods](https://www.cometchat.com/docs/ui-kit/ios/v6/methods.md)
>
> CometChatSession

> [card] [Upgrading from v5](https://www.cometchat.com/docs/ui-kit/ios/v6/migrating-from-v5.md)
>
> What changed for v5 apps


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.