engsys 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +202 -0
  3. package/core/agents/aaron.md +152 -0
  4. package/core/agents/bert.md +115 -0
  5. package/core/agents/isabelle.md +136 -0
  6. package/core/agents/jody.md +150 -0
  7. package/core/agents/leith.md +111 -0
  8. package/core/agents/marcelo.md +282 -0
  9. package/core/agents/melvin.md +101 -0
  10. package/core/agents/nyx.md +152 -0
  11. package/core/agents/otto.md +168 -0
  12. package/core/agents/patricia.md +283 -0
  13. package/core/commands/design-audit-local.md +155 -0
  14. package/core/commands/design-audit.md +235 -0
  15. package/core/commands/design-critique.md +96 -0
  16. package/core/commands/file-issue.md +22 -0
  17. package/core/commands/generate-project.md +45 -0
  18. package/core/commands/implement-issue.md +37 -0
  19. package/core/commands/implement-project.md +40 -0
  20. package/core/commands/naturalize.md +61 -0
  21. package/core/commands/pre-push.md +29 -0
  22. package/core/commands/prep-review-collect.md +130 -0
  23. package/core/commands/prep-review-finalize.md +121 -0
  24. package/core/commands/prep-review-publish.md +113 -0
  25. package/core/commands/prep-review.md +65 -0
  26. package/core/commands/project-closeout.md +25 -0
  27. package/core/skills/agentic-eval/SKILL.md +195 -0
  28. package/core/skills/chrome-devtools/SKILL.md +97 -0
  29. package/core/skills/code-review/SKILL.md +26 -0
  30. package/core/skills/gh-cli/SKILL.md +2202 -0
  31. package/core/skills/git-commit/SKILL.md +124 -0
  32. package/core/skills/git-workflow-agents/SKILL.md +462 -0
  33. package/core/skills/git-workflow-agents/reference.md +220 -0
  34. package/core/skills/github-actions/SKILL.md +190 -0
  35. package/core/skills/github-issues/SKILL.md +154 -0
  36. package/core/skills/llm-structured-outputs/SKILL.md +323 -0
  37. package/core/skills/llm-structured-outputs/references/provider-details.md +392 -0
  38. package/core/skills/pre-push/SKILL.md +115 -0
  39. package/core/skills/refactor/SKILL.md +645 -0
  40. package/core/skills/web-design-reviewer/SKILL.md +371 -0
  41. package/core/skills/webapp-testing/SKILL.md +127 -0
  42. package/core/skills/webapp-testing/test-helper.js +56 -0
  43. package/core/templates/CLAUDE.md.tmpl +98 -0
  44. package/core/templates/adr-template.md +67 -0
  45. package/core/templates/gh-issue-templates/bug.md +39 -0
  46. package/core/templates/gh-issue-templates/content.md +42 -0
  47. package/core/templates/gh-issue-templates/enhancement.md +36 -0
  48. package/core/templates/gh-issue-templates/feature.md +39 -0
  49. package/core/templates/gh-issue-templates/infrastructure.md +41 -0
  50. package/core/templates/post-edit-reminders.sh.tmpl +19 -0
  51. package/core/templates/settings.json.tmpl +90 -0
  52. package/core/templates/settings.local.json.tmpl +3 -0
  53. package/core/workflows/agent-implementation-workflow.md +346 -0
  54. package/core/workflows/generate-project.md +258 -0
  55. package/core/workflows/implement-project-workflow.md +190 -0
  56. package/core/workflows/issue-tracking.md +89 -0
  57. package/core/workflows/project-closeout-ceremony.md +77 -0
  58. package/core/workflows/review-workflow.md +266 -0
  59. package/engsys.config.example.yaml +46 -0
  60. package/install +202 -0
  61. package/lessons-library/README.md +80 -0
  62. package/lessons-library/async-callbacks-verify-liveness.md +15 -0
  63. package/lessons-library/change-isnt-done-until-every-surface-updated.md +15 -0
  64. package/lessons-library/claim-then-act-for-irreversible-ops.md +16 -0
  65. package/lessons-library/co-commit-entangled-work.md +15 -0
  66. package/lessons-library/dependabot-triage-playbook.md +17 -0
  67. package/lessons-library/deploy-by-digest-and-verify-the-running-revision.md +15 -0
  68. package/lessons-library/enforce-your-guarantee-at-your-boundary.md +16 -0
  69. package/lessons-library/gate-changes-on-measurement-not-vibes.md +15 -0
  70. package/lessons-library/iac-first-no-console-changes.md +15 -0
  71. package/lessons-library/independent-objective-review-gate.md +15 -0
  72. package/lessons-library/keep-an-immutable-source-of-truth.md +15 -0
  73. package/lessons-library/long-agent-runs-checkpoint-not-poll.md +15 -0
  74. package/lessons-library/model-identity-with-stable-ids-and-provenance.md +15 -0
  75. package/lessons-library/operator-choices-are-first-class.md +15 -0
  76. package/lessons-library/prefer-tool-enforced-structured-output.md +15 -0
  77. package/lessons-library/prove-causation-before-acting.md +15 -0
  78. package/lessons-library/re-read-state-before-acting.md +14 -0
  79. package/lessons-library/read-layer-tolerates-unbackfilled-rows.md +15 -0
  80. package/lessons-library/shell-safety-pipefail-and-validate-before-teardown.md +14 -0
  81. package/lessons-library/shift-correctness-left-and-distrust-false-greens.md +15 -0
  82. package/lessons-library/stray-control-bytes-hide-changes.md +14 -0
  83. package/lessons-library/tests-can-assert-the-bug.md +15 -0
  84. package/lessons-library/verify-ground-truth-not-reports.md +15 -0
  85. package/lessons-library/worktrees-need-bootstrap-from-origin-main.md +15 -0
  86. package/lib/commands.js +356 -0
  87. package/lib/generate-team-avatars.mjs +251 -0
  88. package/lib/manifest.js +155 -0
  89. package/lib/render.js +135 -0
  90. package/lib/selftest.js +90 -0
  91. package/lib/util.js +89 -0
  92. package/lib/yaml.js +156 -0
  93. package/optional-agents/gary.md +86 -0
  94. package/optional-agents/jos.md +136 -0
  95. package/optional-agents/sandy.md +101 -0
  96. package/optional-agents/steve.md +161 -0
  97. package/package.json +43 -0
  98. package/stacks/cloud/aws/claude.fragment.md +17 -0
  99. package/stacks/cloud/aws/settings.fragment.json +39 -0
  100. package/stacks/cloud/aws/skills/aws-deployment-preflight/SKILL.md +165 -0
  101. package/stacks/cloud/aws/skills/cloud-architecture-aws/SKILL.md +265 -0
  102. package/stacks/cloud/azure/claude.fragment.md +17 -0
  103. package/stacks/cloud/azure/settings.fragment.json +45 -0
  104. package/stacks/cloud/azure/skills/azure-deployment-preflight/SKILL.md +175 -0
  105. package/stacks/cloud/azure/skills/cloud-architecture-azure/SKILL.md +211 -0
  106. package/stacks/cloud/cloudflare/claude.fragment.md +21 -0
  107. package/stacks/cloud/cloudflare/settings.fragment.json +31 -0
  108. package/stacks/cloud/cloudflare/skills/cloud-architecture-cloudflare/SKILL.md +294 -0
  109. package/stacks/cloud/cloudflare/skills/cloudflare-deployment-preflight/SKILL.md +175 -0
  110. package/stacks/cloud/gcp/claude.fragment.md +17 -0
  111. package/stacks/cloud/gcp/settings.fragment.json +40 -0
  112. package/stacks/cloud/gcp/skills/cloud-architecture-gcp/SKILL.md +208 -0
  113. package/stacks/cloud/gcp/skills/gcp-deployment-preflight/SKILL.md +137 -0
  114. package/stacks/db/mongo/skills/mongo-conventions/SKILL.md +96 -0
  115. package/stacks/db/prisma/claude.fragment.md +49 -0
  116. package/stacks/db/prisma/skills/docker-database-package-copy/SKILL.md +44 -0
  117. package/stacks/db/prisma/skills/prisma-conventions/SKILL.md +37 -0
  118. package/stacks/domain/mobile-growth/skills/apple-ads/SKILL.md +184 -0
  119. package/stacks/domain/mobile-growth/skills/apple-ads/references/benchmark-notes.md +47 -0
  120. package/stacks/domain/mobile-growth/skills/apple-ads/references/official-links.md +53 -0
  121. package/stacks/domain/mobile-growth/skills/google-play-growth/SKILL.md +197 -0
  122. package/stacks/domain/mobile-growth/skills/google-play-growth/references/benchmark-notes.md +47 -0
  123. package/stacks/domain/mobile-growth/skills/google-play-growth/references/official-links.md +45 -0
  124. package/stacks/iac/bicep/claude.fragment.md +14 -0
  125. package/stacks/iac/bicep/settings.fragment.json +20 -0
  126. package/stacks/iac/bicep/skills/iac-bicep/SKILL.md +113 -0
  127. package/stacks/iac/cdk/claude.fragment.md +14 -0
  128. package/stacks/iac/cdk/settings.fragment.json +23 -0
  129. package/stacks/iac/cdk/skills/iac-cdk/SKILL.md +104 -0
  130. package/stacks/iac/terraform/claude.fragment.md +13 -0
  131. package/stacks/iac/terraform/settings.fragment.json +25 -0
  132. package/stacks/iac/terraform/skills/iac-terraform/SKILL.md +93 -0
  133. package/stacks/iac/terraform/skills/terraform-conventions/SKILL.md +87 -0
  134. package/stacks/lang/kotlin/skills/android-testing/SKILL.md +263 -0
  135. package/stacks/lang/kotlin/skills/jetpack-compose/SKILL.md +264 -0
  136. package/stacks/lang/kotlin/skills/kotlin-coroutines/SKILL.md +329 -0
  137. package/stacks/lang/python/skills/python-conventions/SKILL.md +61 -0
  138. package/stacks/lang/shell/skills/shell-scripting/SKILL.md +110 -0
  139. package/stacks/lang/swift/skills/swift-concurrency/SKILL.md +423 -0
  140. package/stacks/lang/swift/skills/swift-concurrency/references/approachable-concurrency.md +80 -0
  141. package/stacks/lang/swift/skills/swift-concurrency/references/concurrency-patterns.md +233 -0
  142. package/stacks/lang/swift/skills/swift-concurrency/references/swiftui-concurrency.md +187 -0
  143. package/stacks/lang/swift/skills/swift-concurrency/references/synchronization-primitives.md +341 -0
  144. package/stacks/lang/swift/skills/swift-testing/SKILL.md +497 -0
  145. package/stacks/lang/swift/skills/swift-testing/references/testing-advanced.md +106 -0
  146. package/stacks/lang/swift/skills/swift-testing/references/testing-patterns.md +504 -0
  147. package/stacks/lang/swift/skills/swiftdata/SKILL.md +334 -0
  148. package/stacks/lang/swift/skills/swiftdata/references/core-data-coexistence.md +504 -0
  149. package/stacks/lang/swift/skills/swiftdata/references/swiftdata-advanced.md +975 -0
  150. package/stacks/lang/swift/skills/swiftdata/references/swiftdata-queries.md +675 -0
  151. package/stacks/lang/swift/skills/swiftui-patterns/SKILL.md +371 -0
  152. package/stacks/lang/swift/skills/swiftui-patterns/references/architecture-patterns.md +486 -0
  153. package/stacks/lang/swift/skills/swiftui-patterns/references/deprecated-migration.md +1097 -0
  154. package/stacks/lang/swift/skills/swiftui-patterns/references/design-polish.md +780 -0
  155. package/stacks/lang/swift/skills/swiftui-patterns/references/platform-and-sharing.md +696 -0
  156. package/stacks/lang/typescript/skills/typescript-conventions/SKILL.md +91 -0
  157. package/stacks/platform/android/claude.fragment.md +40 -0
  158. package/stacks/platform/android/hooks/pre-push-gradle.sh +70 -0
  159. package/stacks/platform/android/settings.fragment.json +13 -0
  160. package/stacks/platform/android/skills/android-build-conventions/SKILL.md +247 -0
  161. package/stacks/platform/ios/claude.fragment.md +24 -0
  162. package/stacks/platform/ios/hooks/pre-push-xcodebuild.sh +82 -0
  163. package/stacks/platform/ios/settings.fragment.json +21 -0
  164. package/stacks/platform/ios/skills/xcodebuildmcp-simulator-logs/SKILL.md +76 -0
  165. package/stacks/platform/web/skills/frontend-testing/SKILL.md +246 -0
  166. package/stacks/platform/web/skills/react-conventions/SKILL.md +261 -0
  167. package/stacks/platform/web/skills/web-platform-conventions/SKILL.md +55 -0
  168. package/stacks/tooling/issue-tracker-github/claude.fragment.md +10 -0
  169. package/stacks/tooling/issue-tracker-github/settings.fragment.json +24 -0
  170. package/stacks/tooling/issue-tracker-github/skills/issue-tracker-github/SKILL.md +278 -0
  171. package/stacks/tooling/issue-tracker-linear/claude.fragment.md +17 -0
  172. package/stacks/tooling/issue-tracker-linear/settings.fragment.json +9 -0
  173. package/stacks/tooling/issue-tracker-linear/skills/issue-tracker-linear/SKILL.md +183 -0
