PyArch-CLI 0.1.2__tar.gz → 0.2.1__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.
- pyarch_cli-0.2.1/.github/workflows/ci.yml +34 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/.gitignore +1 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/PKG-INFO +79 -18
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/README.md +77 -16
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/pyproject.toml +4 -2
- pyarch_cli-0.2.1/src/pyarch/__init__.py +1 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/app.py +7 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/common.py +2 -3
- pyarch_cli-0.2.1/src/pyarch/cli/db.py +47 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/config/manifest.py +1 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/common/filesystem.py +93 -55
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/module/layered.py +167 -168
- pyarch_cli-0.2.1/src/pyarch/generators/project/base.py +104 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/project/layered.py +5 -6
- pyarch_cli-0.2.1/src/pyarch/services/add_integration.py +65 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/services/create_module.py +22 -7
- pyarch_cli-0.2.1/src/pyarch/services/create_project.py +37 -0
- pyarch_cli-0.2.1/src/pyarch/services/database.py +110 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/alembic_env.py.j2 +2 -3
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/config.py.j2 +4 -5
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/dependencies.py.j2 +4 -5
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/routes.py.j2 +3 -4
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/service.py.j2 +19 -10
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/tokens.py.j2 +2 -2
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/user_model.py.j2 +2 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/utils.py.j2 +2 -2
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/env.example.j2 +2 -2
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/models_init.py.j2 +0 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_router.py.j2 +0 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_router_protected.py.j2 +0 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_service.py.j2 +0 -2
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_test_protected.py.j2 +0 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/router.py.j2 +0 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/session.py.j2 +1 -1
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/project/base/Dockerfile.j2 +1 -1
- pyarch_cli-0.2.1/src/pyarch/templates/project/base/README.md.j2 +39 -0
- pyarch_cli-0.2.1/src/pyarch/templates/project/base/ci.yml.j2 +26 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/project/base/conftest.py.j2 +8 -9
- pyarch_cli-0.2.1/src/pyarch/templates/project/base/docker-compose.postgres.yml.j2 +43 -0
- pyarch_cli-0.2.1/src/pyarch/templates/project/base/docker-compose.sqlite.yml.j2 +6 -0
- pyarch_cli-0.2.1/src/pyarch/templates/project/base/dockerignore.j2 +12 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/project/base/main.py.j2 +0 -1
- pyarch_cli-0.2.1/src/pyarch/templates/project/base/ruff.toml.j2 +8 -0
- pyarch_cli-0.2.1/tests/integration/test_generated_project.py +68 -0
- pyarch_cli-0.2.1/tests/integration/test_project_generation.py +97 -0
- pyarch_cli-0.2.1/tests/unit/test_database_cli.py +57 -0
- pyarch_cli-0.2.1/tests/unit/test_database_service.py +162 -0
- pyarch_cli-0.2.1/tests/unit/test_filesystem.py +30 -0
- pyarch_cli-0.2.1/tests/unit/test_manifest.py +29 -0
- pyarch_cli-0.2.1/tests/unit/test_module_generator.py +43 -0
- pyarch_cli-0.2.1/tests/unit/test_templates.py +79 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/uv.lock +50 -2
- pyarch_cli-0.1.2/src/pyarch/__init__.py +0 -1
- pyarch_cli-0.1.2/src/pyarch/generators/project/base.py +0 -66
- pyarch_cli-0.1.2/src/pyarch/services/add_integration.py +0 -35
- pyarch_cli-0.1.2/src/pyarch/services/create_project.py +0 -19
- pyarch_cli-0.1.2/src/pyarch/templates/project/base/README.md.j2 +0 -13
- pyarch_cli-0.1.2/src/pyarch/templates/project/base/docker-compose.yml.j2 +0 -55
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/.python-version +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/LICENSE +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/assets/Dockerfile.vhs +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/assets/pyarch-demo.gif +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/assets/pyarch-demo.tape +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/assets/vhs-uv +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/add.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/generate.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/info.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/cli/init.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/config/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/config/models.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/common/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/common/commands.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/common/gitignore.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/common/renderer.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/integration/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/integration/auth.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/module/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/generators/project/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/main.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/services/__init__.py +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/refresh_session_model.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/schemas.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/test_auth.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/auth/test_helpers.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/config.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/errors.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/exception_handlers.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_model.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_repo.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_schema.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/module/module_test.py.j2 +0 -0
- {pyarch_cli-0.1.2 → pyarch_cli-0.2.1}/src/pyarch/templates/layered/pagination.py.j2 +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: pyarch-ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
checks:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v5
|
|
12
|
+
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.13"
|
|
16
|
+
|
|
17
|
+
- name: Install dependencies
|
|
18
|
+
run: |
|
|
19
|
+
pip install uv
|
|
20
|
+
uv sync
|
|
21
|
+
|
|
22
|
+
- name: linter
|
|
23
|
+
run: |
|
|
24
|
+
uv run ruff check .
|
|
25
|
+
uv run ruff format --check .
|
|
26
|
+
|
|
27
|
+
- name: run tests
|
|
28
|
+
run: uv run pytest
|
|
29
|
+
|
|
30
|
+
- name: type check
|
|
31
|
+
run: uv run mypy src tests
|
|
32
|
+
|
|
33
|
+
- name: build package
|
|
34
|
+
run: uv build
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: PyArch-CLI
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
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
|
|
@@ -34,7 +34,7 @@ Description-Content-Type: text/markdown
|
|
|
34
34
|

