agentleFS
christopherkaranichristopherkarani/rv/.claude/skills/swift-functional-architecture/SKILL.md

swift-functional-architecture

Skill8 starsChanged 6 days agoApache-2.0View on GitHub

Default design skill for pragmatic functional Swift: functional core / imperative shell, values and composable transformations, enums for closed state, generics that preserve relationships, protocols as capabilities, intentional some/any boundaries, and effects pushed to adapters. Use for non-trivial Swift design and implementation. Also /swift-functional-architecture.

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. About 0 are common, 14 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Default design skill for non-trivial Swift design and implementation.

    line 15
  2. Distinctive:

    Prefer the smallest specialist skill when the task is narrowly about types, concurrency, testing, API naming, PR review, or broad …

    line 21
  3. Distinctive:

    Use classes when identity, lifecycle, framework constraints, observation, or shared resource ownership are real.

    line 51
  4. Distinctive:

    Prefer enums and associated values for closed state spaces.

    line 55
  5. Distinctive:

    Avoid boolean/optional combinations that permit invalid states.

    line 57
  6. Distinctive:

    Use exhaustive switches when adding a domain state should force callers to reconsider behavior.

    line 59
  7. Very specific:

    Prefer semantic types (PackID, RuleID, ShellCommand) over raw primitives when the distinction matters.

    line 61
  8. Distinctive:

    Use generics when the compiler should know a real relationship between types.

    line 67
  9. Distinctive:

    Ask: what incorrect program becomes impossible?

    line 69
  10. Distinctive:

    Keep generic complexity local.

    line 73
  11. Distinctive:

    When advanced typing makes call sites significantly harder without proportionate safety gain, prefer the simpler design.

    line 75
  12. Distinctive:

    Prefer narrow protocols. Prefer composition over large kitchen-sink protocols.

    line 81
  13. Distinctive:

    Prefer concrete types at module edges when the concrete type is the API.

    line 87
  14. Very specific:

    Use some to hide a concrete type while preserving a single underlying type.

    line 88
  15. Very specific:

    Use any only when runtime heterogeneity is intentional.

    line 89
  16. Distinctive:

    Prefer constrained existentials over open-ended erasure when possible.

    line 90
  17. Distinctive:

    Do not expose internal coordination types, temporary product types, or framework accidents as public surface.

    line 100
  18. Very specific:

    Prefer structured concurrency.

    line 106
  19. Very specific:

    Prefer deterministic tests over the functional core: pure inputs, pure outputs, injected clocks/filesystem/env at the shell.

    line 112

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Swift Functional Architecture

Default design skill for non-trivial Swift design and implementation.

Core doctrine:

Model data explicitly, keep behavior composable, isolate effects, preserve type information, and use the compiler to enforce relationships and invariants.

Prefer the smallest specialist skill when the task is narrowly about types, concurrency, testing, API naming, PR review, or broad architecture discovery. This skill is the default when shaping or implementing domain behavior.

Shape of a good design

typed input
→ pure/composable transformations
→ typed result
→ effectful adapter

Push effects to the shell:

  • filesystem, environment, process execution
  • XPC / network / IPC
  • terminal I/O, logging
  • clocks, randomness, persistence
  • setup/install mutations

Domain logic should not reach for ambient state such as FileManager.default, ProcessInfo.processInfo, or Date() when those values can be passed explicitly.

Values and functions first

Prefer:

  • value semantics and immutable data by default
  • explicit inputs and outputs
  • functions that model meaningful transformations
  • local mutation when it simplifies an implementation without leaking state

Use classes when identity, lifecycle, framework constraints, observation, or shared resource ownership are real. Do not use classes merely because behavior exists. Do not use structs dogmatically when identity matters.

Model state in types

Prefer enums and associated values for closed state spaces.

Avoid boolean/optional combinations that permit invalid states.

Use exhaustive switches when adding a domain state should force callers to reconsider behavior.

Prefer semantic types (PackID, RuleID, ShellCommand) over raw primitives when the distinction matters.

Make invalid states difficult to represent without turning simple code into a type puzzle.

Generics preserve relationships

Use generics when the compiler should know a real relationship between types.

Ask: what incorrect program becomes impossible?

Good uses: input/output relationships, same-type constraints, representation-independent algorithms, eliminating casts, preserving associated-type relationships.

Keep generic complexity local. Do not thread type parameters through unrelated modules merely to avoid one existential boundary.

When advanced typing makes call sites significantly harder without proportionate safety gain, prefer the simpler design.

Protocols are capabilities

Protocols should name meaningful capabilities, not accidental implementation reuse.

Prefer narrow protocols. Prefer composition over large kitchen-sink protocols.

Reach for a protocol when there are multiple real implementations, a meaningful abstraction boundary, or a test seam that must exist. Do not invent protocols solely for mocks when one real implementation plus injected values is enough.

some / any are deliberate

  • Prefer concrete types at module edges when the concrete type is the API.
  • Use some to hide a concrete type while preserving a single underlying type.
  • Use any only when runtime heterogeneity is intentional.
  • Prefer constrained existentials over open-ended erasure when possible.

Erasure is a design choice, not a convenience escape hatch.

Deep modules

Hide complexity behind small, stable interfaces.

Callers should know less, not more. A good module makes the next change cheap to make or remove.

Do not expose internal coordination types, temporary product types, or framework accidents as public surface.

Concurrency and ownership

Actors, Sendable, tasks, and locks belong at effect and ownership boundaries. Keep the functional core free of ambient concurrency when the work is a pure transformation.

Prefer structured concurrency. Make cancellation and lifetime explicit. Do not sprinkle @MainActor or unstructured Task {} to silence diagnostics.

For deeper concurrency work, load swift-concurrency. On Swift 6.4, load swift-64-whats-new for 6.4-only APIs (Continuation, UniqueArray, async defer, @c).

Testing posture

Prefer deterministic tests over the functional core: pure inputs, pure outputs, injected clocks/filesystem/env at the shell.

For Swift Testing craft, load swift-testing-pro.

When to hand off

NeedSkill
Generics / protocols / some/any / enum modeling depthswift-type-system-architecture
Actors / Sendable / tasks / cancellationswift-concurrency
Swift 6.4-only APIsswift-64-whats-new
Swift Testing qualityswift-testing-pro
Broad functional evolution candidatesswift-functional-codebase-evolution
Broad deep-module / boundary refactorsswiftify-codebase-architecture
Discover → spec → implement → review → ticket PRsswift-architecture-pipeline
Public/internal API naming fluencyswift-api-design-guidelines

Definition of done (design)

A change is well-shaped when:

  • requested behavior is correct
  • the functional core remains explicit
  • effects remain at appropriate boundaries
  • important state is modeled in types
  • useful type relationships are compiler-checked
  • generic complexity remains local
  • protocols represent meaningful capabilities
  • existential erasure is intentional
  • module depth is preserved or improved
  • concurrency and ownership are clear
  • tests prove meaningful behavior

The best code is not the code using the most Swift features.

The best code makes domain behavior obvious, composition natural, invalid programs difficult to express, and future changes cheap to make or remove.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.