PyArch-CLI 0.1.1__tar.gz → 0.2.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.
Files changed (87) hide show
  1. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/.gitignore +1 -1
  2. pyarch_cli-0.2.0/.release-dist/.gitignore +1 -0
  3. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/PKG-INFO +66 -33
  4. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/README.md +62 -31
  5. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/pyproject.toml +6 -2
  6. pyarch_cli-0.2.0/src/pyarch/__init__.py +1 -0
  7. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/add.py +3 -2
  8. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/app.py +4 -8
  9. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/common.py +2 -6
  10. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/generate.py +1 -3
  11. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/info.py +1 -4
  12. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/init.py +2 -6
  13. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/config/manifest.py +8 -4
  14. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/common/filesystem.py +40 -4
  15. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/common/gitignore.py +3 -2
  16. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/common/renderer.py +0 -1
  17. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/integration/auth.py +4 -5
  18. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/module/layered.py +48 -48
  19. pyarch_cli-0.2.0/src/pyarch/generators/project/base.py +85 -0
  20. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/project/layered.py +9 -5
  21. pyarch_cli-0.2.0/src/pyarch/services/add_integration.py +65 -0
  22. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/services/create_module.py +29 -16
  23. pyarch_cli-0.2.0/src/pyarch/services/create_project.py +37 -0
  24. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/service.py.j2 +14 -5
  25. pyarch_cli-0.2.0/src/pyarch/templates/layered/env.example.j2 +16 -0
  26. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/errors.py.j2 +1 -0
  27. pyarch_cli-0.2.0/src/pyarch/templates/project/base/Dockerfile.j2 +16 -0
  28. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/README.md.j2 +3 -10
  29. pyarch_cli-0.2.0/src/pyarch/templates/project/base/docker-compose.postgres.yml.j2 +53 -0
  30. pyarch_cli-0.2.0/src/pyarch/templates/project/base/docker-compose.sqlite.yml.j2 +14 -0
  31. pyarch_cli-0.2.0/tests/integration/test_generated_project.py +58 -0
  32. pyarch_cli-0.2.0/tests/integration/test_project_generation.py +95 -0
  33. pyarch_cli-0.2.0/tests/unit/test_filesystem.py +27 -0
  34. pyarch_cli-0.2.0/tests/unit/test_manifest.py +29 -0
  35. pyarch_cli-0.2.0/tests/unit/test_module_generator.py +43 -0
  36. pyarch_cli-0.2.0/tests/unit/test_templates.py +65 -0
  37. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/uv.lock +238 -2
  38. pyarch_cli-0.1.1/script_base.py +0 -355
  39. pyarch_cli-0.1.1/src/pyarch/__init__.py +0 -1
  40. pyarch_cli-0.1.1/src/pyarch/generators/project/base.py +0 -52
  41. pyarch_cli-0.1.1/src/pyarch/services/add_integration.py +0 -37
  42. pyarch_cli-0.1.1/src/pyarch/services/create_project.py +0 -20
  43. pyarch_cli-0.1.1/src/pyarch/templates/layered/env.example.j2 +0 -7
  44. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/.python-version +0 -0
  45. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/LICENSE +0 -0
  46. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/assets/Dockerfile.vhs +0 -0
  47. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/assets/pyarch-demo.gif +0 -0
  48. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/assets/pyarch-demo.tape +0 -0
  49. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/assets/vhs-uv +0 -0
  50. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/cli/__init__.py +0 -0
  51. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/config/__init__.py +0 -0
  52. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/config/models.py +0 -0
  53. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/__init__.py +0 -0
  54. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/common/__init__.py +0 -0
  55. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/common/commands.py +0 -0
  56. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/integration/__init__.py +0 -0
  57. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/module/__init__.py +0 -0
  58. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/generators/project/__init__.py +0 -0
  59. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/main.py +0 -0
  60. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/services/__init__.py +0 -0
  61. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/alembic_env.py.j2 +0 -0
  62. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/config.py.j2 +0 -0
  63. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/dependencies.py.j2 +0 -0
  64. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/refresh_session_model.py.j2 +0 -0
  65. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/routes.py.j2 +0 -0
  66. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/schemas.py.j2 +0 -0
  67. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/test_auth.py.j2 +0 -0
  68. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/test_helpers.py.j2 +0 -0
  69. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/tokens.py.j2 +0 -0
  70. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/user_model.py.j2 +0 -0
  71. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/auth/utils.py.j2 +0 -0
  72. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/config.py.j2 +0 -0
  73. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/exception_handlers.py.j2 +0 -0
  74. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/models_init.py.j2 +0 -0
  75. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_model.py.j2 +0 -0
  76. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_repo.py.j2 +0 -0
  77. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_router.py.j2 +0 -0
  78. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_router_protected.py.j2 +0 -0
  79. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_schema.py.j2 +0 -0
  80. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_service.py.j2 +0 -0
  81. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_test.py.j2 +0 -0
  82. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/module/module_test_protected.py.j2 +0 -0
  83. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/pagination.py.j2 +0 -0
  84. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/router.py.j2 +0 -0
  85. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/layered/session.py.j2 +0 -0
  86. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/conftest.py.j2 +0 -0
  87. {pyarch_cli-0.1.1 → pyarch_cli-0.2.0}/src/pyarch/templates/project/base/main.py.j2 +0 -0
