fast-clean-architecture 1.0.0__tar.gz → 1.1.0__tar.gz
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.
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/.gitignore +3 -3
- fast_clean_architecture-1.1.0/.pre-commit-config.yaml +17 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/PKG-INFO +31 -21
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/README.md +26 -10
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0/docs}/CHANGELOG.md +8 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0/docs}/CONTRIBUTING.md +63 -1
- fast_clean_architecture-1.1.0/docs/DEPENDENCY_INJECTION_GUIDE.md +311 -0
- fast_clean_architecture-1.1.0/docs/ENHANCED_TYPE_SAFETY.md +353 -0
- {fast_clean_architecture-1.0.0/examples → fast_clean_architecture-1.1.0/docs}/getting-started.md +34 -6
- fast_clean_architecture-1.1.0/docs/template_validation_guide.md +408 -0
- fast_clean_architecture-1.0.0/examples/components-spec.yaml → fast_clean_architecture-1.1.0/examples/components_spec.yaml +1 -1
- fast_clean_architecture-1.1.0/examples/error_handling_examples.py +283 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/__init__.py +3 -4
- fast_clean_architecture-1.1.0/fast_clean_architecture/analytics.py +260 -0
- fast_clean_architecture-1.1.0/fast_clean_architecture/cli.py +992 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/config.py +47 -23
- fast_clean_architecture-1.1.0/fast_clean_architecture/error_tracking.py +201 -0
- fast_clean_architecture-1.1.0/fast_clean_architecture/exceptions.py +483 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/__init__.py +11 -1
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/component_generator.py +407 -103
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/config_updater.py +186 -38
- fast_clean_architecture-1.1.0/fast_clean_architecture/generators/generator_factory.py +223 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/package_generator.py +9 -7
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/template_validator.py +109 -9
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/validation_config.py +5 -3
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/generators/validation_metrics.py +10 -6
- fast_clean_architecture-1.1.0/fast_clean_architecture/health.py +169 -0
- fast_clean_architecture-1.1.0/fast_clean_architecture/logging_config.py +52 -0
- fast_clean_architecture-1.1.0/fast_clean_architecture/metrics.py +108 -0
- fast_clean_architecture-1.1.0/fast_clean_architecture/protocols.py +406 -0
- fast_clean_architecture-1.1.0/fast_clean_architecture/templates/external.py.j2 +138 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/utils.py +50 -31
- fast_clean_architecture-1.1.0/fast_clean_architecture/validation.py +302 -0
- fast_clean_architecture-1.1.0/fca_config.yaml +152 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/poetry.lock +211 -120
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/pyproject.toml +49 -16
- fast_clean_architecture-1.1.0/requirements-dev.txt +650 -0
- fast_clean_architecture-1.1.0/requirements.txt +275 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/conftest.py +3 -3
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_cli.py +3 -2
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_component_generator.py +7 -3
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_config.py +8 -7
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_cross_platform_compatibility.py +9 -7
- fast_clean_architecture-1.1.0/tests/test_enhanced_type_safety.py +400 -0
- fast_clean_architecture-1.1.0/tests/test_generator_factory.py +321 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_integration.py +13 -11
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_security.py +24 -13
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_symlink_security.py +3 -3
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_utils.py +12 -11
- fast_clean_architecture-1.1.0/update-requirements.sh +38 -0
- fast_clean_architecture-1.0.0/fast_clean_architecture/cli.py +0 -480
- fast_clean_architecture-1.0.0/fast_clean_architecture/exceptions.py +0 -63
- fast_clean_architecture-1.0.0/fast_clean_architecture/templates/external.py.j2 +0 -61
- fast_clean_architecture-1.0.0/test_security_enhancements.py +0 -149
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/LICENSE +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0/docs}/CODE_OF_CONDUCT.md +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0/docs}/TEMPLATE_VALIDATION_REFACTOR.md +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/__init__.py +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/__init__.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/api.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/command.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/entity.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/infrastructure_repository.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/model.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/query.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/repository.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/schemas.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/service.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/fast_clean_architecture/templates/value_object.py.j2 +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/__init__.py +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_template_security.py +0 -0
- {fast_clean_architecture-1.0.0 → fast_clean_architecture-1.1.0}/tests/test_template_validation.py +0 -0
@@ -224,7 +224,7 @@ $RECYCLE.BIN/
|
|
224
224
|
# Project-specific
|
225
225
|
# Configuration backups
|
226
226
|
*.backup.*
|
227
|
-
|
227
|
+
fca_config.yaml.backup.*
|
228
228
|
|
229
229
|
# Generated systems directory (if not tracking)
|
230
230
|
# systems/
|
@@ -410,7 +410,7 @@ override.toml
|
|
410
410
|
# systems/
|
411
411
|
|
412
412
|
# Configuration file backups (already covered above but being explicit)
|
413
|
-
|
413
|
+
fca_config.yaml.backup*
|
414
414
|
|
415
415
|
# Any local test configurations
|
416
416
|
test-config.yaml
|
@@ -946,12 +946,12 @@ fastlane/readme.md
|
|
946
946
|
# Temporary files created by R markdown
|
947
947
|
*.utf8.md
|
948
948
|
*.knit.md
|
949
|
+
*_prompt.md
|
949
950
|
|
950
951
|
# R Environment Variables
|
951
952
|
.Renviron
|
952
953
|
|
953
954
|
# pkgdown site
|
954
|
-
docs/
|
955
955
|
|
956
956
|
# translation temp files
|
957
957
|
po/*~
|
@@ -0,0 +1,17 @@
|
|
1
|
+
repos:
|
2
|
+
- repo: local
|
3
|
+
hooks:
|
4
|
+
- id: export-requirements
|
5
|
+
name: Export requirements.txt
|
6
|
+
entry: poetry export -f requirements.txt --output requirements.txt
|
7
|
+
language: system
|
8
|
+
files: pyproject.toml
|
9
|
+
pass_filenames: false
|
10
|
+
stages: [commit]
|
11
|
+
- id: export-dev-requirements
|
12
|
+
name: Export dev requirements.txt
|
13
|
+
entry: poetry export -f requirements.txt --output requirements-dev.txt --extras dev
|
14
|
+
language: system
|
15
|
+
files: pyproject.toml
|
16
|
+
pass_filenames: false
|
17
|
+
stages: [commit]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fast-clean-architecture
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.1.0
|
4
4
|
Summary: CLI tool for scaffolding clean architecture in FastAPI projects
|
5
5
|
Project-URL: Homepage, https://github.com/alden-technologies/fast-clean-architecture
|
6
6
|
Project-URL: Repository, https://github.com/alden-technologies/fast-clean-architecture
|
@@ -17,28 +17,22 @@ Classifier: Intended Audience :: Developers
|
|
17
17
|
Classifier: License :: OSI Approved :: MIT License
|
18
18
|
Classifier: Operating System :: OS Independent
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
20
|
-
Classifier: Programming Language :: Python :: 3.8
|
21
20
|
Classifier: Programming Language :: Python :: 3.9
|
22
21
|
Classifier: Programming Language :: Python :: 3.10
|
23
22
|
Classifier: Programming Language :: Python :: 3.11
|
24
23
|
Classifier: Programming Language :: Python :: 3.12
|
25
24
|
Classifier: Topic :: Software Development :: Code Generators
|
26
25
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
27
|
-
Requires-Python: >=3.
|
26
|
+
Requires-Python: >=3.9
|
28
27
|
Requires-Dist: jinja2<4.0.0,>=3.1.0
|
29
28
|
Requires-Dist: pathlib-mate<2.0.0,>=1.0.0
|
29
|
+
Requires-Dist: portalocker<3.0.0,>=2.0.0
|
30
|
+
Requires-Dist: psutil>=5.9.0
|
30
31
|
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
31
32
|
Requires-Dist: pyyaml<7.0.0,>=6.0
|
32
33
|
Requires-Dist: rich<14.0.0,>=13.0.0
|
34
|
+
Requires-Dist: structlog<24.0.0,>=23.0.0
|
33
35
|
Requires-Dist: typer[all]<1.0.0,>=0.9.0
|
34
|
-
Provides-Extra: dev
|
35
|
-
Requires-Dist: bandit<2.0.0,>=1.7.0; extra == 'dev'
|
36
|
-
Requires-Dist: black<24.0.0,>=23.0.0; extra == 'dev'
|
37
|
-
Requires-Dist: isort<6.0.0,>=5.0.0; extra == 'dev'
|
38
|
-
Requires-Dist: mypy<2.0.0,>=1.0.0; extra == 'dev'
|
39
|
-
Requires-Dist: pytest-cov<5.0.0,>=4.0.0; extra == 'dev'
|
40
|
-
Requires-Dist: pytest<8.0.0,>=7.0.0; extra == 'dev'
|
41
|
-
Requires-Dist: safety<3.0.0,>=2.0.0; extra == 'dev'
|
42
36
|
Description-Content-Type: text/markdown
|
43
37
|
|
44
38
|
# Fast Clean Architecture
|
@@ -76,36 +70,52 @@ poetry add fast-clean-architecture
|
|
76
70
|
|
77
71
|
### From Source
|
78
72
|
|
79
|
-
#### Using
|
73
|
+
#### Using Poetry (Recommended)
|
80
74
|
```bash
|
81
75
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
82
76
|
cd fast-clean-architecture
|
83
|
-
|
77
|
+
poetry install
|
84
78
|
```
|
85
79
|
|
86
|
-
#### Using
|
80
|
+
#### Using pip with requirements.txt
|
87
81
|
```bash
|
88
82
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
89
83
|
cd fast-clean-architecture
|
90
|
-
|
84
|
+
pip install -r requirements.txt
|
85
|
+
```
|
86
|
+
|
87
|
+
#### Using pip (editable install)
|
88
|
+
```bash
|
89
|
+
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
90
|
+
cd fast-clean-architecture
|
91
|
+
pip install -e .
|
91
92
|
```
|
92
93
|
|
93
94
|
### Development Installation
|
94
95
|
|
95
|
-
#### Using
|
96
|
+
#### Using Poetry (Recommended)
|
96
97
|
```bash
|
97
98
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
98
99
|
cd fast-clean-architecture
|
99
|
-
|
100
|
+
poetry install --extras dev
|
100
101
|
```
|
101
102
|
|
102
|
-
#### Using
|
103
|
+
#### Using pip with dev requirements
|
104
|
+
```bash
|
105
|
+
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
106
|
+
cd fast-clean-architecture
|
107
|
+
pip install -r requirements-dev.txt
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Using pip (editable install with dev dependencies)
|
103
111
|
```bash
|
104
112
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
105
113
|
cd fast-clean-architecture
|
106
|
-
|
114
|
+
pip install -e ".[dev]"
|
107
115
|
```
|
108
116
|
|
117
|
+
**Note**: This project uses Poetry for dependency management. The `requirements.txt` and `requirements-dev.txt` files are provided for convenience and compatibility with pip-based workflows.
|
118
|
+
|
109
119
|
## 🏗️ Architecture Overview
|
110
120
|
|
111
121
|
Fast Clean Architecture follows the clean architecture pattern with these layers:
|
@@ -130,7 +140,7 @@ Fast Clean Architecture follows the clean architecture pattern with these layers
|
|
130
140
|
│ └── 📁 presentation/ # API layer
|
131
141
|
│ ├── 📁 api/ # FastAPI routers
|
132
142
|
│ └── 📁 schemas/ # Pydantic schemas
|
133
|
-
└── 📄
|
143
|
+
└── 📄 fca_config.yaml # Project configuration
|
134
144
|
```
|
135
145
|
|
136
146
|
## 📋 Prerequisites
|
@@ -323,7 +333,7 @@ fca-scaffold create-component --help
|
|
323
333
|
|
324
334
|
### Configuration File
|
325
335
|
|
326
|
-
The `
|
336
|
+
The `fca_config.yaml` file tracks your project structure:
|
327
337
|
|
328
338
|
```yaml
|
329
339
|
project:
|
@@ -33,36 +33,52 @@ poetry add fast-clean-architecture
|
|
33
33
|
|
34
34
|
### From Source
|
35
35
|
|
36
|
-
#### Using
|
36
|
+
#### Using Poetry (Recommended)
|
37
37
|
```bash
|
38
38
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
39
39
|
cd fast-clean-architecture
|
40
|
-
|
40
|
+
poetry install
|
41
41
|
```
|
42
42
|
|
43
|
-
#### Using
|
43
|
+
#### Using pip with requirements.txt
|
44
44
|
```bash
|
45
45
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
46
46
|
cd fast-clean-architecture
|
47
|
-
|
47
|
+
pip install -r requirements.txt
|
48
|
+
```
|
49
|
+
|
50
|
+
#### Using pip (editable install)
|
51
|
+
```bash
|
52
|
+
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
53
|
+
cd fast-clean-architecture
|
54
|
+
pip install -e .
|
48
55
|
```
|
49
56
|
|
50
57
|
### Development Installation
|
51
58
|
|
52
|
-
#### Using
|
59
|
+
#### Using Poetry (Recommended)
|
53
60
|
```bash
|
54
61
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
55
62
|
cd fast-clean-architecture
|
56
|
-
|
63
|
+
poetry install --extras dev
|
57
64
|
```
|
58
65
|
|
59
|
-
#### Using
|
66
|
+
#### Using pip with dev requirements
|
67
|
+
```bash
|
68
|
+
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
69
|
+
cd fast-clean-architecture
|
70
|
+
pip install -r requirements-dev.txt
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Using pip (editable install with dev dependencies)
|
60
74
|
```bash
|
61
75
|
git clone https://github.com/alden-technologies/fast-clean-architecture.git
|
62
76
|
cd fast-clean-architecture
|
63
|
-
|
77
|
+
pip install -e ".[dev]"
|
64
78
|
```
|
65
79
|
|
80
|
+
**Note**: This project uses Poetry for dependency management. The `requirements.txt` and `requirements-dev.txt` files are provided for convenience and compatibility with pip-based workflows.
|
81
|
+
|
66
82
|
## 🏗️ Architecture Overview
|
67
83
|
|
68
84
|
Fast Clean Architecture follows the clean architecture pattern with these layers:
|
@@ -87,7 +103,7 @@ Fast Clean Architecture follows the clean architecture pattern with these layers
|
|
87
103
|
│ └── 📁 presentation/ # API layer
|
88
104
|
│ ├── 📁 api/ # FastAPI routers
|
89
105
|
│ └── 📁 schemas/ # Pydantic schemas
|
90
|
-
└── 📄
|
106
|
+
└── 📄 fca_config.yaml # Project configuration
|
91
107
|
```
|
92
108
|
|
93
109
|
## 📋 Prerequisites
|
@@ -280,7 +296,7 @@ fca-scaffold create-component --help
|
|
280
296
|
|
281
297
|
### Configuration File
|
282
298
|
|
283
|
-
The `
|
299
|
+
The `fca_config.yaml` file tracks your project structure:
|
284
300
|
|
285
301
|
```yaml
|
286
302
|
project:
|
@@ -35,6 +35,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
35
35
|
- Added dependency vulnerability scanning
|
36
36
|
- Implemented secure file operations
|
37
37
|
- Enhanced input validation and sanitization
|
38
|
+
- **CRITICAL**: Fixed 3 security vulnerabilities in dependencies:
|
39
|
+
- Updated black to ^24.3.0 to fix CVE-2024-21503 (ReDoS vulnerability)
|
40
|
+
- Added pip ^25.0 constraint to fix PVE-2025-75180 (malicious wheel execution)
|
41
|
+
- Added setuptools ^78.1.1 constraint to fix CVE-2025-47273 (path traversal)
|
42
|
+
- Resolved all Bandit security warnings with proper fixes and suppressions
|
43
|
+
- Replaced MD5 hashing with SHA256 for error ID generation
|
44
|
+
- Enabled Jinja2 autoescape to prevent XSS vulnerabilities
|
45
|
+
- Replaced assert statements with proper exception handling
|
38
46
|
|
39
47
|
## [0.1.0] - 2024-01-15
|
40
48
|
|
@@ -102,6 +102,68 @@ Pull requests are the best way to propose changes to the codebase. We actively w
|
|
102
102
|
poetry run mypy fast_clean_architecture
|
103
103
|
```
|
104
104
|
|
105
|
+
## Dependency Management
|
106
|
+
|
107
|
+
This project uses **Poetry** as the primary dependency manager, but also provides `requirements.txt` files for pip-based workflows.
|
108
|
+
|
109
|
+
### Understanding the Files
|
110
|
+
|
111
|
+
- **`pyproject.toml`**: Primary dependency definition (Poetry format)
|
112
|
+
- **`poetry.lock`**: Locked dependency versions (Poetry)
|
113
|
+
- **`requirements.txt`**: Production dependencies (pip format)
|
114
|
+
- **`requirements-dev.txt`**: Development dependencies (pip format)
|
115
|
+
|
116
|
+
### Updating Dependencies
|
117
|
+
|
118
|
+
#### Adding New Dependencies
|
119
|
+
|
120
|
+
**Using Poetry (Recommended)**
|
121
|
+
```bash
|
122
|
+
# Add production dependency
|
123
|
+
poetry add package-name
|
124
|
+
|
125
|
+
# Add development dependency
|
126
|
+
poetry add --group dev package-name
|
127
|
+
```
|
128
|
+
|
129
|
+
**Using pip**
|
130
|
+
```bash
|
131
|
+
# Add to pyproject.toml manually, then update requirements files
|
132
|
+
./update-requirements.sh
|
133
|
+
```
|
134
|
+
|
135
|
+
#### Updating Requirements Files
|
136
|
+
|
137
|
+
The `requirements.txt` files are automatically updated by pre-commit hooks when `pyproject.toml` changes. You can also update them manually:
|
138
|
+
|
139
|
+
```bash
|
140
|
+
# Using the provided script
|
141
|
+
./update-requirements.sh
|
142
|
+
|
143
|
+
# Or manually with Poetry
|
144
|
+
poetry export -f requirements.txt --output requirements.txt
|
145
|
+
poetry export -f requirements.txt --output requirements-dev.txt --extras dev
|
146
|
+
```
|
147
|
+
|
148
|
+
### Installation Options for Contributors
|
149
|
+
|
150
|
+
#### Option A: Using pip with requirements.txt
|
151
|
+
```bash
|
152
|
+
git clone https://github.com/YOUR_USERNAME/fast-clean-architecture.git
|
153
|
+
cd fast-clean-architecture
|
154
|
+
python -m venv venv
|
155
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
156
|
+
pip install -r requirements-dev.txt
|
157
|
+
```
|
158
|
+
|
159
|
+
#### Option B: Using Poetry (Recommended)
|
160
|
+
```bash
|
161
|
+
git clone https://github.com/YOUR_USERNAME/fast-clean-architecture.git
|
162
|
+
cd fast-clean-architecture
|
163
|
+
poetry install --extras dev
|
164
|
+
poetry shell
|
165
|
+
```
|
166
|
+
|
105
167
|
## Code Style
|
106
168
|
|
107
169
|
We use several tools to maintain code quality:
|
@@ -294,7 +356,7 @@ Use pytest fixtures for common test setup:
|
|
294
356
|
@pytest.fixture
|
295
357
|
def temp_project(tmp_path):
|
296
358
|
"""Create a temporary project structure for testing."""
|
297
|
-
config_path = tmp_path / "
|
359
|
+
config_path = tmp_path / "fca_config.yaml"
|
298
360
|
config_path.write_text("""
|
299
361
|
project:
|
300
362
|
name: test-project
|
@@ -0,0 +1,311 @@
|
|
1
|
+
# Dependency Injection and Factory Pattern Guide
|
2
|
+
|
3
|
+
This guide demonstrates the implementation of dependency injection and factory patterns in Fast Clean Architecture, providing better testability, loose coupling, and maintainable code.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
The Fast Clean Architecture now implements:
|
8
|
+
|
9
|
+
1. **Dependency Injection Pattern**: Components receive their dependencies through constructor injection rather than creating them internally
|
10
|
+
2. **Factory Pattern**: A centralized factory creates generators with proper dependency injection
|
11
|
+
3. **Protocol-Based Design**: All dependencies are defined through protocols for better type safety
|
12
|
+
|
13
|
+
## Architecture Improvements
|
14
|
+
|
15
|
+
### Before: Tight Coupling
|
16
|
+
|
17
|
+
```python
|
18
|
+
# Old approach - tight coupling
|
19
|
+
class ComponentGenerator:
|
20
|
+
def __init__(self, config: Config):
|
21
|
+
self.config = config
|
22
|
+
# Direct instantiation creates tight coupling
|
23
|
+
self.validator = TemplateValidator() # Hard dependency
|
24
|
+
self.path_handler = SecurePathHandler() # Hard dependency
|
25
|
+
```
|
26
|
+
|
27
|
+
### After: Dependency Injection
|
28
|
+
|
29
|
+
```python
|
30
|
+
# New approach - loose coupling through dependency injection
|
31
|
+
class ComponentGenerator:
|
32
|
+
def __init__(
|
33
|
+
self,
|
34
|
+
config: Config,
|
35
|
+
template_validator: Optional[TemplateValidatorProtocol] = None,
|
36
|
+
path_handler: Optional[SecurePathHandler] = None,
|
37
|
+
console: Optional[Console] = None
|
38
|
+
):
|
39
|
+
"""Initialize ComponentGenerator with dependency injection.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
config: Configuration object
|
43
|
+
template_validator: Template validator (injected dependency)
|
44
|
+
path_handler: Secure path handler (injected dependency)
|
45
|
+
console: Console for output
|
46
|
+
"""
|
47
|
+
self.config = config
|
48
|
+
self.console = console or Console()
|
49
|
+
|
50
|
+
# Use injected dependencies or create defaults for backward compatibility
|
51
|
+
self.template_validator = template_validator or self._create_default_validator()
|
52
|
+
self.path_handler = path_handler or self._create_default_path_handler()
|
53
|
+
```
|
54
|
+
|
55
|
+
## Factory Pattern Implementation
|
56
|
+
|
57
|
+
### Generator Factory
|
58
|
+
|
59
|
+
The `GeneratorFactory` provides a centralized way to create generators with proper dependency injection:
|
60
|
+
|
61
|
+
```python
|
62
|
+
from fast_clean_architecture.generators import create_generator_factory
|
63
|
+
from fast_clean_architecture.config import Config
|
64
|
+
|
65
|
+
# Create factory with dependencies
|
66
|
+
config = Config.load_from_file('fca_config.yaml')
|
67
|
+
factory = create_generator_factory(config)
|
68
|
+
|
69
|
+
# Create generators using the factory
|
70
|
+
component_generator = factory.create_generator('component')
|
71
|
+
package_generator = factory.create_generator('package')
|
72
|
+
config_updater = factory.create_generator('config', config_path=Path('custom_config.yaml'))
|
73
|
+
```
|
74
|
+
|
75
|
+
### Dependency Container
|
76
|
+
|
77
|
+
The `DependencyContainer` manages the lifecycle of shared dependencies:
|
78
|
+
|
79
|
+
```python
|
80
|
+
from fast_clean_architecture.generators.generator_factory import DependencyContainer, GeneratorFactory
|
81
|
+
|
82
|
+
# Create dependency container
|
83
|
+
dependencies = DependencyContainer(config, console)
|
84
|
+
|
85
|
+
# Create factory with dependency container
|
86
|
+
factory = GeneratorFactory(dependencies)
|
87
|
+
|
88
|
+
# All generators created by this factory will share the same dependencies
|
89
|
+
gen1 = factory.create_generator('component')
|
90
|
+
gen2 = factory.create_generator('component')
|
91
|
+
# Both generators share the same template validator and path handler instances
|
92
|
+
```
|
93
|
+
|
94
|
+
## Benefits
|
95
|
+
|
96
|
+
### 1. Improved Testability
|
97
|
+
|
98
|
+
```python
|
99
|
+
# Easy to mock dependencies for testing
|
100
|
+
from unittest.mock import Mock
|
101
|
+
|
102
|
+
mock_validator = Mock(spec=TemplateValidatorProtocol)
|
103
|
+
mock_path_handler = Mock(spec=SecurePathHandler)
|
104
|
+
|
105
|
+
# Inject mocks for testing
|
106
|
+
generator = ComponentGenerator(
|
107
|
+
config=test_config,
|
108
|
+
template_validator=mock_validator,
|
109
|
+
path_handler=mock_path_handler
|
110
|
+
)
|
111
|
+
|
112
|
+
# Test with controlled dependencies
|
113
|
+
generator.create_component(...)
|
114
|
+
mock_validator.validate.assert_called_once()
|
115
|
+
```
|
116
|
+
|
117
|
+
### 2. Flexible Configuration
|
118
|
+
|
119
|
+
```python
|
120
|
+
# Custom validator for specific use cases
|
121
|
+
class StrictTemplateValidator(TemplateValidatorProtocol):
|
122
|
+
def validate(self, template_source: str, template_vars: Dict[str, Any]) -> None:
|
123
|
+
# Custom strict validation logic
|
124
|
+
pass
|
125
|
+
|
126
|
+
# Use custom validator
|
127
|
+
custom_validator = StrictTemplateValidator()
|
128
|
+
generator = ComponentGenerator(
|
129
|
+
config=config,
|
130
|
+
template_validator=custom_validator
|
131
|
+
)
|
132
|
+
```
|
133
|
+
|
134
|
+
### 3. Resource Management
|
135
|
+
|
136
|
+
```python
|
137
|
+
# Shared dependencies reduce resource usage
|
138
|
+
factory = create_generator_factory(config)
|
139
|
+
|
140
|
+
# Multiple generators share the same validator and path handler
|
141
|
+
for i in range(10):
|
142
|
+
generator = factory.create_generator('component')
|
143
|
+
# All generators use the same validator instance
|
144
|
+
```
|
145
|
+
|
146
|
+
## Usage Examples
|
147
|
+
|
148
|
+
### Basic Usage (Backward Compatible)
|
149
|
+
|
150
|
+
```python
|
151
|
+
# Still works - uses default dependencies
|
152
|
+
from fast_clean_architecture.generators import ComponentGenerator
|
153
|
+
from fast_clean_architecture.config import Config
|
154
|
+
|
155
|
+
config = Config.load_from_file('fca_config.yaml')
|
156
|
+
generator = ComponentGenerator(config)
|
157
|
+
```
|
158
|
+
|
159
|
+
### Factory Pattern Usage
|
160
|
+
|
161
|
+
```python
|
162
|
+
# Recommended approach - uses factory
|
163
|
+
from fast_clean_architecture.generators import create_generator_factory
|
164
|
+
|
165
|
+
factory = create_generator_factory(config)
|
166
|
+
component_generator = factory.create_generator('component')
|
167
|
+
package_generator = factory.create_generator('package')
|
168
|
+
```
|
169
|
+
|
170
|
+
### Custom Dependencies
|
171
|
+
|
172
|
+
```python
|
173
|
+
# Advanced usage - custom dependencies
|
174
|
+
from fast_clean_architecture.generators.generator_factory import DependencyContainer, GeneratorFactory
|
175
|
+
from fast_clean_architecture.protocols import SecurePathHandler
|
176
|
+
|
177
|
+
# Create custom path handler with different settings
|
178
|
+
custom_path_handler = SecurePathHandler(
|
179
|
+
max_path_length=8192, # Longer paths allowed
|
180
|
+
allowed_extensions=['.py', '.j2', '.yaml', '.yml', '.json', '.txt']
|
181
|
+
)
|
182
|
+
|
183
|
+
# Create dependency container
|
184
|
+
dependencies = DependencyContainer(config, console)
|
185
|
+
|
186
|
+
# Override default path handler
|
187
|
+
dependencies._path_handler = custom_path_handler
|
188
|
+
|
189
|
+
# Create factory with custom dependencies
|
190
|
+
factory = GeneratorFactory(dependencies)
|
191
|
+
generator = factory.create_generator('component')
|
192
|
+
```
|
193
|
+
|
194
|
+
### CLI Integration
|
195
|
+
|
196
|
+
The CLI now uses the factory pattern internally:
|
197
|
+
|
198
|
+
```python
|
199
|
+
# In CLI code
|
200
|
+
config_updater = ConfigUpdater(config_path, console)
|
201
|
+
generator_factory = create_generator_factory(config_updater.config, console)
|
202
|
+
component_generator = generator_factory.create_generator('component')
|
203
|
+
```
|
204
|
+
|
205
|
+
## Protocol-Based Design
|
206
|
+
|
207
|
+
All dependencies are defined through protocols for better type safety:
|
208
|
+
|
209
|
+
```python
|
210
|
+
from fast_clean_architecture.protocols import (
|
211
|
+
ComponentGeneratorProtocol,
|
212
|
+
TemplateValidatorProtocol,
|
213
|
+
SecurePathHandler
|
214
|
+
)
|
215
|
+
|
216
|
+
# Type-safe dependency injection
|
217
|
+
def create_custom_generator(
|
218
|
+
config: Config,
|
219
|
+
validator: TemplateValidatorProtocol,
|
220
|
+
path_handler: SecurePathHandler
|
221
|
+
) -> ComponentGeneratorProtocol:
|
222
|
+
return ComponentGenerator(
|
223
|
+
config=config,
|
224
|
+
template_validator=validator,
|
225
|
+
path_handler=path_handler
|
226
|
+
)
|
227
|
+
```
|
228
|
+
|
229
|
+
## Migration Guide
|
230
|
+
|
231
|
+
### For Existing Code
|
232
|
+
|
233
|
+
1. **No changes required**: Existing code continues to work due to backward compatibility
|
234
|
+
2. **Gradual migration**: Replace direct instantiation with factory pattern over time
|
235
|
+
3. **Testing improvements**: Start using dependency injection in tests immediately
|
236
|
+
|
237
|
+
### Recommended Migration Steps
|
238
|
+
|
239
|
+
1. **Update imports**:
|
240
|
+
```python
|
241
|
+
# Old
|
242
|
+
from fast_clean_architecture.generators import ComponentGenerator
|
243
|
+
|
244
|
+
# New
|
245
|
+
from fast_clean_architecture.generators import create_generator_factory
|
246
|
+
```
|
247
|
+
|
248
|
+
2. **Replace instantiation**:
|
249
|
+
```python
|
250
|
+
# Old
|
251
|
+
generator = ComponentGenerator(config, console)
|
252
|
+
|
253
|
+
# New
|
254
|
+
factory = create_generator_factory(config, console)
|
255
|
+
generator = factory.create_generator('component')
|
256
|
+
```
|
257
|
+
|
258
|
+
3. **Update tests**:
|
259
|
+
```python
|
260
|
+
# Old
|
261
|
+
generator = ComponentGenerator(config)
|
262
|
+
|
263
|
+
# New - with mocked dependencies
|
264
|
+
generator = ComponentGenerator(
|
265
|
+
config=config,
|
266
|
+
template_validator=mock_validator,
|
267
|
+
path_handler=mock_path_handler
|
268
|
+
)
|
269
|
+
```
|
270
|
+
|
271
|
+
## Best Practices
|
272
|
+
|
273
|
+
1. **Use the factory pattern** for creating generators in application code
|
274
|
+
2. **Use dependency injection** for testing and custom configurations
|
275
|
+
3. **Leverage protocols** for type safety and interface contracts
|
276
|
+
4. **Share dependencies** through the dependency container for resource efficiency
|
277
|
+
5. **Mock dependencies** in tests for better isolation and control
|
278
|
+
|
279
|
+
## Error Handling
|
280
|
+
|
281
|
+
The factory pattern includes proper error handling:
|
282
|
+
|
283
|
+
```python
|
284
|
+
try:
|
285
|
+
generator = factory.create_generator('invalid_type')
|
286
|
+
except ValueError as e:
|
287
|
+
print(f"Error: {e}") # "Unsupported generator type: invalid_type"
|
288
|
+
|
289
|
+
# Check available types
|
290
|
+
available_types = factory.get_available_types()
|
291
|
+
print(f"Available generator types: {available_types}")
|
292
|
+
```
|
293
|
+
|
294
|
+
## Extending the Factory
|
295
|
+
|
296
|
+
You can register custom generator types:
|
297
|
+
|
298
|
+
```python
|
299
|
+
class CustomGenerator:
|
300
|
+
def __init__(self, config: Config, console: Console):
|
301
|
+
self.config = config
|
302
|
+
self.console = console
|
303
|
+
|
304
|
+
# Register custom generator
|
305
|
+
factory.register_generator('custom', CustomGenerator)
|
306
|
+
|
307
|
+
# Use custom generator
|
308
|
+
custom_gen = factory.create_generator('custom')
|
309
|
+
```
|
310
|
+
|
311
|
+
This architecture provides a solid foundation for maintainable, testable, and extensible code while maintaining backward compatibility with existing implementations.
|