|
|
35
35
|

|
|
36
36
|

|
|
37
|
-

|
|
38
38
|
|
|
39
39
|
PyArch is a CLI for creating and extending Layered FastAPI projects. It sets up
|
|
40
40
|
the application structure, database, tests and Alembic, then lets you add CRUD
|
|
@@ -56,12 +56,22 @@ ready to change.
|
|
|
56
56
|
- Layered FastAPI project structure
|
|
57
57
|
- PostgreSQL and SQLite support
|
|
58
58
|
- Complete CRUD modules with models, schemas, repositories, services and routes
|
|
59
|
+
- GitHub Actions workflow for generated-project linting and tests
|
|
59
60
|
- Automatic model and router registration
|
|
60
61
|
- JWT auth integration with generated RSA keys
|
|
61
62
|
- Protected CRUD routes
|
|
62
63
|
- Alembic setup for relational databases
|
|
63
64
|
- Tests and dependency setup through `uv`
|
|
64
65
|
- Project-aware generation through `pyarch.toml`
|
|
66
|
+
- Atomic project creation and rollback for failed extensions
|
|
67
|
+
|
|
68
|
+
## v0.2.1 Highlights
|
|
69
|
+
|
|
70
|
+
- Atomic project creation through a staging directory, with cleanup on failure
|
|
71
|
+
- Rollback for failed module and auth generation
|
|
72
|
+
- Docker Compose support for PostgreSQL projects
|
|
73
|
+
- Refresh-token rotation protected against concurrent reuse on PostgreSQL
|
|
74
|
+
- Self-tests for PyArch and an end-to-end generated-project workflow
|
|
65
75
|
|
|
66
76
|
## Quick Start
|
|
67
77
|
|
|
@@ -81,23 +91,54 @@ pyarch init my_project --database postgres
|
|
|
81
91
|
cd my_project
|
|
82
92
|
```
|
|
83
93
|
|
|
84
|
-
Copy `.env.example` to `.env` and set the database connection values.
|
|
94
|
+
Copy `.env.example` to `.env` and set the database connection values. For a
|
|
95
|
+
PostgreSQL project, initialize the database schema before starting the app:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pyarch db init
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Start the generated application:
|
|
85
102
|
|
|
86
103
|
```bash
|
|
87
104
|
docker compose up -d
|
|
88
105
|
```
|
|
89
106
|
|
|
107
|
+
After a model change in a PostgreSQL project, generate and apply a reviewed
|
|
108
|
+
revision and restart the application with:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pyarch db upgrade --message "describe schema change"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Without `--message`, PyArch prompts for one. When Alembic finds no metadata
|
|
115
|
+
changes, `db upgrade` restarts Compose but creates no empty revision. Compose
|
|
116
|
+
never runs migrations implicitly; migration files remain source code and should
|
|
117
|
+
be reviewed and committed.
|
|
118
|
+
|
|
119
|
+
## Safe Generation
|
|
120
|
+
|
|
121
|
+
`pyarch init` builds the project in a staging directory and publishes it only
|
|
122
|
+
after all generation steps complete. If setup fails, the staging directory is
|
|
123
|
+
removed. `generate module` and `add integration` track every affected file and
|
|
124
|
+
restore the previous state if a generation step fails, including the manifest
|
|
125
|
+
and dependency files.
|
|
126
|
+
|
|
90
127
|
Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
|
|
91
128
|
|
|
92
129
|
You can now extend the project:
|
|
93
130
|
|
|
94
131
|
```bash
|
|
95
|
-
pyarch generate module
|
|
132
|
+
pyarch generate module user
|
|
96
133
|
pyarch add integration auth
|
|
97
|
-
pyarch generate module
|
|
134
|
+
pyarch generate module task --protected
|
|
98
135
|
pyarch info
|
|
99
136
|
```
|
|
100
137
|
|
|
138
|
+
Module names must be singular identifiers. PyArch derives the plural table and
|
|
139
|
+
route names from them: use `user` to generate `/users` and the `users` table,
|
|
140
|
+
not `users`.
|
|
141
|
+
|
|
101
142
|
## What Gets Generated
|
|
102
143
|
|
|
103
144
|
A new project includes the application layers, database configuration, test
|
|
@@ -137,9 +178,9 @@ Each generated CRUD module adds:
|
|
|
137
178
|
| ------------------------------------------- | ------------------------------------------------ |
|
|
138
179
|
| `pyarch init <name>` | Create a Layered FastAPI project |
|
|
139
180
|
| `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
|
|
140
|
-
| `pyarch generate module <name>`
|
|
181
|
+
| `pyarch generate module <singular-name>` | Add a CRUD module to the current project |
|
|
141
182
|
| `pyarch add integration auth` | Add JWT authentication and user management |
|
|
142
|
-
| `pyarch generate module <name> --protected` | Generate CRUD routes
|
|
183
|
+
| `pyarch generate module <singular-name> --protected` | Generate protected CRUD routes |
|
|
143
184
|
| `pyarch info` | Show the current project configuration |
|
|
144
185
|
| `pyarch --help` | Show CLI help |
|
|
145
186
|
|
|
@@ -156,6 +197,9 @@ Current limitations:
|
|
|
156
197
|
|
|
157
198
|
- only Layered Architecture is supported;
|
|
158
199
|
- generated applications use synchronous database access;
|
|
200
|
+
- SQLite projects run locally and do not include Docker Compose; `pyarch db`
|
|
201
|
+
lifecycle commands are PostgreSQL-only. SQLite migrations can be run with
|
|
202
|
+
Alembic directly;
|
|
159
203
|
- generated projects are starter scaffolds and still require
|
|
160
204
|
application-specific configuration and code;
|
|
161
205
|
- the manifest format may change before a stable release.
|
|
@@ -177,7 +221,7 @@ Clone the repository and install the development environment:
|
|
|
177
221
|
```bash
|
|
178
222
|
git clone https://github.com/Allcode-1/PyArch.git
|
|
179
223
|
cd PyArch
|
|
180
|
-
uv sync
|
|
224
|
+
uv sync --group dev
|
|
181
225
|
```
|
|
182
226
|
|
|
183
227
|
Run the CLI from the checkout:
|
|
@@ -192,6 +236,15 @@ Or install the current checkout as an editable CLI tool:
|
|
|
192
236
|
uv tool install --editable .
|
|
193
237
|
```
|
|
194
238
|
|
|
239
|
+
Run the project checks before opening a pull request or releasing a version:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
uv run pytest
|
|
243
|
+
uv run ruff check src tests
|
|
244
|
+
uv run mypy src tests
|
|
245
|
+
uv build
|
|
246
|
+
```
|
|
247
|
+
|
|
195
248
|
## Architecture and Design
|
|
196
249
|
|
|
197
250
|
<details>
|
|
@@ -246,26 +299,34 @@ instead of producing incomplete files.
|
|
|
246
299
|
|
|
247
300
|
## Roadmap
|
|
248
301
|
|
|
249
|
-
### v0.2
|
|
302
|
+
### v0.2.1 (current)
|
|
303
|
+
|
|
304
|
+
- singular module-name contract and corrected SQLite workflow documentation;
|
|
305
|
+
- generated GitHub Actions workflow for linting and tests;
|
|
306
|
+
- package and generated-manifest versions kept in sync.
|
|
307
|
+
|
|
308
|
+
### v0.2.0
|
|
250
309
|
|
|
251
|
-
-
|
|
252
|
-
- rollback
|
|
253
|
-
-
|
|
310
|
+
- atomic project creation and cleanup on failure;
|
|
311
|
+
- rollback for failed module and auth generation;
|
|
312
|
+
- PostgreSQL Compose template and SQLite local setup;
|
|
313
|
+
- self-test suite and generated-project integration coverage.
|
|
254
314
|
|
|
255
315
|
### v0.3
|
|
256
316
|
|
|
257
|
-
- Redis integration;
|
|
258
|
-
-
|
|
317
|
+
- Redis integration foundation;
|
|
318
|
+
- opt-in cache-aside generation for CRUD modules;
|
|
259
319
|
- dry-run mode.
|
|
260
320
|
|
|
261
321
|
### Later
|
|
262
322
|
|
|
323
|
+
- scheduler integration;
|
|
263
324
|
- more architectures;
|
|
264
325
|
- plugin system;
|
|
265
326
|
- asynchronous database access.
|
|
266
327
|
|
|
267
328
|
## Status
|
|
268
329
|
|
|
269
|
-
PyArch is
|
|
270
|
-
templates, generated code and the manifest may still change before a
|
|
271
|
-
release.
|
|
330
|
+
PyArch v0.2.1 is an early alpha release. The main workflow is usable, but
|
|
331
|
+
commands, templates, generated code and the manifest may still change before a
|
|
332
|
+
stable release.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|