@@ -0,0 +1,486 @@
1
+ # Architecture Patterns
2
+
3
+ ## Contents
4
+ - [MV Patterns](#mv-patterns)
5
+ - [App Wiring and Dependency Graph](#app-wiring-and-dependency-graph)
6
+ - [Lightweight Clients](#lightweight-clients)
7
+
8
+ ## MV Patterns
9
+
10
+ Default to Model-View (MV) in SwiftUI. Views are lightweight state expressions; models and services own business logic. Do not introduce view models unless the existing code already requires them.
11
+
12
+ ### Contents
13
+
14
+ - [Core Principles](#core-principles)
15
+ - [Why Not MVVM](#why-not-mvvm)
16
+ - [MV Pattern in Practice](#mv-pattern-in-practice)
17
+ - [When a View Model Already Exists](#when-a-view-model-already-exists)
18
+ - [Testing Strategy](#testing-strategy)
19
+ - [Source](#source)
20
+
21
+ ### Core Principles
22
+
23
+ - Views orchestrate UI flow using `@State`, `@Environment`, `@Query`, `.task`, and `.onChange`
24
+ - Services and shared models live in the environment, are testable in isolation, and encapsulate complexity
25
+ - Split large views into smaller subviews rather than introducing a view model
26
+ - Test models, services, and business logic; views should stay simple and declarative
27
+
28
+ ### Why Not MVVM
29
+
30
+ SwiftUI views are structs -- lightweight, disposable, and recreated frequently. Adding a ViewModel means fighting the framework's core design. Apple's own WWDC sessions (*Data Flow Through SwiftUI*, *Data Essentials in SwiftUI*, *Discover Observation in SwiftUI*) barely mention ViewModels.
31
+
32
+ Every ViewModel adds:
33
+ - More complexity and objects to synchronize
34
+ - More indirection and cognitive overhead
35
+ - Manual data fetching that duplicates SwiftUI/SwiftData mechanisms
36
+
37
+ ### MV Pattern in Practice
38
+
39
+ #### View with Environment-Injected Service
40
+
41
+ ```swift
42
+ struct FeedView: View {
43
+ @Environment(FeedClient.self) private var client
44
+ @Environment(AppTheme.self) private var theme
45
+
46
+ enum ViewState {
47
+ case loading, error(String), loaded([Post])
48
+ }
49
+
50
+ @State private var viewState: ViewState = .loading
51
+ @State private var isRefreshing = false
52
+
53
+ var body: some View {
54
+ NavigationStack {
55
+ List {
56
+ switch viewState {
57
+ case .loading:
58
+ ProgressView("Loading feed...")
59
+ .frame(maxWidth: .infinity)
60
+ .listRowSeparator(.hidden)
61
+ case .error(let message):
62
+ ContentUnavailableView("Error", systemImage: "exclamationmark.triangle",
63
+ description: Text(message))
64
+ .listRowSeparator(.hidden)
65
+ case .loaded(let posts):
66
+ ForEach(posts) { post in
67
+ PostRowView(post: post)
68
+ }
69
+ }
70
+ }
71
+ .listStyle(.plain)
72
+ .refreshable { await loadFeed() }
73
+ .task { await loadFeed() }
74
+ }
75
+ }
76
+
77
+ private func loadFeed() async {
78
+ do {
79
+ let posts = try await client.getFeed()
80
+ viewState = .loaded(posts)
81
+ } catch {
82
+ viewState = .error(error.localizedDescription)
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ #### Using .task(id:) and .onChange
89
+
90
+ SwiftUI modifiers act as small state reducers:
91
+
92
+ ```swift
93
+ .task(id: searchText) {
94
+ guard !searchText.isEmpty else { return }
95
+ await searchFeed(query: searchText)
96
+ }
97
+ .onChange(of: isInSearch, initial: false) {
98
+ guard !isInSearch else { return }
99
+ Task { await fetchSuggestedFeed() }
100
+ }
101
+ ```
102
+
103
+ #### App-Level Environment Setup
104
+
105
+ ```swift
106
+ @main
107
+ struct MyApp: App {
108
+ @State var client = APIClient()
109
+ @State var auth = Auth()
110
+ @State var router = AppRouter(initialTab: .feed)
111
+
112
+ var body: some Scene {
113
+ WindowGroup {
114
+ ContentView()
115
+ .environment(client)
116
+ .environment(auth)
117
+ .environment(router)
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ All dependencies are injected once and available everywhere.
124
+
125
+ #### SwiftData: The Perfect MV Example
126
+
127
+ SwiftData was built to work directly in views:
128
+
129
+ ```swift
130
+ struct BookListView: View {
131
+ @Query private var books: [Book]
132
+ @Environment(\.modelContext) private var modelContext
133
+
134
+ var body: some View {
135
+ List {
136
+ ForEach(books) { book in
137
+ BookRowView(book: book)
138
+ .swipeActions {
139
+ Button("Delete", role: .destructive) {
140
+ modelContext.delete(book)
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ Forcing a ViewModel here means manual fetching, manual refresh, and boilerplate everywhere.
150
+
151
+ ### When a View Model Already Exists
152
+
153
+ If a view model exists in the codebase:
154
+ - Make it non-optional when possible
155
+ - Pass dependencies via `init`, then forward them into the view model in the view's `init`
156
+ - Store as `@State` in the root view that owns it
157
+ - Avoid `bootstrapIfNeeded` patterns
158
+
159
+ ```swift
160
+ @State private var viewModel: SomeViewModel
161
+
162
+ init(dependency: Dependency) {
163
+ _viewModel = State(initialValue: SomeViewModel(dependency: dependency))
164
+ }
165
+ ```
166
+
167
+ ### Testing Strategy
168
+
169
+ - Unit test services and business logic
170
+ - Test models and transformations
171
+ - Use SwiftUI previews for visual regression
172
+ - Use UI automation for end-to-end tests
173
+ - Views should be simple enough that they do not need dedicated unit tests
174
+
175
+ ### Source
176
+
177
+ Based on guidance from "SwiftUI in 2025: Forget MVVM" (Thomas Ricouard) and Apple WWDC sessions on SwiftUI data flow.
178
+
179
+ ## App Wiring and Dependency Graph
180
+
181
+ ### Contents
182
+
183
+ - [Intent](#intent)
184
+ - [Recommended Structure](#recommended-structure)
185
+ - [Root Shell Example](#root-shell-example)
186
+ - [Dependency Graph Modifier](#dependency-graph-modifier)
187
+ - [SwiftData / ModelContainer](#swiftdata-modelcontainer)
188
+ - [Sheet Routing (Enum-Driven)](#sheet-routing-enum-driven)
189
+ - [App Entry Point](#app-entry-point)
190
+ - [Deep Linking](#deep-linking)
191
+ - [When to Use](#when-to-use)
192
+ - [Caveats](#caveats)
193
+
194
+ ### Intent
195
+
196
+ Wire the app shell (TabView + NavigationStack + sheets) and install a global dependency graph (environment objects, services, streaming clients, SwiftData ModelContainer) in one place.
197
+
198
+ ### Recommended Structure
199
+
200
+ 1. Root view sets up tabs, per-tab routers, and sheets.
201
+ 2. A dedicated view modifier installs global dependencies and lifecycle tasks (auth state, streaming watchers, push tokens, data containers).
202
+ 3. Feature views pull only what they need from the environment; feature-specific state stays local.
203
+
204
+ ### Root Shell Example
205
+
206
+ ```swift
207
+ @MainActor
208
+ struct AppView: View {
209
+ @State private var selectedTab: AppTab = .home
210
+ @State private var tabRouter = TabRouter()
211
+
212
+ var body: some View {
213
+ TabView(selection: $selectedTab) {
214
+ ForEach(AppTab.allCases) { tab in
215
+ let router = tabRouter.router(for: tab)
216
+ Tab(value: tab) {
217
+ NavigationStack(path: tabRouter.binding(for: tab)) {
218
+ tab.makeContentView()
219
+ }
220
+ .withSheetDestinations(sheet: Binding(
221
+ get: { router.presentedSheet },
222
+ set: { router.presentedSheet = $0 }
223
+ ))
224
+ .environment(router)
225
+ } label: {
226
+ tab.label
227
+ }
228
+ }
229
+ }
230
+ .tabBarMinimizeBehavior(.onScrollDown)
231
+ .withAppDependencyGraph()
232
+ }
233
+ }
234
+ ```
235
+
236
+ #### AppTab Enum
237
+
238
+ ```swift
239
+ @MainActor
240
+ enum AppTab: Identifiable, Hashable, CaseIterable {
241
+ case home, notifications, settings
242
+ var id: String { String(describing: self) }
243
+
244
+ @ViewBuilder
245
+ func makeContentView() -> some View {
246
+ switch self {
247
+ case .home: HomeView()
248
+ case .notifications: NotificationsView()
249
+ case .settings: SettingsView()
250
+ }
251
+ }
252
+
253
+ @ViewBuilder
254
+ var label: some View {
255
+ switch self {
256
+ case .home: Label("Home", systemImage: "house")
257
+ case .notifications: Label("Notifications", systemImage: "bell")
258
+ case .settings: Label("Settings", systemImage: "gear")
259
+ }
260
+ }
261
+ }
262
+ ```
263
+
264
+ #### Router Skeleton
265
+
266
+ ```swift
267
+ @MainActor
268
+ @Observable
269
+ final class RouterPath {
270
+ var path: [Route] = []
271
+ var presentedSheet: SheetDestination?
272
+ }
273
+
274
+ enum Route: Hashable {
275
+ case detail(id: String)
276
+ }
277
+ ```
278
+
279
+ ### Dependency Graph Modifier
280
+
281
+ Use a single modifier to install environment objects and handle lifecycle hooks. This keeps wiring consistent and avoids forgetting a dependency at call sites.
282
+
283
+ ```swift
284
+ extension View {
285
+ func withAppDependencyGraph(
286
+ client: APIClient = .shared,
287
+ auth: Auth = .shared,
288
+ theme: Theme = .shared,
289
+ toastCenter: ToastCenter = .shared
290
+ ) -> some View {
291
+ environment(client)
292
+ .environment(auth)
293
+ .environment(theme)
294
+ .environment(toastCenter)
295
+ .task(id: auth.currentAccount?.id) {
296
+ // Re-seed services when account changes
297
+ await client.configure(for: auth.currentAccount)
298
+ }
299
+ }
300
+ }
301
+ ```
302
+
303
+ Notes:
304
+ - The `.task(id:)` hooks respond to account/client changes, re-seeding services and watcher state.
305
+ - Keep the modifier focused on global wiring; feature-specific state stays within features.
306
+ - Adjust types to match your project.
307
+
308
+ ### SwiftData / ModelContainer
309
+
310
+ Install `ModelContainer` at the root so all feature views share the same store:
311
+
312
+ ```swift
313
+ extension View {
314
+ func withModelContainer() -> some View {
315
+ modelContainer(for: [Draft.self, LocalTimeline.self, TagGroup.self])
316
+ }
317
+ }
318
+ ```
319
+
320
+ A single container avoids duplicated stores per sheet or tab and keeps data consistent.
321
+
322
+ ### Sheet Routing (Enum-Driven)
323
+
324
+ Centralize sheets with a small enum and a helper modifier:
325
+
326
+ ```swift
327
+ enum SheetDestination: Identifiable {
328
+ case composer
329
+ case settings
330
+ var id: String { String(describing: self) }
331
+ }
332
+
333
+ extension View {
334
+ func withSheetDestinations(sheet: Binding<SheetDestination?>) -> some View {
335
+ sheet(item: sheet) { destination in
336
+ switch destination {
337
+ case .composer:
338
+ ComposerView().withEnvironments()
339
+ case .settings:
340
+ SettingsView().withEnvironments()
341
+ }
342
+ }
343
+ }
344
+ }
345
+ ```
346
+
347
+ Enum-driven sheets keep presentation centralized and testable; adding a new sheet means one enum case and one switch branch.
348
+
349
+ ### App Entry Point
350
+
351
+ ```swift
352
+ @main
353
+ struct MyApp: App {
354
+ @State var client = APIClient()
355
+ @State var auth = Auth()
356
+ @State var router = AppRouter(initialTab: .home)
357
+
358
+ var body: some Scene {
359
+ WindowGroup {
360
+ AppView()
361
+ .environment(client)
362
+ .environment(auth)
363
+ .environment(router)
364
+ }
365
+ }
366
+ }
367
+ ```
368
+
369
+ ### Deep Linking
370
+
371
+ Store `NavigationPath` as `Codable` for state restoration. Handle incoming URLs with `.onOpenURL`:
372
+
373
+ ```swift
374
+ .onOpenURL { url in
375
+ guard let route = Route(from: url) else { return }
376
+ router.navigate(to: route)
377
+ }
378
+ ```
379
+
380
+ See the `swiftui-navigation` skill for full URL routing patterns.
381
+
382
+ ### When to Use
383
+
384
+ - Apps with multiple packages/modules that share environment objects and services
385
+ - Apps that need to react to account/client changes and rewire streaming/push safely
386
+ - Any app that wants consistent TabView + NavigationStack + sheet wiring without repeating environment setup
387
+
388
+ ### Caveats
389
+
390
+ - Keep the dependency modifier slim; do not put feature state or heavy logic there
391
+ - Ensure `.task(id:)` work is lightweight or cancelled appropriately; long-running work belongs in services
392
+ - If unauthenticated clients exist, gate streaming/watch calls to avoid reconnect spam
393
+
394
+ ## Lightweight Clients
395
+
396
+ Use this pattern to keep networking or service dependencies simple and testable without introducing a full view model or heavy DI framework. It works well for SwiftUI apps where you want a small, composable API surface that can be swapped in previews/tests.
397
+
398
+ ### Intent
399
+ - Provide a tiny "client" type made of async closures.
400
+ - Keep business logic in a store or feature layer, not the view.
401
+ - Enable easy stubbing in previews/tests.
402
+
403
+ ### Minimal shape
404
+ ```swift
405
+ struct SomeClient {
406
+ var fetchItems: (_ limit: Int) async throws -> [Item]
407
+ var search: (_ query: String, _ limit: Int) async throws -> [Item]
408
+ }
409
+
410
+ extension SomeClient {
411
+ static func live(baseURL: URL = URL(string: "https://example.com")!) -> SomeClient {
412
+ let session = URLSession.shared // Prototyping only. For production, create a URLSession with timeoutIntervalForRequest: 30, timeoutIntervalForResource: 300, waitsForConnectivity: true, and a URLCache.
413
+ return SomeClient(
414
+ fetchItems: { limit in
415
+ // build URL, call session, decode
416
+ },
417
+ search: { query, limit in
418
+ // build URL, call session, decode
419
+ }
420
+ )
421
+ }
422
+ }
423
+ ```
424
+
425
+ ### Usage pattern
426
+ ```swift
427
+ @MainActor
428
+ @Observable final class ItemsStore {
429
+ enum LoadState { case idle, loading, loaded, failed(String) }
430
+
431
+ var items: [Item] = []
432
+ var state: LoadState = .idle
433
+ private let client: SomeClient
434
+
435
+ init(client: SomeClient) {
436
+ self.client = client
437
+ }
438
+
439
+ func load(limit: Int = 20) async {
440
+ state = .loading
441
+ do {
442
+ items = try await client.fetchItems(limit)
443
+ state = .loaded
444
+ } catch {
445
+ state = .failed(error.localizedDescription)
446
+ }
447
+ }
448
+ }
449
+ ```
450
+
451
+ ```swift
452
+ struct ContentView: View {
453
+ @Environment(ItemsStore.self) private var store
454
+
455
+ var body: some View {
456
+ List(store.items) { item in
457
+ Text(item.title)
458
+ }
459
+ .task { await store.load() }
460
+ }
461
+ }
462
+ ```
463
+
464
+ ```swift
465
+ @main
466
+ struct MyApp: App {
467
+ @State private var store = ItemsStore(client: .live())
468
+
469
+ var body: some Scene {
470
+ WindowGroup {
471
+ ContentView()
472
+ .environment(store)
473
+ }
474
+ }
475
+ }
476
+ ```
477
+
478
+ ### Guidance
479
+ - Keep decoding and URL-building in the client; keep state changes in the store.
480
+ - Make the store accept the client in `init` and keep it private.
481
+ - Avoid global singletons; use `.environment` for store injection.
482
+ - If you need multiple variants (mock/stub), add `static func mock(...)`.
483
+
484
+ ### Pitfalls
485
+ - Don’t put UI state in the client; keep state in the store.
486
+ - Don’t capture `self` or view state in the client closures.