Index of every page on this site: llms.txt
All skills
daveebbelaar avatar

/improve-architecture

@22dc792
by Dave Ebbelaardaveebbelaar/bama1.9k stars
238
Run it yourself

Architecture check-in for a growing macOS Swift codebase. Finds hot spots, proposes deeper modules, and refactors one step per commit with behavior proven unchanged. Use at the end of a milestone, before a big feature, when a file passes 600 lines, when one feature touches many files, when bugs repeat in one area, or when the user asks to refactor or clean up the code.

Use this Skill: https://skilld.dev/gh/daveebbelaar/bama/improve-architecture

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

architecture.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Architecture for apps that grow

The template starts with one target. Move to this shape when the app gets a CLI, an engine (media, sync, parsing), or a second contributor.

Contents

  • Targets and dependency direction
  • Edits as pure operations
  • Split state by update rate
  • Seams with two adapters
  • Engines report counters, not exceptions
  • Safe saves
  • Errors
  • File size norms
  • Gotchas

Targets and dependency direction

App (SwiftUI, menus, windows) -> feature and engine targets -> Core

Never the reverse. Core knows nothing about SwiftUI, AVFoundation, or Metal.

// Package.swift
.target(name: "AppCore"),                                  // values, documents, rules, math
.target(name: "AppStore", dependencies: ["AppCore"]),      // persistence, sync
.target(name: "AppEngine", dependencies: ["AppCore"]),     // media, rendering, heavy work
.executableTarget(name: "App", dependencies: ["AppCore", "AppStore", "AppEngine"]),
.executableTarget(name: "appctl", dependencies: ["AppCore", "AppStore"]),   // CLI
.testTarget(name: "AppCoreTests", dependencies: ["AppCore"]),

A CLI on the same core keeps the core free of UI by force. The app target stays thin: views and one @MainActor model per page.

Edits as pure operations

Every change to the user's document is an operation applied to a value. One entry point serves the UI, Undo, the CLI, and tests.

public enum EditOp: Codable, Sendable { case rename(id: ID, to: String), move(id: ID, to: Int) }

public extension Document {
    func apply(_ ops: [EditOp]) throws -> Document   // all or nothing, returns a new value
}

@discardableResult func perform(_ ops: [EditOp], named name: String) -> Bool {
    do {
        let next = try doc.apply(ops)
        guard next != doc else { return false }
        pushUndo(name); doc = next; scheduleSave(); return true
    } catch { errorMessage = error.localizedDescription; return false }
}

Split state by update rate

A value that changes many times a second (a playhead, a meter, a timer) lives in its own small observable object. Only the views that show it observe it. Putting it on the page model re-renders every view on the page.

@MainActor @Observable final class PlayheadClock { var frame = 0 }

struct PlayheadLabel: View {
    let clock: PlayheadClock
    var body: some View { Text("\(clock.frame)").monospacedDigit() }
}

Engines own their real-time state. The UI reads snapshots at the rate a person can see: 15 Hz for meters, 1 Hz for device lists.

Seams with two adapters

Add a protocol only where you swap behavior: network, clock, file system, an external service. Give it a production adapter and a test adapter on day one.

public protocol Transport: Sendable {
    func data(for request: URLRequest) async throws -> (Data, HTTPURLResponse)
}
struct URLSessionTransport: Transport { ... }
struct RecordedTransport: Transport { ... }    // tests: replays saved responses

Engines report counters, not exceptions

Real-time paths never throw. They count what went wrong and expose a snapshot.

public struct WriterStats: Sendable { var appended = 0, stalls = 0, dropped = 0, fallbacks = 0 }
public func snapshot() -> WriterStats { lock.withLock { stats } }

The self-test prints the counters. A non-zero dropped fails it.

Safe saves

Write to a temp file, then rename (atomic). Keep a revision number; when the file changed under you, reload and replay unsaved operations. Never overwrite an output another feature points at: write a new version.

Errors

A typed enum per module that conforms to LocalizedError. The UI shows errorMessage. Media and real-time paths degrade (drop a preview frame, fall back to the CPU) and count it.

File size norms

Library files mostly 100 to 450 lines. A file over 600 lines is a check-in signal. View models over 1,000 lines are the first refactor targets. Test hooks live in a test target or behind a launch flag, not in app files.

Gotchas

  • Synthesized Codable can change the bytes of old files when you add a property (it writes "items": []). Keep a test that loads and re-saves an old file byte for byte.
  • model.child?.field = f(model.child) on an @Observable type can crash with an exclusivity violation. Read into a let first.
  • A menu action named like an AppKit setter (setAppearance:) crashes. Name actions applyAppearance(_:).
  • A huge function can crash the release optimizer. Split it.
  • Two agents building one package at once break each other. New types land in new files that compile on their own; never add an empty target.
  • Async job queues: give each job a generation number and claim it before starting, so a retry never runs a paid job twice.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts28d3 checks · Risk SAFE
  • Gen Agent Trust Hub28d

    The skill is a development tool designed for macOS Swift architecture reviews. It analyzes local source code and project documentation to identify technical debt and propose refactors. A low-severity risk of indirect prompt injection exists because the skill processes content from local project files that could potentially contain malicious instructions if the repository itself is untrusted.

  • Socket28d

    No alerts

  • Snyk28d

    Risk: LOW · No issues

Signed by skilld at 22dc792. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month

README badge

README badge for daveebbelaar/bama/improve-architecture