|
|
7
7
|

|
|
8
8
|

|
|
9
|
-

|
|
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
|
|
@@ -28,12 +28,22 @@ ready to change.
|
|
|
28
28
|
- Layered FastAPI project structure
|
|
29
29
|
- PostgreSQL and SQLite support
|
|
30
30
|
- Complete CRUD modules with models, schemas, repositories, services and routes
|
|
31
|
+
- GitHub Actions workflow for generated-project linting and tests
|
|
31
32
|
- Automatic model and router registration
|
|
32
33
|
- JWT auth integration with generated RSA keys
|
|
33
34
|
- Protected CRUD routes
|
|
34
35
|
- Alembic setup for relational databases
|
|
35
36
|
- Tests and dependency setup through `uv`
|
|
36
37
|
- Project-aware generation through `pyarch.toml`
|
|
38
|
+
- Atomic project creation and rollback for failed extensions
|
|
39
|
+
|
|
40
|
+
## v0.2.1 Highlights
|
|
41
|
+
|
|
42
|
+
- Atomic project creation through a staging directory, with cleanup on failure
|
|
43
|
+
- Rollback for failed module and auth generation
|
|
44
|
+
- Docker Compose support for PostgreSQL projects
|
|
45
|
+
- Refresh-token rotation protected against concurrent reuse on PostgreSQL
|
|
46
|
+
- Self-tests for PyArch and an end-to-end generated-project workflow
|
|
37
47
|
|
|
38
48
|
## Quick Start
|
|
39
49
|
|
|
@@ -53,23 +63,54 @@ pyarch init my_project --database postgres
|
|
|
53
63
|
cd my_project
|
|
54
64
|
```
|
|
55
65
|
|
|
56
|
-
Copy `.env.example` to `.env` and set the database connection values.
|
|
66
|
+
Copy `.env.example` to `.env` and set the database connection values. For a
|
|
67
|
+
PostgreSQL project, initialize the database schema before starting the app:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pyarch db init
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Start the generated application:
|
|
57
74
|
|
|
58
75
|
```bash
|
|
59
76
|
docker compose up -d
|
|
60
77
|
```
|
|
61
78
|
|
|
79
|
+
After a model change in a PostgreSQL project, generate and apply a reviewed
|
|
80
|
+
revision and restart the application with:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pyarch db upgrade --message "describe schema change"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Without `--message`, PyArch prompts for one. When Alembic finds no metadata
|
|
87
|
+
changes, `db upgrade` restarts Compose but creates no empty revision. Compose
|
|
88
|
+
never runs migrations implicitly; migration files remain source code and should
|
|
89
|
+
be reviewed and committed.
|
|
90
|
+
|
|
91
|
+
## Safe Generation
|
|
92
|
+
|
|
93
|
+
`pyarch init` builds the project in a staging directory and publishes it only
|
|
94
|
+
after all generation steps complete. If setup fails, the staging directory is
|
|
95
|
+
removed. `generate module` and `add integration` track every affected file and
|
|
96
|
+
restore the previous state if a generation step fails, including the manifest
|
|
97
|
+
and dependency files.
|
|
98
|
+
|
|
62
99
|
Open `http://127.0.0.1:8000/docs` to use the generated Swagger UI.
|
|
63
100
|
|
|
64
101
|
You can now extend the project:
|
|
65
102
|
|
|
66
103
|
```bash
|
|
67
|
-
pyarch generate module
|
|
104
|
+
pyarch generate module user
|
|
68
105
|
pyarch add integration auth
|
|
69
|
-
pyarch generate module
|
|
106
|
+
pyarch generate module task --protected
|
|
70
107
|
pyarch info
|
|
71
108
|
```
|
|
72
109
|
|
|
110
|
+
Module names must be singular identifiers. PyArch derives the plural table and
|
|
111
|
+
route names from them: use `user` to generate `/users` and the `users` table,
|
|
112
|
+
not `users`.
|
|
113
|
+
|
|
73
114
|
## What Gets Generated
|
|
74
115
|
|
|
75
116
|
A new project includes the application layers, database configuration, test
|
|
@@ -109,9 +150,9 @@ Each generated CRUD module adds:
|
|
|
109
150
|
| ------------------------------------------- | ------------------------------------------------ |
|
|
110
151
|
| `pyarch init <name>` | Create a Layered FastAPI project |
|
|
111
152
|
| `pyarch init <name> --database <engine>` | Select PostgreSQL or SQLite |
|
|
112
|
-
| `pyarch generate module <name>`
|
|
153
|
+
| `pyarch generate module <singular-name>` | Add a CRUD module to the current project |
|
|
113
154
|
| `pyarch add integration auth` | Add JWT authentication and user management |
|
|
114
|
-
| `pyarch generate module <name> --protected` | Generate CRUD routes
|
|
155
|
+
| `pyarch generate module <singular-name> --protected` | Generate protected CRUD routes |
|
|
115
156
|
| `pyarch info` | Show the current project configuration |
|
|
116
157
|
| `pyarch --help` | Show CLI help |
|
|
117
158
|
|
|
@@ -128,6 +169,9 @@ Current limitations:
|
|
|
128
169
|
|
|
129
170
|
- only Layered Architecture is supported;
|
|
130
171
|
- generated applications use synchronous database access;
|
|
172
|
+
- SQLite projects run locally and do not include Docker Compose; `pyarch db`
|
|
173
|
+
lifecycle commands are PostgreSQL-only. SQLite migrations can be run with
|
|
174
|
+
Alembic directly;
|
|
131
175
|
- generated projects are starter scaffolds and still require
|
|
132
176
|
application-specific configuration and code;
|
|
133
177
|
- the manifest format may change before a stable release.
|
|
@@ -149,7 +193,7 @@ Clone the repository and install the development environment:
|
|
|
149
193
|
```bash
|
|
150
194
|
git clone https://github.com/Allcode-1/PyArch.git
|
|
151
195
|
cd PyArch
|
|
152
|
-
uv sync
|
|
196
|
+
uv sync --group dev
|
|
153
197
|
```
|
|
154
198
|
|
|
155
199
|
Run the CLI from the checkout:
|
|
@@ -164,6 +208,15 @@ Or install the current checkout as an editable CLI tool:
|
|
|
164
208
|
uv tool install --editable .
|
|
165
209
|
```
|
|
166
210
|
|
|
211
|
+
Run the project checks before opening a pull request or releasing a version:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
uv run pytest
|
|
215
|
+
uv run ruff check src tests
|
|
216
|
+
uv run mypy src tests
|
|
217
|
+
uv build
|
|
218
|
+
```
|
|
219
|
+
|
|
167
220
|
## Architecture and Design
|
|
168
221
|
|
|
169
222
|
<details>
|
|
@@ -218,26 +271,34 @@ instead of producing incomplete files.
|
|
|
218
271
|
|
|
219
272
|
## Roadmap
|
|
220
273
|
|
|
221
|
-
### v0.2
|
|
274
|
+
### v0.2.1 (current)
|
|
275
|
+
|
|
276
|
+
- singular module-name contract and corrected SQLite workflow documentation;
|
|
277
|
+
- generated GitHub Actions workflow for linting and tests;
|
|
278
|
+
- package and generated-manifest versions kept in sync.
|
|
279
|
+
|
|
280
|
+
### v0.2.0
|
|
222
281
|
|
|
223
|
-
-
|
|
224
|
-
- rollback
|
|
225
|
-
-
|
|
282
|
+
- atomic project creation and cleanup on failure;
|
|
283
|
+
- rollback for failed module and auth generation;
|
|
284
|
+
- PostgreSQL Compose template and SQLite local setup;
|
|
285
|
+
- self-test suite and generated-project integration coverage.
|
|
226
286
|
|
|
227
287
|
### v0.3
|
|
228
288
|
|
|
229
|
-
- Redis integration;
|
|
230
|
-
-
|
|
289
|
+
- Redis integration foundation;
|
|
290
|
+
- opt-in cache-aside generation for CRUD modules;
|
|
231
291
|
- dry-run mode.
|
|
232
292
|
|
|
233
293
|
### Later
|
|
234
294
|
|
|
295
|
+
- scheduler integration;
|
|
235
296
|
- more architectures;
|
|
236
297
|
- plugin system;
|
|
237
298
|
- asynchronous database access.
|
|
238
299
|
|
|
239
300
|
## Status
|
|
240
301
|
|
|
241
|
-
PyArch is
|
|
242
|
-
templates, generated code and the manifest may still change before a
|
|
243
|
-
release.
|
|
302
|
+
PyArch v0.2.1 is an early alpha release. The main workflow is usable, but
|
|
303
|
+
commands, templates, generated code and the manifest may still change before a
|
|
304
|
+
stable release.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "PyArch-CLI"
|
|
3
|
-
version = "0.1
|
|
3
|
+
version = "0.2.1"
|
|
4
4
|
description = "Stateful CLI generator for Layered FastAPI projects"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
@@ -43,4 +43,6 @@ build-backend = "hatchling.build"
|
|
|
43
43
|
packages = ["src/pyarch"]
|
|
44
44
|
|
|
45
45
|
[dependency-groups]
|
|
46
|
-
dev = [
|
|
46
|
+
dev = [
|
|
47
|
+
"pytest>=9.1.1",
|
|
48
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.1"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import typer
|
|
2
2
|
|
|
3
3
|
from pyarch.cli.add import app as add_app
|
|
4
|
+
from pyarch.cli.db import app as db_app
|
|
4
5
|
from pyarch.cli.generate import app as generate_app
|
|
5
6
|
from pyarch.cli.info import show_info
|
|
6
7
|
from pyarch.cli.init import init_project
|
|
@@ -27,3 +28,9 @@ app.add_typer(
|
|
|
27
28
|
name="add",
|
|
28
29
|
help="Add project integrations.",
|
|
29
30
|
)
|
|
31
|
+
|
|
32
|
+
app.add_typer(
|
|
33
|
+
db_app,
|
|
34
|
+
name="db",
|
|
35
|
+
help="Create and apply database migrations.",
|
|
36
|
+
)
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import subprocess
|
|
2
2
|
from collections.abc import Callable
|
|
3
|
-
from typing import Never
|
|
3
|
+
from typing import Never
|
|
4
4
|
|
|
5
5
|
import typer
|
|
6
6
|
from rich.console import Console
|
|
7
7
|
|
|
8
8
|
console = Console()
|
|
9
|
-
ResultT = TypeVar("ResultT")
|
|
10
9
|
|
|
11
10
|
|
|
12
|
-
def execute_or_exit(action: Callable[[], ResultT]) -> ResultT:
|
|
11
|
+
def execute_or_exit[ResultT](action: Callable[[], ResultT]) -> ResultT:
|
|
13
12
|
try:
|
|
14
13
|
return action()
|
|
15
14
|
except (
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from pyarch.cli.common import console, execute_or_exit
|
|
6
|
+
from pyarch.services.database import initialize_database, upgrade_database
|
|
7
|
+
|
|
8
|
+
app = typer.Typer(no_args_is_help=True)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@app.command("init")
|
|
12
|
+
def initialize_database_command() -> None:
|
|
13
|
+
"""Create and apply the initial database revision without starting the app."""
|
|
14
|
+
|
|
15
|
+
project_root = execute_or_exit(initialize_database)
|
|
16
|
+
console.print(
|
|
17
|
+
f"[green]Database initialized[/green] in [bold]{project_root}[/bold]. "
|
|
18
|
+
"The application was not started."
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@app.command("upgrade")
|
|
23
|
+
def upgrade_database_command(
|
|
24
|
+
message: Annotated[
|
|
25
|
+
str | None,
|
|
26
|
+
typer.Option("--message", "-m", help="Message for the Alembic revision."),
|
|
27
|
+
] = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
"""Generate, apply, and restart the application with a schema revision."""
|
|
30
|
+
|
|
31
|
+
migration_message = message
|
|
32
|
+
if migration_message is None:
|
|
33
|
+
migration_message = typer.prompt("Migration message")
|
|
34
|
+
|
|
35
|
+
project_root, schema_changed = execute_or_exit(
|
|
36
|
+
lambda: upgrade_database(migration_message)
|
|
37
|
+
)
|
|
38
|
+
if not schema_changed:
|
|
39
|
+
console.print(
|
|
40
|
+
"[yellow]No schema changes detected; Compose was restarted without a migration.[/yellow]"
|
|
41
|
+
)
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
console.print(
|
|
45
|
+
f"[green]Database upgraded and Compose restarted[/green] in "
|
|
46
|
+
f"[bold]{project_root}[/bold]"
|
|
47
|
+
)
|
|
@@ -114,7 +114,7 @@ def load_manifest(project_dir: Path) -> ProjectManifest:
|
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
def save_manifest(project_dir: Path, manifest: ProjectManifest) -> Path:
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
manifest_path = project_dir / MANIFEST_NAME
|
|
119
119
|
temporary_path = manifest_path.with_suffix(".toml.tmp")
|
|
120
120
|
|
|
@@ -1,55 +1,93 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
from contextlib import contextmanager
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def create_empty_dir(directory: Path) -> Path:
|
|
7
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
8
|
+
return directory
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_empty_file(file: Path) -> Path:
|
|
12
|
+
file.parent.mkdir(parents=True, exist_ok=True)
|
|
13
|
+
file.touch(exist_ok=True)
|
|
14
|
+
return file
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def init_py_module(directory: Path) -> Path:
|
|
18
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
19
|
+
init = directory / "__init__.py"
|
|
20
|
+
init.touch(exist_ok=True)
|
|
21
|
+
return init
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create_module_path(directory: Path) -> Path:
|
|
25
|
+
create_empty_dir(directory)
|
|
26
|
+
init_py_module(directory)
|
|
27
|
+
return directory
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def insert_line_before_marker(
|
|
31
|
+
file_path: Path,
|
|
32
|
+
marker: str,
|
|
33
|
+
line: str,
|
|
34
|
+
) -> bool:
|
|
35
|
+
content = file_path.read_text(encoding="utf-8")
|
|
36
|
+
|
|
37
|
+
if line in content.splitlines():
|
|
38
|
+
return False
|
|
39
|
+
|
|
40
|
+
if marker not in content:
|
|
41
|
+
raise ValueError(f"Marker {marker!r} was not found in {file_path}")
|
|
42
|
+
|
|
43
|
+
updated_content = content.replace(marker, f"{line}\n{marker}", 1)
|
|
44
|
+
file_path.write_text(updated_content, encoding="utf-8")
|
|
45
|
+
return True
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def append_text_once(file_path: Path, marker: str, text: str) -> bool:
|
|
49
|
+
content = file_path.read_text(encoding="utf-8") if file_path.exists() else ""
|
|
50
|
+
|
|
51
|
+
if marker in content:
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
separator = "" if not content or content.endswith("\n") else "\n"
|
|
55
|
+
file_path.parent.mkdir(parents=True, exist_ok=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(
|
|
86
|
+
created_directories, key=lambda path: len(path.parts), reverse=True
|
|
87
|
+
):
|
|
88
|
+
try:
|
|
89
|
+
directory.rmdir()
|
|
90
|
+
except OSError:
|
|
91
|
+
pass
|
|
92
|
+
|
|
93
|
+
raise
|