Skip to content

[desktop/macos] APIClient.swift is a 5,750-line god actor with hand-duplicated server models #8844

Closed

Description

@Git-on-my-level

Area: Architecture — API layer & data models

Problem

Desktop/Sources/APIClient.swift is a single 5,750-line file: one actor, 18+ anonymous extension APIClient blocks, 168 functions, plus most server DTOs defined inline (ActionItem at :1040, ConversationPhoto at :1185, ServerMemory at :1444, ActionItemsListResponse at :2163, …). Every feature touches this file, so it is a permanent merge-conflict and review hotspot at ~1190 desktop commits/month.

The DTOs are also hand-duplicated across three codebases with no generated contract:

  • Swift: APIClient.swift (ActionItem, ServerMemory) + GRDB mirror Rewind/Core/ActionItemModels.swift (ActionItemRecord)
  • Rust: Backend-Rust/src/models/conversation.rs:55 (ActionItem), models/memory.rs:19/35 (Memory, MemoryDB), models/action_item.rs:10 (ActionItemDB)
  • Python backend models (source of truth for the REST API)

Drift is already visible in the scars: Tests/ServerMemoryV17DecodingTests.swift exists because decoding broke against a server schema change.

Suggested fix (incremental, no rewrite)

  1. Mechanically split APIClient.swift into per-domain files (APIClient+Conversations.swift, APIClient+Memories.swift, APIClient+Tasks.swift, …) and move DTOs into a Models/ directory. Pure file moves, no behavior change — do it in one PR to keep blame useful.
  2. Add a CI ratchet: fail if any Swift file under Desktop/Sources exceeds its current line count high-water mark (or a fixed cap for new files), so god files can only shrink. Same medicine applies to TasksPage.swift (5,394), ChatProvider.swift (4,406), FloatingControlBarWindow.swift (3,636).
  3. Longer term: generate the Swift DTOs from the Python backend's OpenAPI schema (FastAPI already produces one; backend/scripts/openapi_runner.sh exists), or at minimum add contract tests pinning JSON fixtures shared between the Swift and Rust decoders — mirroring the existing desktop-backend-contracts.yml pattern.

Open questions

  • Which DTOs are desktop-only (Rust backend) vs shared with the Python API? The split determines which contract source to generate from.

Activity

  1. added
    docs-tooling
    p3
    on Jul 4, 2026
  2. Git-on-my-level commented on Jul 22, 2026

    @Git-on-my-level
    MemberAuthor

    Done: APIClient.swift is now 1,103 lines with domain files split out (Services/APIClient/APIClient+Settings.swift, +AuthPolicy.swift), and the god-file ratchet exists as product-file-line-count-ratchet in .github/checks-manifest.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs-toolingp3refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions