# seifateek/afm-gui architecture

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

- Interactive diagram: https://gitdiagram.com/seifateek/afm-gui
- Repository: https://github.com/seifateek/afm-gui

## Overview

AFM Chat is a native, offline macOS client for Apple’s on-device Foundation Model. The main workflow is composing a message (optionally with an image or skill), sending it through AppState for streaming generation, then viewing and managing the reply. AppState also handles conversation context and summarization; the UI provides chat organization, settings, and artifact previews. The graph combines sampled calls and imports with documented capabilities; some feature-level wiring is not visible in the excerpts, so those links are omitted or marked unverified.

Main entry points: [`Sources/AFMChat/AppState.swift`](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/AppState.swift) (Chat runtime), [`Sources/AFMChat/Views.swift`](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Views.swift) (Chat views), [`Sources/AFMChat/Composer.swift`](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Composer.swift) (Message composer), [`Sources/AFMChat/Models.swift`](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift) (Artifact extraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and interface"]
  node_app_entry["App entry<br/>[App.swift]"]
  node_chat_views["Chat views<br/>[Views.swift]"]
  node_composer["Message composer<br/>[Composer.swift]"]
  node_settings["Settings UI<br/>[Settings.swift]"]
end

subgraph group_conversation["Conversation runtime"]
  node_runtime["Chat runtime<br/>[AppState.swift]"]
  node_model["On-device model"]
  node_context["Context management<br/>[AppState.swift]"]
end

subgraph group_domain["Chat data"]
  node_chat_data["Chat and skill data<br/>[Models.swift]"]
  node_local_store[("Local chat store<br/>[Models.swift]")]
  node_markdown["Markdown parsing<br/>[Models.swift]"]
  node_image_files[("Image attachments<br/>[Models.swift]")]
end

subgraph group_capabilities["User capabilities"]
  node_artifact_data["Artifact extraction<br/>[Models.swift]"]
  node_artifact_panel["Artifact preview<br/>[Artifacts.swift]"]
  node_speech["Read aloud<br/>[Views.swift]"]
end

node_user(("User"))

node_user -->|"uses"| node_chat_views
node_app_entry -->|"opens"| node_chat_views
node_chat_views -->|"embeds"| node_composer
node_chat_views -->|"uses"| node_runtime
node_composer -->|"sends prompts"| node_runtime
node_runtime -->|"generates with"| node_model
node_runtime -->|"manages"| node_context
node_runtime -->|"saves chats"| node_local_store
node_runtime -->|"loads images"| node_image_files
node_composer -->|"imports images"| node_image_files
node_settings -->|"updates settings"| node_runtime
node_chat_views -->|"opens panel"| node_artifact_panel
node_artifact_panel -->|"lists artifacts"| node_artifact_data
node_artifact_data -->|"parses blocks"| node_markdown
node_chat_views -.->|"offers playback"| node_speech
node_chat_data -.->|"persists records"| node_local_store

click node_app_entry "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/App.swift"
click node_chat_views "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Views.swift"
click node_composer "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Composer.swift"
click node_settings "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Settings.swift"
click node_runtime "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/AppState.swift"
click node_context "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/AppState.swift"
click node_chat_data "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift"
click node_local_store "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift"
click node_markdown "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift"
click node_image_files "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift"
click node_artifact_data "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift"
click node_artifact_panel "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Artifacts.swift"
click node_speech "https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Views.swift"

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_app_entry,node_chat_views,node_composer,node_settings,node_user toneBlue
class node_runtime,node_model,node_context toneAmber
class node_chat_data,node_local_store,node_markdown,node_image_files toneMint
class node_artifact_data,node_artifact_panel,node_speech toneRose
```

## Components

### App and interface

- [App entry](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/App.swift): `Sources/AFMChat/App.swift`
- [Chat views](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Views.swift): `Sources/AFMChat/Views.swift`
- [Message composer](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Composer.swift): `Sources/AFMChat/Composer.swift`
- [Settings UI](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Settings.swift): `Sources/AFMChat/Settings.swift`

### Conversation runtime

- [Chat runtime](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/AppState.swift): `Sources/AFMChat/AppState.swift`
- **On-device model**
- [Context management](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/AppState.swift): `Sources/AFMChat/AppState.swift`

### Chat data

- [Chat and skill data](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift): `Sources/AFMChat/Models.swift`
- [Local chat store](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift): `Sources/AFMChat/Models.swift`
- [Markdown parsing](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift): `Sources/AFMChat/Models.swift`
- [Image attachments](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift): `Sources/AFMChat/Models.swift`

### User capabilities

- [Artifact extraction](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Models.swift): `Sources/AFMChat/Models.swift`
- [Artifact preview](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Artifacts.swift): `Sources/AFMChat/Artifacts.swift`
- [Read aloud](https://github.com/seifateek/afm-gui/blob/main/Sources/AFMChat/Views.swift): `Sources/AFMChat/Views.swift`

### Other components

- **User**

## Connections

- User → Chat views: uses (evidence: `README.md`)
- App entry → Chat views: opens (evidence: `Sources/AFMChat/App.swift`)
- Chat views → Message composer: embeds (evidence: `Sources/AFMChat/Views.swift`)
- Chat views → Chat runtime: uses (evidence: `Sources/AFMChat/Views.swift`)
- Message composer → Chat runtime: sends prompts (evidence: `Sources/AFMChat/Composer.swift`)
- Chat runtime → On-device model: generates with (evidence: `Sources/AFMChat/AppState.swift`)
- Chat runtime → Context management: manages (evidence: `Sources/AFMChat/AppState.swift`)
- Chat runtime → Local chat store: saves chats (evidence: `Sources/AFMChat/AppState.swift`)
- Chat runtime → Image attachments: loads images (evidence: `Sources/AFMChat/AppState.swift`)
- Message composer → Image attachments: imports images (evidence: `Sources/AFMChat/Composer.swift`)
- Settings UI → Chat runtime: updates settings (evidence: `Sources/AFMChat/Settings.swift`)
- Chat views → Artifact preview: opens panel (evidence: `Sources/AFMChat/Views.swift`)
- Artifact preview → Artifact extraction: lists artifacts (evidence: `Sources/AFMChat/Artifacts.swift`)
- Artifact extraction → Markdown parsing: parses blocks (evidence: `Sources/AFMChat/Models.swift`)
- Chat views → Read aloud: offers playback (evidence: `README.md`)
- Chat and skill data → Local chat store: persists records (evidence: `Sources/AFMChat/Models.swift`)
