Sourcery
RepositoryFreeMeta-programming for Swift, stop writing boilerplate code.
Capabilities13 decomposed
swiftsyntax-based ast parsing with intelligent caching
Medium confidenceParses Swift source files using Apple's SwiftSyntax framework (since v1.9.0) to build a complete abstract syntax tree, extracting type definitions, methods, variables, and relationships. Implements an intelligent caching system that fingerprints file contents and skips re-parsing unchanged files, dramatically improving performance on large codebases by avoiding redundant syntax analysis.
Uses Apple's official SwiftSyntax framework for structurally-aware parsing instead of regex or custom lexers, combined with file-level content hashing for incremental re-parsing — enabling accurate handling of Swift's complex syntax including generics, opaque types, and macro annotations
More accurate than regex-based parsers (handles edge cases like string literals containing type syntax) and faster than re-parsing on every invocation due to intelligent caching, though slower than simple text-based pattern matching for small files
multi-template language support with stencil, swift, and javascript
Medium confidenceSupports three distinct template languages — Stencil (Jinja2-like syntax), native Swift templates, and JavaScript — allowing developers to choose the most ergonomic approach for their code generation needs. Each template language has access to the complete parsed type model through a unified context object, enabling templates to introspect types, iterate over methods/variables, and conditionally generate code based on annotations or type characteristics.
Supports three distinct template languages (Stencil, Swift, JavaScript) with unified access to the same parsed type model, allowing developers to choose the most ergonomic approach — Swift templates can use native language features, Stencil templates leverage familiar Jinja2 syntax, and JavaScript templates enable cross-platform logic
More flexible than single-language generators (e.g., Sourcegen which only supports Stencil) and more accessible than code-as-configuration approaches (e.g., SwiftGen's YAML) by supporting multiple familiar syntaxes
type model introspection api for templates
Medium confidenceExposes a comprehensive object model (Type, Class, Struct, Enum, Protocol, Method, Variable, Parameter, etc.) to templates, allowing introspection of type characteristics, methods, properties, and relationships. Templates can query type metadata (name, kind, access level, annotations), iterate over methods and variables with full signature information, and traverse type relationships to make generation decisions based on type structure.
Exposes a rich object model (Type, Method, Variable, Parameter, etc.) to templates with full access to parsed type information including signatures, annotations, and relationships, enabling templates to make sophisticated code generation decisions based on type structure without re-parsing
More complete than simple string-based type information (enables type-aware generation) and more accessible than requiring templates to parse AST directly (abstracts away syntax details)
multi-platform swift code generation for ios, macos, tvos, watchos
Medium confidenceGenerates Swift code compatible with multiple Apple platforms (iOS, macOS, tvOS, watchOS) by understanding platform-specific APIs and availability annotations. Templates can query platform availability information and conditionally generate platform-specific code, enabling creation of cross-platform libraries and frameworks that adapt generated code to target platforms.
Parses @available annotations to understand platform-specific APIs and makes this information available to templates, enabling generation of platform-adapted code without requiring templates to manually parse availability syntax
More maintainable than manual platform-specific code generation (availability information is automatically extracted) and more flexible than single-platform generators, though requires templates to implement platform-specific logic
error reporting and diagnostics with file/line information
Medium confidenceProvides detailed error messages and diagnostics that include source file paths and line numbers, helping developers quickly locate and fix issues in source code or templates. Errors during parsing, template processing, or code generation include context about what failed and where, reducing debugging time for code generation issues.
Includes file paths and line numbers in error messages for parsing, template processing, and code generation errors, helping developers quickly locate issues in source code or templates without manual debugging
More helpful than generic error messages (includes context about location and cause) and more accessible than requiring manual debugging with print statements
annotation-driven code generation with documentation comments
Medium confidenceParses documentation comments (/// annotations) embedded in Swift source code to extract metadata that controls code generation behavior. Developers can annotate types, methods, and variables with custom markers (e.g., // sourcery: AutoMockable) that templates can query to conditionally generate code — enabling declarative, in-source configuration of which types receive generated code without separate configuration files.
Extracts code generation directives from documentation comments (/// sourcery: annotations) parsed by SwiftSyntax, allowing developers to declare generation intent inline with type definitions rather than in separate configuration files — the parsed annotations are available to templates as queryable metadata on Type objects
More discoverable than external configuration files (annotations live next to the code they affect) and more flexible than attribute-based approaches (e.g., @Codable) which require language-level support, though less type-safe than compile-time annotations
type relationship composition and inheritance resolution
Medium confidenceBuilds a complete type relationship graph by composing parsed types to resolve inheritance chains, protocol conformance, and type dependencies. The Composer component walks the parsed AST to establish parent-child relationships, protocol implementations, and generic type bindings, creating a queryable model where templates can traverse inheritance hierarchies, find all types conforming to a protocol, or identify generic type parameters.
The Composer component explicitly walks the parsed AST to resolve type relationships (inheritance, protocol conformance, generic bindings) into a queryable graph structure, allowing templates to traverse hierarchies and find related types — rather than requiring templates to manually parse relationship information
More complete than simple type listing (enables hierarchical queries) and more efficient than re-parsing relationships in each template (relationships are computed once during composition phase)
configuration-driven file discovery and multi-source input
Medium confidenceSupports flexible input configuration through YAML files (.sourcery.yml) and command-line arguments, enabling developers to specify source files, directories, Xcode project targets, and Swift package targets as input sources. The configuration system resolves these diverse input types into a unified list of Swift files to parse, supporting project-level configuration that can be version-controlled and shared across teams.
Supports three input source types (direct files, Xcode project targets, Swift package targets) resolved through a unified configuration system that can be specified via YAML or CLI, allowing teams to configure code generation at the project level rather than manually listing files
More flexible than file-list-based approaches (e.g., specifying individual files) because it understands Xcode and SPM project structures, and more maintainable than CLI-only configuration because YAML files can be version-controlled
file watching and continuous code generation
Medium confidenceImplements optional file system watching that monitors source files and templates for changes, automatically re-running the code generation pipeline when modifications are detected. The watcher uses platform-specific file system events (FSEvents on macOS, inotify on Linux) to trigger incremental re-parsing and re-generation, enabling developers to see generated code updates in real-time during development without manual invocation.
Implements optional file system watching using platform-specific APIs (FSEvents/inotify) that automatically triggers incremental re-parsing and code generation when source or template files change, enabling real-time feedback during development without requiring manual re-invocation
More convenient than manual re-invocation (typical of build-time code generators) and more responsive than polling-based approaches, though adds background process overhead compared to one-shot generation
automockable protocol mock generation
Medium confidenceProvides a built-in code generator that automatically creates mock implementations of protocols annotated with // sourcery: AutoMockable. The generator introspects protocol method signatures, parameter types, and return types to synthesize mock objects with recording/verification capabilities, eliminating manual mock writing for unit testing. Mocks include call tracking, argument capture, and return value configuration.
Generates protocol mocks with built-in call tracking and argument capture by introspecting protocol method signatures and synthesizing mock implementations, rather than requiring manual mock writing or runtime reflection-based mocking frameworks
More maintainable than manual mocks (automatically updates when protocol changes) and more type-safe than runtime mocking frameworks (e.g., Mockito) because mocks are generated code with compile-time type checking
autohashable and autoequatable synthesis
Medium confidenceAutomatically generates Hashable and Equatable protocol implementations for types annotated with // sourcery: AutoHashable or AutoEquatable. The generator introspects all stored properties of the type and synthesizes hash() and == implementations that include all properties, ensuring consistency between equality and hashing semantics without manual implementation.
Synthesizes Equatable and Hashable implementations by introspecting all stored properties and generating implementations that include all properties, ensuring hash/equality consistency without manual implementation or reliance on Swift's automatic synthesis (which has limitations)
More explicit than Swift's automatic Equatable/Hashable synthesis (which can be surprising) and more maintainable than manual implementations (automatically updates when properties change)
custom code generator templates with full type model access
Medium confidenceEnables developers to write custom code generators by creating templates (in Stencil, Swift, or JavaScript) that have full access to the parsed type model, including types, methods, variables, annotations, and relationships. Templates can iterate over types, filter by annotations or characteristics, and generate arbitrary code based on introspection, allowing creation of domain-specific code generators beyond built-in generators.
Provides full access to the parsed type model (Type, Method, Variable, Annotation objects) in templates, allowing developers to introspect types, filter by characteristics, and generate arbitrary code — enabling creation of custom generators for domain-specific patterns without modifying Sourcery core
More flexible than built-in generators (supports arbitrary code generation patterns) and more accessible than writing Swift plugins (templates don't require compilation), though less performant than compiled code generators
incremental output file generation with diff-based updates
Medium confidenceGenerates output files with awareness of existing content, using diff-based comparison to determine which files have actually changed. Only modified files are written to disk, reducing unnecessary file system churn and avoiding triggering unnecessary Xcode rebuilds. The system preserves file modification times for unchanged files, enabling build systems to skip recompilation when generated code hasn't changed.
Implements diff-based output file writing that compares generated content with existing files and only writes when content has changed, preserving file modification times to avoid triggering unnecessary rebuilds in Xcode and other build systems
More build-system-aware than naive file writing (which always touches files) and reduces CI/CD pipeline time by avoiding spurious rebuilds, though adds slight overhead for diff comparison
Capabilities are decomposed by AI analysis. Each maps to specific user intents and improves with match feedback.
Related Artifactssharing capabilities
Artifacts that share capabilities with Sourcery, ranked by overlap. Discovered automatically through the match graph.
ts-morph
TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Prettier
Opinionated code formatter for JS, TS, CSS, HTML.
JS Refactoring Assistant
Edit, modernize, and refactor JavaScript, TypeScript, React, and Vue.js code effectively with over 120 code actions.
@effect/ai-anthropic
Effect modules for working with AI apis
CodeVisualizer
Real-time interactive flowcharts for your code
AI.JSX
[Twitter](https://twitter.com/fixieai)
Best For
- ✓iOS/macOS teams with large codebases (1000+ Swift files)
- ✓Developers building custom code generators on top of Sourcery
- ✓Teams needing incremental code generation in CI/CD pipelines
- ✓Teams with diverse template language preferences
- ✓Projects requiring complex conditional logic in code generation
- ✓Organizations migrating from other code generators with Stencil templates
- ✓Template developers writing custom code generators
- ✓Teams building sophisticated code generation logic based on type structure
Known Limitations
- ⚠Cache invalidation is file-level only — changes to imported types don't automatically invalidate dependent files
- ⚠SwiftSyntax parsing adds ~50-200ms per file depending on complexity
- ⚠No support for parsing Objective-C headers or mixed-language projects
- ⚠Cache directory must be writable; no in-memory-only mode for sandboxed environments
- ⚠Stencil templates have limited performance for very large type models (100+ types with 1000+ methods)
- ⚠Swift templates require compilation, adding ~2-5 seconds per template change
Requirements
Input / Output
UnfragileRank
UnfragileRank is computed from adoption signals, documentation quality, ecosystem connectivity, match graph feedback, and freshness. No artifact can pay for a higher rank.
Repository Details
Last commit: Feb 11, 2026
About
Meta-programming for Swift, stop writing boilerplate code.
Categories
Alternatives to Sourcery
Are you the builder of Sourcery?
Claim this artifact to get a verified badge, access match analytics, see which intents users search for, and manage your listing.
Get the weekly brief
New tools, rising stars, and what's actually worth your time. No spam.
Data Sources
Looking for something else?
Search →