Skip to content

Commit 3dc1c7a

Browse files
authored
chore: added detailed architecture and AI context docs (#130)
1 parent ab61565 commit 3dc1c7a

File tree

11 files changed

+1607
-39
lines changed

11 files changed

+1607
-39
lines changed

.github/config/spellcheck-wordlist.txt

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
1+
ActorVariable
2+
APIs
3+
AssociatedVariable
4+
AttributeExpander
5+
Benchmarking
16
Bool
2-
CocoaPods
7+
ClassVariable
8+
Codable
39
CodedIn
410
CodingKey
11+
CodingKeys
12+
CodingKeysMap
13+
CocoaPods
14+
ConstraintGenerator
515
DateCoder
16+
Decodable
17+
DocumentationExtension
18+
Encodable
19+
EnumCaseVariable
20+
EnumSwitcherVariable
21+
EnumVariable
22+
ExprRegistration
623
Github
724
HelperCoder
825
HelperCoders
26+
IgnoreEncoding
927
JSON
1028
LossySequenceCoder
11-
Codable
12-
Encodable
13-
Decodable
1429
MetaCodable
30+
MetaCodable's
1531
MetaProtocolCodable
1632
Midbin
33+
PathRegistration
34+
PluginCore
35+
Podfile
36+
Pre
37+
PropertyVariableTreeNode
1738
README
1839
Refactorings
40+
Runtime
1941
SPM
42+
SequenceCoder
43+
SwiftData
44+
SwiftFormat
45+
SwiftUI
2046
SwiftyLab
2147
TabNavigator
48+
Trie
49+
VSCode
2250
ValueCoder
2351
Xcode
2452
ae
@@ -27,8 +55,15 @@ bc
2755
boolean
2856
cb
2957
cd
58+
cocoapods
59+
conformances
60+
customizable
3061
da
62+
datasets
3163
eb
64+
enum
65+
enums
66+
expander
3267
faq
3368
formatters
3469
getter
@@ -39,30 +74,20 @@ https
3974
initializer
4075
initializers
4176
json
77+
lowercasing
4278
macOS
4379
mahunt
4480
memberwise
81+
mergeBehavior
82+
preprocessing
4583
sexualized
4684
socio
4785
soumya
4886
structs
4987
swiftpackageindex
5088
tvOS
89+
typealias
5190
variadic
5291
vscode
5392
watchOS
5493
www
55-
typealias
56-
customizable
57-
enum
58-
enums
59-
conformances
60-
Podfile
61-
cocoapods
62-
DocumentationExtension
63-
mergeBehavior
64-
lowercasing
65-
SwiftData
66-
SwiftUI
67-
IgnoreEncoding
68-
VSCode

.github/copilot-instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
We follow swift camel case for naming folders and files.
2+
We use swift-format to for formatting and linting. Custom formatting rules are defined in .swift-format file.
3+
We use swift testing to write tests.
4+
Always remove empty spaces in generated code.

CONTRIBUTING.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,24 @@ Please read it before you start participating.
55

66
_See also: [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md)_
77

8+
## Developer Documentation
9+
10+
Detailed documentation for contributors is available in the [Contributing](Contributing/README.md) folder:
11+
12+
- [Architecture Overview](Contributing/ARCHITECTURE.md) - Core components and system design
13+
- [Macro Processing Pipeline](Contributing/MACRO_PROCESSING.md) - Class hierarchy and code generation
14+
- [Coding Strategies](Contributing/CODING_STRATEGIES.md) - Implementation patterns and helper systems
15+
- [Build Plugin System](Contributing/BUILD_PLUGIN.md) - Plugin architecture and integration
16+
- [Testing and Development](Contributing/TESTING.md) - Testing methodology and best practices
17+
- [Troubleshooting](Contributing/TROUBLESHOOTING.md) - Common issues and solutions
18+
819
## Submitting Pull Requests
920

10-
You can contribute by fixing bugs or adding new features. For larger code changes, we first recommend discussing them in our [Github issues](https://github.com/SwiftyLab/MetaCodable/issues). When submitting a pull request, please add relevant tests and ensure your changes don't break any existing tests (see [Automated Tests](#automated-tests) below).
21+
You can contribute by fixing bugs or adding new features. For larger code changes, we first recommend:
22+
1. Review the [Architecture Overview](Contributing/ARCHITECTURE.md) to understand the system
23+
2. Discuss your proposed changes in our [Github issues](https://github.com/SwiftyLab/MetaCodable/issues)
24+
3. Read the relevant documentation in the [Contributing](Contributing/README.md) folder
25+
4. Submit your pull request with appropriate tests (see [Testing](Contributing/TESTING.md))
1126

1227
### Things you will need
1328

@@ -39,7 +54,9 @@ open $PATH_TO_XCODE_INSTALLATION --env METACODABLE_CI=1
3954
4055
### Automated Tests
4156

42-
GitHub action is already setup to run tests on pull requests targeting `main` branch. However, to reduce heavy usage of GitHub runners, run the following commands in your terminal to test:
57+
GitHub action is already setup to run tests on pull requests targeting `main` branch. For detailed testing instructions and methodology, see our [Testing Guide](Contributing/TESTING.md).
58+
59+
To run tests locally and reduce usage of GitHub runners:
4360

4461
| Test category | With [Node] | Manually |
4562
| --- | --- | --- |

Contributing/ARCHITECTURE.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# MetaCodable Architecture
2+
3+
This document provides a high-level overview of MetaCodable's architecture and implementation details.
4+
5+
## Overview
6+
7+
MetaCodable is a Swift macro-based framework that supercharges Swift's `Codable` implementations. It uses the power of Swift macros to generate sophisticated coding logic while keeping the API simple and declarative.
8+
9+
## Core Components
10+
11+
```mermaid
12+
graph TD
13+
A[MetaCodable Core] --> B[Macro System]
14+
A --> C[Helper Coders]
15+
A --> D[Protocol Generation]
16+
B --> E[Attribute Processing]
17+
B --> F[Code Generation]
18+
C --> G[Built-in Coders]
19+
C --> H[Custom Coders]
20+
D --> I[Build Tool Plugin]
21+
D --> J[Dynamic Codable]
22+
23+
style A fill:#f9f,stroke:#333,stroke-width:4px
24+
```
25+
26+
### 1. Macro System
27+
The core of MetaCodable is built around Swift's macro system, primarily using:
28+
- `@Codable` - The main attribute macro that drives the code generation
29+
- `@CodedAt`, `@CodedIn`, `@CodedBy` etc. - Attribute macros for customizing coding behavior
30+
- `PluginCore` - Core functionality for macro expansions and code generation
31+
32+
### 2. Helper Coders System
33+
Implements extensible coding strategies through:
34+
- `HelperCoder` protocol for custom coding implementations
35+
- Built-in coders like `ValueCoder`, `SequenceCoder`, etc.
36+
- Support for custom coders through `@CodedBy` attribute
37+
38+
### 3. Protocol Generation System
39+
Provides dynamic protocol conformance through:
40+
- `MetaProtocolCodable` build tool plugin
41+
- `DynamicCodable` type for generating protocol implementations
42+
- Source code parsing and synthesis capabilities
43+
44+
## Data Flow
45+
46+
```mermaid
47+
sequenceDiagram
48+
participant User
49+
participant Macros
50+
participant CodeGen
51+
participant Runtime
52+
53+
User->>Macros: Adds @Codable attribute
54+
Macros->>CodeGen: Process attributes
55+
CodeGen->>CodeGen: Generate implementation
56+
CodeGen->>Runtime: Emit Codable conformance
57+
Runtime->>User: Use generated code
58+
```
59+
60+
## Key Features
61+
62+
1. **Flexible Key Mapping**
63+
- Custom CodingKey values per property
64+
- Nested coding key support
65+
- Multiple coding key paths
66+
67+
2. **Smart Defaults and Error Handling**
68+
- Default value specification
69+
- Custom error handling
70+
- Missing value handling
71+
72+
3. **Protocol and Type Support**
73+
- Enum support with various tagging styles
74+
- Protocol type generation
75+
- Generic type support
76+
77+
## Implementation Details
78+
79+
### Attribute Processing
80+
The framework processes attributes in multiple phases:
81+
1. Attribute validation and preprocessing
82+
2. Context gathering and analysis
83+
3. Code generation and emission
84+
85+
### Code Generation
86+
The code generation system follows these principles:
87+
1. Maintains source compatibility
88+
2. Generates optimal, efficient code
89+
3. Supports full customization through attributes

0 commit comments

Comments
 (0)