@@ -5,7 +5,7 @@ build/
5
5
  dist/
6
6
  wheels/
7
7
  *.egg-info
8
+ *_cache
8
9
 
9
10
  # Virtual environments
10
11
  .venv
11
- after_script.txt
@@ -0,0 +1 @@
1
+ *
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: PyArch-CLI
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Stateful CLI generator for Layered FastAPI projects
5
5
  Project-URL: Homepage, https://github.com/Allcode-1/PyArch
6
6
  Project-URL: Repository, https://github.com/Allcode-1/PyArch
@@ -19,7 +19,9 @@ Classifier: Topic :: Software Development :: Code Generators
19
19
  Requires-Python: >=3.13
20
20
  Requires-Dist: cryptography>=46.0.3
21
21
  Requires-Dist: jinja2>=3.1.6
22
+ Requires-Dist: mypy>=2.3.0
22
23
  Requires-Dist: rich>=15.0.0
24
+ Requires-Dist: ruff>=0.16.1
23
25
  Requires-Dist: tomlkit>=0.15.0
24
26
  Requires-Dist: typer>=0.24.2
25
27
  Description-Content-Type: text/markdown
@@ -32,7 +34,7 @@ Description-Content-Type: text/markdown
32
34
  ![Typer](https://img.shields.io/badge/Typer-CLI-purple)
33
35
  ![Jinja2](https://img.shields.io/badge/Jinja2-templates-orange)
34
36
  ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
35
- ![Status](https://img.shields.io/badge/status-MVP%2B-orange)
37
+ ![Status](https://img.shields.io/badge/status-v0.2.0-blue)
36
38
 
37
39
  PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up
38
40
  the application structure, database, tests and Alembic, then lets you add CRUD
@@ -60,6 +62,15 @@ ready to change.
60
62
  - Alembic setup for relational databases
61
63
  - Tests and dependency setup through `uv`
62
64
  - Project-aware generation through `pyarch.toml`
65
+ - Atomic project creation and rollback for failed extensions
66
+
67
+ ## v0.2.0 Highlights
68
+
69
+ - Atomic project creation through a staging directory, with cleanup on failure
70
+ - Rollback for failed module and auth generation
71
+ - Database-specific Docker Compose files for PostgreSQL and SQLite
72
+ - Refresh-token rotation protected against concurrent reuse on PostgreSQL
73
+ - Self-tests for PyArch and an end-to-end generated-project workflow
63
74
 
64
75
  ## Quick Start
65
76
 
@@ -79,19 +90,30 @@ pyarch init my_project --database postgres
79
90
  cd my_project
80
91
  ```
81
92
 
82
- Copy `.env.example` to `.env` and set the database connection values. For
83
- PostgreSQL or SQLite, create the first migration:
93
+ Copy `.env.example` to `.env` and set the database connection values. The
94
+ generated Compose file matches the selected database: PostgreSQL projects get
95
+ database services; SQLite projects get only migration and API services.
96
+
97
+ Start the generated application:
84
98
 
85
99
  ```bash
86
- uv run alembic revision --autogenerate -m "initial"
87
- uv run alembic upgrade head
100
+ docker compose up -d
88
101
  ```
89
102
 
90
- Run the API:
103
+ After adding a generated module or integration that changes the database
104
+ schema, create a revision with
105
+ `uv run alembic revision --autogenerate -m "describe schema change"`. Then
106
+ apply it with `uv run alembic upgrade head`.
107
+ PyArch never autogenerates revisions during container startup: migration files
108
+ are source code and should be reviewed and committed.
91
109
 
92
- ```bash
93
- uv run uvicorn app.main:app --reload
94
- ```
110
+ ## Safe Generation
111
+
112
+ `pyarch init` builds the project in a staging directory and publishes it only
113
+ after all generation steps complete. If setup fails, the staging directory is
114
+ removed. `generate module` and `add integration` track every affected file and
115
+ restore the previous state if a generation step fails, including the manifest
116
+ and dependency files.
95
117
 
96
118
  Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
97
119
 
@@ -139,24 +161,24 @@ Each generated CRUD module adds:
139
161
 
140
162
  ## Commands
141
163
 
142
- | Command | Description |
143
- | --- | --- |
144
- | `pyarch init <name>` | Create a Layered FastAPI project |
145
- | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
146
- | `pyarch generate module <name>` | Add a CRUD module to the current project |
147
- | `pyarch add integration auth` | Add JWT authentication and user management |
164
+ | Command | Description |
165
+ | ------------------------------------------- | ------------------------------------------------ |
166
+ | `pyarch init <name>` | Create a Layered FastAPI project |
167
+ | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
168
+ | `pyarch generate module <name>` | Add a CRUD module to the current project |
169
+ | `pyarch add integration auth` | Add JWT authentication and user management |
148
170
  | `pyarch generate module <name> --protected` | Generate CRUD routes that require authentication |
149
- | `pyarch info` | Show the current project configuration |
150
- | `pyarch --help` | Show CLI help |
171
+ | `pyarch info` | Show the current project configuration |
172
+ | `pyarch --help` | Show CLI help |
151
173
 
152
174
  Generation commands must be run inside a project created by PyArch.
153
175
 
154
176
  ## Databases and Current Limitations
155
177
 
156
- | Database | CRUD modules | Alembic | Auth integration | Protected modules |
157
- | --- | --- | --- | --- | --- |
158
- | PostgreSQL | Yes | Yes | Yes | Yes |
159
- | SQLite | Yes | Yes | Yes | Yes |
178
+ | Database | CRUD modules | Alembic | Auth integration | Protected modules |
179
+ | ---------- | ------------ | ------- | ---------------- | ----------------- |
180
+ | PostgreSQL | Yes | Yes | Yes | Yes |
181
+ | SQLite | Yes | Yes | Yes | Yes |
160
182
 
161
183
  Current limitations:
162
184
 
@@ -183,7 +205,7 @@ Clone the repository and install the development environment:
183
205
  ```bash
184
206
  git clone https://github.com/Allcode-1/PyArch.git
185
207
  cd PyArch
186
- uv sync
208
+ uv sync --group dev
187
209
  ```
188
210
 
189
211
  Run the CLI from the checkout:
@@ -198,6 +220,15 @@ Or install the current checkout as an editable CLI tool:
198
220
  uv tool install --editable .
199
221
  ```
200
222
 
223
+ Run the project checks before opening a pull request or releasing a version:
224
+
225
+ ```bash
226
+ uv run pytest
227
+ uv run ruff check src tests
228
+ uv run mypy src tests
229
+ uv build
230
+ ```
231
+
201
232
  ## Architecture and Design
202
233
 
203
234
  <details>
@@ -252,26 +283,28 @@ instead of producing incomplete files.
252
283
 
253
284
  ## Roadmap
254
285
 
255
- ### v0.2
286
+ ### v0.2.0 (current)
256
287
 
257
- - safer generation and validation;
258
- - rollback on failed generation;
259
- - Redis integration foundation.
288
+ - atomic project creation and cleanup on failure;
289
+ - rollback for failed module and auth generation;
290
+ - PostgreSQL- and SQLite-specific Compose templates;
291
+ - self-test suite and generated-project integration coverage.
260
292
 
261
293
  ### v0.3
262
294
 
263
- - Redis integration;
264
- - scheduler integration;
295
+ - Redis integration foundation;
296
+ - opt-in cache-aside generation for CRUD modules;
265
297
  - dry-run mode.
266
298
 
267
299
  ### Later
268
300
 
301
+ - scheduler integration;
269
302
  - more architectures;
270
303
  - plugin system;
271
304
  - asynchronous database access.
272
305
 
273
306
  ## Status
274
307
 
275
- PyArch is in early development. The main workflow is usable, but commands,
276
- templates, generated code and the manifest may still change before a stable
277
- release.
308
+ PyArch v0.2.0 is an early alpha release. The main workflow is usable, but
309
+ commands, templates, generated code and the manifest may still change before a
310
+ stable release.
@@ -6,7 +6,7 @@
6
6
  ![Typer](https://img.shields.io/badge/Typer-CLI-purple)
7
7
  ![Jinja2](https://img.shields.io/badge/Jinja2-templates-orange)
8
8
  ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
9
- ![Status](https://img.shields.io/badge/status-MVP%2B-orange)
9
+ ![Status](https://img.shields.io/badge/status-v0.2.0-blue)
10
10
 
11
11
  PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up
12
12
  the application structure, database, tests and Alembic, then lets you add CRUD
@@ -34,6 +34,15 @@ ready to change.
34
34
  - Alembic setup for relational databases
35
35
  - Tests and dependency setup through `uv`
36
36
  - Project-aware generation through `pyarch.toml`
37
+ - Atomic project creation and rollback for failed extensions
38
+
39
+ ## v0.2.0 Highlights
40
+
41
+ - Atomic project creation through a staging directory, with cleanup on failure
42
+ - Rollback for failed module and auth generation
43
+ - Database-specific Docker Compose files for PostgreSQL and SQLite
44
+ - Refresh-token rotation protected against concurrent reuse on PostgreSQL
45
+ - Self-tests for PyArch and an end-to-end generated-project workflow
37
46
 
38
47
  ## Quick Start
39
48
 
@@ -53,19 +62,30 @@ pyarch init my_project --database postgres
53
62
  cd my_project
54
63
  ```
55
64
 
56
- Copy `.env.example` to `.env` and set the database connection values. For
57
- PostgreSQL or SQLite, create the first migration:
65
+ Copy `.env.example` to `.env` and set the database connection values. The
66
+ generated Compose file matches the selected database: PostgreSQL projects get
67
+ database services; SQLite projects get only migration and API services.
68
+
69
+ Start the generated application:
58
70
 
59
71
  ```bash
60
- uv run alembic revision --autogenerate -m "initial"
61
- uv run alembic upgrade head
72
+ docker compose up -d
62
73
  ```
63
74
 
64
- Run the API:
75
+ After adding a generated module or integration that changes the database
76
+ schema, create a revision with
77
+ `uv run alembic revision --autogenerate -m "describe schema change"`. Then
78
+ apply it with `uv run alembic upgrade head`.
79
+ PyArch never autogenerates revisions during container startup: migration files
80
+ are source code and should be reviewed and committed.
65
81
 
66
- ```bash
67
- uv run uvicorn app.main:app --reload
68
- ```
82
+ ## Safe Generation
83
+
84
+ `pyarch init` builds the project in a staging directory and publishes it only
85
+ after all generation steps complete. If setup fails, the staging directory is
86
+ removed. `generate module` and `add integration` track every affected file and
87
+ restore the previous state if a generation step fails, including the manifest
88
+ and dependency files.
69
89
 
70
90
  Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
71
91
 
@@ -113,24 +133,24 @@ Each generated CRUD module adds:
113
133
 
114
134
  ## Commands
115
135
 
116
- | Command | Description |
117
- | --- | --- |
118
- | `pyarch init <name>` | Create a Layered FastAPI project |
119
- | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
120
- | `pyarch generate module <name>` | Add a CRUD module to the current project |
121
- | `pyarch add integration auth` | Add JWT authentication and user management |
136
+ | Command | Description |
137
+ | ------------------------------------------- | ------------------------------------------------ |
138
+ | `pyarch init <name>` | Create a Layered FastAPI project |
139
+ | `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
140
+ | `pyarch generate module <name>` | Add a CRUD module to the current project |
141
+ | `pyarch add integration auth` | Add JWT authentication and user management |
122
142
  | `pyarch generate module <name> --protected` | Generate CRUD routes that require authentication |
123
- | `pyarch info` | Show the current project configuration |
124
- | `pyarch --help` | Show CLI help |
143
+ | `pyarch info` | Show the current project configuration |
144
+ | `pyarch --help` | Show CLI help |
125
145
 
126
146
  Generation commands must be run inside a project created by PyArch.
127
147
 
128
148
  ## Databases and Current Limitations
129
149
 
130
- | Database | CRUD modules | Alembic | Auth integration | Protected modules |
131
- | --- | --- | --- | --- | --- |
132
- | PostgreSQL | Yes | Yes | Yes | Yes |
133
- | SQLite | Yes | Yes | Yes | Yes |
150
+ | Database | CRUD modules | Alembic | Auth integration | Protected modules |
151
+ | ---------- | ------------ | ------- | ---------------- | ----------------- |
152
+ | PostgreSQL | Yes | Yes | Yes | Yes |
153
+ | SQLite | Yes | Yes | Yes | Yes |
134
154
 
135
155
  Current limitations:
136
156
 
@@ -157,7 +177,7 @@ Clone the repository and install the development environment:
157
177
  ```bash
158
178
  git clone https://github.com/Allcode-1/PyArch.git
159
179
  cd PyArch
160
- uv sync
180
+ uv sync --group dev
161
181
  ```
162
182
 
163
183
  Run the CLI from the checkout:
@@ -172,6 +192,15 @@ Or install the current checkout as an editable CLI tool:
172
192
  uv tool install --editable .
173
193
  ```
174
194
 
195
+ Run the project checks before opening a pull request or releasing a version:
196
+
197
+ ```bash
198
+ uv run pytest
199
+ uv run ruff check src tests
200
+ uv run mypy src tests
201
+ uv build
202
+ ```
203
+
175
204
  ## Architecture and Design
176
205
 
177
206
  <details>
@@ -226,26 +255,28 @@ instead of producing incomplete files.
226
255
 
227
256
  ## Roadmap
228
257
 
229
- ### v0.2
258
+ ### v0.2.0 (current)
230
259
 
231
- - safer generation and validation;
232
- - rollback on failed generation;
233
- - Redis integration foundation.
260
+ - atomic project creation and cleanup on failure;
261
+ - rollback for failed module and auth generation;
262
+ - PostgreSQL- and SQLite-specific Compose templates;
263
+ - self-test suite and generated-project integration coverage.
234
264
 
235
265
  ### v0.3
236
266
 
237
- - Redis integration;
238
- - scheduler integration;
267
+ - Redis integration foundation;
268
+ - opt-in cache-aside generation for CRUD modules;
239
269
  - dry-run mode.
240
270
 
241
271
  ### Later
242
272
 
273
+ - scheduler integration;
243
274
  - more architectures;
244
275
  - plugin system;
245
276
  - asynchronous database access.
246
277
 
247
278
  ## Status
248
279
 
249
- PyArch is in early development. The main workflow is usable, but commands,
250
- templates, generated code and the manifest may still change before a stable
251
- release.
280
+ PyArch v0.2.0 is an early alpha release. The main workflow is usable, but
281
+ commands, templates, generated code and the manifest may still change before a
282
+ stable release.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "PyArch-CLI"
3
- version = "0.1.1"
3
+ version = "0.2.0"
4
4
  description = "Stateful CLI generator for Layered FastAPI projects"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -20,7 +20,9 @@ classifiers = [
20
20
  dependencies = [
21
21
  "cryptography>=46.0.3",
22
22
  "jinja2>=3.1.6",
23
+ "mypy>=2.3.0",
23
24
  "rich>=15.0.0",
25
+ "ruff>=0.16.1",
24
26
  "tomlkit>=0.15.0",
25
27
  "typer>=0.24.2",
26
28
  ]
@@ -41,4 +43,6 @@ build-backend = "hatchling.build"
41
43
  packages = ["src/pyarch"]
42
44
 
43
45
  [dependency-groups]
44
- dev = []
46
+ dev = [
47
+ "pytest>=9.1.1",
48
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.1.2"
@@ -5,7 +5,6 @@ import typer
5
5
  from pyarch.cli.common import console, execute_or_exit
6
6
  from pyarch.services.add_integration import add_integration
7
7
 
8
-
9
8
  app = typer.Typer(no_args_is_help=True)
10
9
 
11
10
 
@@ -18,7 +17,9 @@ def add_integration_command(
18
17
  ) -> None:
19
18
  """Add a supported integration to the current project."""
20
19
 
21
- project_root, created_files = execute_or_exit(lambda: add_integration(integration_name))
20
+ project_root, created_files = execute_or_exit(
21
+ lambda: add_integration(integration_name)
22
+ )
22
23
  console.print(
23
24
  f"[green]Added integration[/green] [bold]{integration_name}[/bold]"
24
25
  f" in {project_root}"
@@ -1,12 +1,10 @@
1
-
2
1
  import typer
3
2
 
4
- from pyarch.cli.info import show_info
5
3
  from pyarch.cli.add import app as add_app
6
4
  from pyarch.cli.generate import app as generate_app
5
+ from pyarch.cli.info import show_info
7
6
  from pyarch.cli.init import init_project
8
7
 
9
-
10
8
  app = typer.Typer(
11
9
  name="pyarch",
12
10
  help="Generate and extend Layered FastAPI projects.",
@@ -14,7 +12,9 @@ app = typer.Typer(
14
12
  )
15
13
 
16
14
  app.command("init", help="Create a new Layered FastAPI project.")(init_project)
17
- app.command("info", help="Show information from the current project's manifest.")(show_info)
15
+ app.command("info", help="Show information from the current project's manifest.")(
16
+ show_info
17
+ )
18
18
 
19
19
  app.add_typer(
20
20
  generate_app,
@@ -27,7 +27,3 @@ app.add_typer(
27
27
  name="add",
28
28
  help="Add project integrations.",
29
29
  )
30
-
31
-
32
-
33
-
@@ -1,16 +1,12 @@
1
1
  import subprocess
2
2
  from collections.abc import Callable
3
- from typing import Never, TypeVar
3
+ from typing import Never
4
4
 
5
5
  import typer
6
6
  from rich.console import Console
7
7
 
8
-
9
8
  console = Console()
10
- ResultT = TypeVar("ResultT")
11
-
12
-
13
- def execute_or_exit(action: Callable[[], ResultT]) -> ResultT:
9
+ def execute_or_exit[ResultT](action: Callable[[], ResultT]) -> ResultT:
14
10
  try:
15
11
  return action()
16
12
  except (
@@ -5,7 +5,6 @@ import typer
5
5
  from pyarch.cli.common import console, execute_or_exit
6
6
  from pyarch.services.create_module import create_module
7
7
 
8
-
9
8
  app = typer.Typer(no_args_is_help=True)
10
9
 
11
10
 
@@ -27,8 +26,7 @@ def generate_module(
27
26
  )
28
27
 
29
28
  console.print(
30
- f"[green]Created module[/green] [bold]{module_name}[/bold] "
31
- f"in {project_root}"
29
+ f"[green]Created module[/green] [bold]{module_name}[/bold] in {project_root}"
32
30
  )
33
31
  for file_path in created_files:
34
32
  console.print(f" [dim]{file_path.relative_to(project_root)}[/dim]")
@@ -1,10 +1,9 @@
1
1
  import typer
2
-
3
2
  from rich.table import Table
3
+
4
4
  from pyarch.cli.common import console, execute_or_exit
5
5
  from pyarch.config.manifest import load_current_manifest
6
6
 
7
-
8
7
  app = typer.Typer(no_args_is_help=True)
9
8
 
10
9
 
@@ -28,5 +27,3 @@ def show_info() -> None:
28
27
  ", ".join(manifest.state.integrations) or "none",
29
28
  )
30
29
  console.print(table)
31
-
32
-
@@ -6,7 +6,6 @@ from pyarch.cli.common import console, execute_or_exit
6
6
  from pyarch.config.models import DatabaseEngine
7
7
  from pyarch.services.create_project import create_project
8
8
 
9
-
10
9
  app = typer.Typer(no_args_is_help=True)
11
10
 
12
11
 
@@ -29,10 +28,7 @@ def init_project(
29
28
  """Create a new Layered FastAPI project."""
30
29
 
31
30
  console.print(
32
- f"Creating [bold]{project_name}[/bold] "
33
- f"with [cyan]{database.value}[/cyan]..."
34
- )
35
- project_dir = execute_or_exit(
36
- lambda: create_project(project_name, database)
31
+ f"Creating [bold]{project_name}[/bold] with [cyan]{database.value}[/cyan]..."
37
32
  )
33
+ project_dir = execute_or_exit(lambda: create_project(project_name, database))
38
34
  console.print(f"[bold green]Project created:[/bold green] {project_dir}")
@@ -15,7 +15,6 @@ from pyarch.config.models import (
15
15
  ProjectState,
16
16
  )
17
17
 
18
-
19
18
  MANIFEST_NAME = "pyarch.toml"
20
19
  SCHEMA_VERSION = 1
21
20
 
@@ -23,10 +22,12 @@ SCHEMA_VERSION = 1
23
22
  class ManifestError(ValueError):
24
23
  pass
25
24
 
25
+
26
26
  def load_current_manifest():
27
27
  project_root = find_project_root()
28
28
  return project_root, load_manifest(project_root)
29
29
 
30
+
30
31
  def create_manifest(
31
32
  project_dir: Path,
32
33
  project_name: str,
@@ -44,7 +45,9 @@ def create_manifest(
44
45
 
45
46
 
46
47
  def find_project_root(start: Path | None = None) -> Path:
48
+
47
49
  current = (start or Path.cwd()).resolve()
50
+
48
51
  if current.is_file():
49
52
  current = current.parent
50
53
 
@@ -58,7 +61,9 @@ def find_project_root(start: Path | None = None) -> Path:
58
61
 
59
62
 
60
63
  def load_manifest(project_dir: Path) -> ProjectManifest:
64
+
61
65
  manifest_path = project_dir / MANIFEST_NAME
66
+
62
67
  if not manifest_path.is_file():
63
68
  raise FileNotFoundError(f"Manifest does not exist: {manifest_path}")
64
69
 
@@ -109,6 +114,7 @@ def load_manifest(project_dir: Path) -> ProjectManifest:
109
114
 
110
115
 
111
116
  def save_manifest(project_dir: Path, manifest: ProjectManifest) -> Path:
117
+
112
118
  manifest_path = project_dir / MANIFEST_NAME
113
119
  temporary_path = manifest_path.with_suffix(".toml.tmp")
114
120
 
@@ -153,8 +159,6 @@ def require_table(raw: dict[str, Any], key: str) -> dict[str, Any]:
153
159
 
154
160
  def require_string_list(data: dict[str, Any], key: str) -> list[str]:
155
161
  value = data[key]
156
- if not isinstance(value, list) or not all(
157
- isinstance(item, str) for item in value
158
- ):
162
+ if not isinstance(value, list) or not all(isinstance(item, str) for item in value):
159
163
  raise ManifestError(f"{key!r} must be an array of strings")
160
164
  return list(value)
@@ -1,4 +1,6 @@
1
- from pathlib import Path
1
+ from collections.abc import Iterator
2
+ from contextlib import contextmanager
3
+ from pathlib import Path
2
4
 
3
5
 
4
6
  def create_empty_dir(directory: Path) -> Path:
@@ -43,7 +45,7 @@ def insert_line_before_marker(
43
45
  return True
44
46
 
45
47
 
46
- def append_text_once(file_path: Path, marker: str, text: str) -> bool:
48
+ def append_text_once(file_path: Path, marker: str, text: str) -> bool:
47
49
  content = file_path.read_text(encoding="utf-8") if file_path.exists() else ""
48
50
 
49
51
  if marker in content:
@@ -51,5 +53,39 @@ def append_text_once(file_path: Path, marker: str, text: str) -> bool:
51
53
 
52
54
  separator = "" if not content or content.endswith("\n") else "\n"
53
55
  file_path.parent.mkdir(parents=True, exist_ok=True)
54
- file_path.write_text(f"{content}{separator}{text}", encoding="utf-8")
55
- return True
56
+ file_path.write_text(f"{content}{separator}{text}", encoding="utf-8")
57
+ return True
58
+
59
+
60
+ @contextmanager
61
+ def rollback_file_changes(
62
+ files: tuple[Path, ...],
63
+ directories: tuple[Path, ...] = (),
64
+ ) -> Iterator[None]:
65
+ """Restore tracked files if a generation step fails."""
66
+
67
+ snapshots = {
68
+ file_path: file_path.read_bytes() if file_path.is_file() else None
69
+ for file_path in files
70
+ }
71
+ created_directories = tuple(
72
+ directory for directory in directories if not directory.exists()
73
+ )
74
+
75
+ try:
76
+ yield
77
+ except BaseException:
78
+ for file_path, content in snapshots.items():
79
+ if content is None:
80
+ file_path.unlink(missing_ok=True)
81
+ else:
82
+ file_path.parent.mkdir(parents=True, exist_ok=True)
83
+ file_path.write_bytes(content)
84
+
85
+ for directory in sorted(created_directories, key=lambda path: len(path.parts), reverse=True):
86
+ try:
87
+ directory.rmdir()
88
+ except OSError:
89
+ pass
90
+
91
+ raise
@@ -1,6 +1,5 @@
1
1
  from pathlib import Path
2
2
 
3
-
4
3
  BASE_GITIGNORE_ENTRIES = (
5
4
  ".env",
6
5
  ".env.*",
@@ -32,7 +31,9 @@ def ensure_gitignore_entries(
32
31
  entries: tuple[str, ...],
33
32
  ) -> Path:
34
33
  gitignore_path = project_dir / ".gitignore"
35
- content = gitignore_path.read_text(encoding="utf-8") if gitignore_path.exists() else ""
34
+ content = (
35
+ gitignore_path.read_text(encoding="utf-8") if gitignore_path.exists() else ""
36
+ )
36
37
  lines = content.splitlines()
37
38
  existing_entries = {line.strip() for line in lines}
38
39
 
@@ -2,7 +2,6 @@ from pathlib import Path
2
2
 
3
3
  from jinja2 import Environment, FileSystemLoader, StrictUndefined
4
4
 
5
-
6
5
  TEMPLATES_DIR = Path(__file__).resolve().parents[2] / "templates"
7
6
 
8
7
  environment = Environment(