This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an iOS educational app demonstrating all 23 Gang of Four (GoF) design patterns with practical Swift/SwiftUI implementations. The app is organized into three pattern categories: Creational, Structural, and Behavioral. Each pattern includes working code examples, visual demonstrations, and detailed markdown documentation.
The project follows a strict layered architecture:
DataLayer: Repository pattern for data access
Models/: Domain models (DesignPatternModel, DesignPatternCategory)Repositories/: Data access logic (DesignPatternsRepository)Responses/: Data transfer objects for JSON decoding
PresentationLayer: MVVM + Routing
App/: App entry point with dependency injection setupGeneral/: Shared utilities, extensions, routing infrastructureStories/: Feature modules organized by screen- Each story contains ViewModels, Views, and DisplayModels
- Mock implementations provided for previews
SupportingFiles: Generated code, assets, and data
Generated/: SwiftGen outputs (JSON+Generated.swift)Data/: JSON files (GOFPatterns.json)
Custom Router implementation supporting:
NavigationType: push, sheet, fullScreenCoverRoutableprotocol: Each screen conforms and provides its viewRouter<Destination>: Generic router managing NavigationPath and presentation state- Usage: Define routes as enums conforming to
Routable
Uses NerdzInject for simple DI:
- Dependencies registered in
DesignPatternsApp.init() - Inject via
@InjectedorNerdzInject.shared.getObject() - Register protocols with concrete implementations
Pattern implementations live in PresentationLayer/Stories/Samples/:
Creational/: AbstractFactory, Builder, FactoryMethod, Prototype, SingletonBehavioral/: ChainOfResponsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, TemplateMethod, VisitorStructural/: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy
Each sample is a self-contained Swift file demonstrating the pattern with SwiftUI views.
SwiftGen generates type-safe accessors from JSON data:
swiftgen config runConfiguration: swiftgen.yml
- Inputs:
DesignPatterns/SupportingFiles/Data/ - Output:
DesignPatterns/SupportingFiles/Generated/JSON+Generated.swift
SwiftLint enforces strict code style (see swiftlint.yml):
swiftlintKey rules:
- 4-space indentation
- Explicit
selfrequired - Force unwrapping forbidden
- No
printstatements (custom rule) - UIKit forbidden in Repository/Request files
- Image/color naming conventions enforced
Standard Xcode build:
xcodebuild -scheme DesignPatterns -configuration Debug buildOr build via Xcode (Cmd+B).
Write tests following TDD principles with XCTest. Mock ViewModels already exist for preview purposes (e.g., MockPatternsListViewModel, MockPatternDetailsViewModel).
- NerdzInject: Lightweight dependency injection
- NerdzUtils: Utility extensions
- SwiftMessages: Toast/message presentation
- SFSafeSymbols: Type-safe SF Symbols
- KeychainAccess: Secure storage
- xcstrings-tool-plugin: Localization tooling
ViewModels follow a protocol-based approach:
protocol PatternsListViewModelType: ObservableObject {
var state: ViewState { get }
func loadPatterns()
}
final class PatternsListViewModel: PatternsListViewModelType {
// Implementation
}UI-specific models separate from domain models:
PatternsListDisplayModelPatternsListSectionDisplayModelPatternsListCategoryDisplayModel
App-wide message display using AppMessagableViewModelType:
- ViewModels conforming to this protocol can show error/success messages
- Uses SwiftMessages library for toast notifications
Uses String Catalog (.xcstrings). Generated accessors via:
String.localizable(.someKey)Markdown files in MDFiles/:
Main.md: Complete guide to all 23 patterns with pros/cons/examples- Individual pattern docs (AbstractFactory.md, Builder.md, etc.)
Reference these when implementing or explaining patterns.
- Create Swift file in appropriate category folder under
PresentationLayer/Stories/Samples/ - Implement the pattern with protocols and concrete classes
- Add SwiftUI view demonstrating the pattern
- Update
GOFPatterns.jsonwith pattern metadata - Run
swiftgen config runto regenerate accessors - Update routing if pattern needs dedicated screen
- Add case to route enum (e.g.,
RootRoute) - Implement
Routableprotocol (specifynavigationTypeandviewToDisplay) - Use
router.routeTo(.yourRoute)to navigate
Data source: DesignPatterns/SupportingFiles/Data/GOFPatterns.json
- Modify JSON
- Run SwiftGen:
swiftgen config run - Access via type-safe generated code
- Never use
print()(use proper logging) - Avoid
public/openunless necessary (prefer internal) - Use
-not_in asset names - Image names must end with
-iconor-image - Color names must end with
-color - Keep closure bodies under 100 lines
- Follow MARK comment format:
// MARK: - Section