PyArch-CLI 0.4.0__tar.gz → 0.4.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.
Files changed (115) hide show
  1. pyarch_cli-0.4.1/PKG-INFO +121 -0
  2. pyarch_cli-0.4.1/README.md +95 -0
  3. pyarch_cli-0.4.1/docs/configuration.md +30 -0
  4. pyarch_cli-0.4.1/docs/development.md +24 -0
  5. pyarch_cli-0.4.1/docs/generated-project.md +91 -0
  6. pyarch_cli-0.4.1/docs/how-it-works.md +50 -0
  7. pyarch_cli-0.4.1/docs/integrations.md +71 -0
  8. pyarch_cli-0.4.1/docs/migrations.md +51 -0
  9. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/pyproject.toml +3 -3
  10. pyarch_cli-0.4.1/src/pyarch/__init__.py +1 -0
  11. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/common.py +4 -4
  12. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/compose_edit.py +330 -252
  13. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/filesystem.py +17 -6
  14. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/integration/auth.py +11 -1
  15. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/integration/redis.py +244 -237
  16. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/project/base.py +3 -1
  17. pyarch_cli-0.4.1/src/pyarch/main.py +32 -0
  18. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/services/create_module.py +31 -1
  19. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/services/create_project.py +20 -1
  20. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/infra/redis/cache.py.j2 +113 -87
  21. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/infra/redis/config.py.j2 +9 -8
  22. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_schema.py.j2 +8 -1
  23. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_test.py.j2 +8 -0
  24. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_test_protected.py.j2 +14 -0
  25. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/README.md.j2 +1 -1
  26. pyarch_cli-0.4.1/src/pyarch/templates/project/base/ci.yml.j2 +59 -0
  27. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/conftest.py.j2 +5 -3
  28. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/integration/test_project_generation.py +29 -0
  29. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_compose_edit.py +401 -340
  30. pyarch_cli-0.4.1/tests/unit/test_filesystem.py +58 -0
  31. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_module_generator.py +27 -0
  32. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_templates.py +21 -1
  33. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/uv.lock +1 -1
  34. pyarch_cli-0.4.0/PKG-INFO +0 -417
  35. pyarch_cli-0.4.0/README.md +0 -391
  36. pyarch_cli-0.4.0/src/pyarch/__init__.py +0 -1
  37. pyarch_cli-0.4.0/src/pyarch/main.py +0 -9
  38. pyarch_cli-0.4.0/src/pyarch/templates/project/base/ci.yml.j2 +0 -26
  39. pyarch_cli-0.4.0/tests/unit/test_filesystem.py +0 -30
  40. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/.github/workflows/ci.yml +0 -0
  41. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/.gitignore +0 -0
  42. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/.python-version +0 -0
  43. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/LICENSE +0 -0
  44. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/assets/Dockerfile.vhs +0 -0
  45. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/assets/pyarch-demo.gif +0 -0
  46. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/assets/pyarch-demo.tape +0 -0
  47. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/assets/vhs-uv +0 -0
  48. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/__init__.py +0 -0
  49. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/add.py +0 -0
  50. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/app.py +0 -0
  51. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/db.py +0 -0
  52. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/generate.py +0 -0
  53. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/info.py +0 -0
  54. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/cli/init.py +0 -0
  55. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/config/__init__.py +0 -0
  56. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/config/manifest.py +0 -0
  57. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/config/models.py +0 -0
  58. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/__init__.py +0 -0
  59. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/__init__.py +0 -0
  60. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/commands.py +0 -0
  61. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/gitignore.py +0 -0
  62. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/renderer.py +0 -0
  63. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/common/source_edit.py +0 -0
  64. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/integration/__init__.py +0 -0
  65. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/integration/registry.py +0 -0
  66. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/integration/spec.py +0 -0
  67. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/module/__init__.py +0 -0
  68. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/module/layered.py +0 -0
  69. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/project/__init__.py +0 -0
  70. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/generators/project/layered.py +0 -0
  71. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/services/__init__.py +0 -0
  72. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/services/add_integration.py +0 -0
  73. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/services/database.py +0 -0
  74. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/services/dry_run.py +0 -0
  75. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/alembic_env.py.j2 +0 -0
  76. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/config.py.j2 +0 -0
  77. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/dependencies.py.j2 +0 -0
  78. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/refresh_session_model.py.j2 +0 -0
  79. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/routes.py.j2 +0 -0
  80. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/schemas.py.j2 +0 -0
  81. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/service.py.j2 +0 -0
  82. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/test_auth.py.j2 +0 -0
  83. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/test_helpers.py.j2 +0 -0
  84. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/tokens.py.j2 +0 -0
  85. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/user_model.py.j2 +0 -0
  86. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/auth/utils.py.j2 +0 -0
  87. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/config.py.j2 +0 -0
  88. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/env.example.j2 +0 -0
  89. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/errors.py.j2 +0 -0
  90. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/exception_handlers.py.j2 +0 -0
  91. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/models_init.py.j2 +0 -0
  92. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_model.py.j2 +0 -0
  93. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_repo.py.j2 +0 -0
  94. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_router.py.j2 +0 -0
  95. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_router_protected.py.j2 +0 -0
  96. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/module/module_service.py.j2 +0 -0
  97. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/pagination.py.j2 +0 -0
  98. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/router.py.j2 +0 -0
  99. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/layered/session.py.j2 +0 -0
  100. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/Dockerfile.j2 +0 -0
  101. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/docker-compose.postgres.yml.j2 +0 -0
  102. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/docker-compose.sqlite.yml.j2 +0 -0
  103. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/dockerignore.j2 +0 -0
  104. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/main.py.j2 +0 -0
  105. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/src/pyarch/templates/project/base/ruff.toml.j2 +0 -0
  106. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/integration/test_generated_project.py +0 -0
  107. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_add_integration.py +0 -0
  108. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_auth_integration.py +0 -0
  109. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_database_cli.py +0 -0
  110. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_database_service.py +0 -0
  111. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_dry_run.py +0 -0
  112. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_generate_cli.py +0 -0
  113. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_manifest.py +0 -0
  114. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_redis_integration.py +0 -0
  115. {pyarch_cli-0.4.0 → pyarch_cli-0.4.1}/tests/unit/test_source_edit.py +0 -0
@@ -0,0 +1,121 @@
1
+ Metadata-Version: 2.5
2
+ Name: PyArch-CLI
3
+ Version: 0.4.1
4
+ Summary: CLI for creating and extending FastAPI projects
5
+ Project-URL: Homepage, https://github.com/Allcode-1/PyArch
6
+ Project-URL: Repository, https://github.com/Allcode-1/PyArch
7
+ Project-URL: Issues, https://github.com/Allcode-1/PyArch/issues
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: cli,fastapi,generator,jinja2,sqlalchemy,typer
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Code Generators
19
+ Requires-Python: >=3.13
20
+ Requires-Dist: cryptography>=46.0.3
21
+ Requires-Dist: jinja2>=3.1.6
22
+ Requires-Dist: rich>=15.0.0
23
+ Requires-Dist: tomlkit>=0.15.0
24
+ Requires-Dist: typer>=0.24.2
25
+ Description-Content-Type: text/markdown
26
+
27
+ # PyArch
28
+
29
+ [![PyPI](https://img.shields.io/pypi/v/PyArch-CLI)](https://pypi.org/project/PyArch-CLI/)
30
+ ![Python](https://img.shields.io/badge/Python-3.13%2B-blue)
31
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
32
+
33
+ PyArch is a CLI for creating and growing FastAPI projects.
34
+
35
+ Starting a FastAPI service usually means an hour of the same setup: project
36
+ layout, database session, Alembic, settings, Docker, tests, CI. Every new entity
37
+ then needs a model, schemas, a repository, a service, routes and tests, plus
38
+ registration in a few shared files. PyArch does this with one command and
39
+ produces ordinary, readable code you own and edit as usual.
40
+
41
+ It is not a one-shot template: PyArch remembers what it generated in
42
+ `pyarch.toml`, so you can keep adding modules and integrations to a project
43
+ that already has your code in it.
44
+
45
+ <p align="center">
46
+ <img src="https://raw.githubusercontent.com/Allcode-1/pyarch/main/assets/pyarch-demo.gif" alt="PyArch CLI demo" width="900">
47
+ </p>
48
+
49
+ ## Why PyArch?
50
+
51
+ - **Less boilerplate.** A working API with PostgreSQL or SQLite, Alembic,
52
+ Docker Compose, tests and CI in one command.
53
+ - **Full CRUD modules.** Model, schemas, repository, service, routes and tests,
54
+ wired into the app automatically.
55
+ - **Integrations on demand.** JWT auth with protected routes, Redis with
56
+ cache-aside reads.
57
+ - **Safe to run on a live project.** Preview changes with `--dry-run --diff`;
58
+ a failed command rolls back every file it touched.
59
+ - **No lock-in.** Generated code has no runtime dependency on PyArch.
60
+
61
+ ## Installation
62
+
63
+ Requires Python 3.13+ and [uv](https://docs.astral.sh/uv/).
64
+
65
+ ```bash
66
+ pip install pyarch-cli
67
+ ```
68
+
69
+ ## Quick Start
70
+
71
+ ```bash
72
+ pyarch init my_project # PostgreSQL by default, or --database sqlite
73
+ cd my_project
74
+ pyarch db init # create and apply the initial migration
75
+ docker compose up -d
76
+ ```
77
+
78
+ Open `http://127.0.0.1:8000/docs` for Swagger UI.
79
+
80
+ Add features as the project grows:
81
+
82
+ ```bash
83
+ pyarch generate module book # /api/v1/books
84
+ pyarch add integration auth
85
+ pyarch generate module order --protected # routes require a JWT
86
+ pyarch add integration redis
87
+ pyarch generate module author --cache # cached reads by id
88
+ pyarch db upgrade -m "add books, orders, authors"
89
+ ```
90
+
91
+ ## Commands
92
+
93
+ | Command | Description |
94
+ | --- | --- |
95
+ | `pyarch init <name>` | Create a project |
96
+ | `pyarch generate module <name>` | Add a CRUD module (`--protected`, `--cache`) |
97
+ | `pyarch add integration <auth\|redis>` | Add an integration |
98
+ | `pyarch db init` | Create and apply the initial migration |
99
+ | `pyarch db upgrade -m <message>` | Generate and apply a migration, restart the API |
100
+ | `pyarch info` | Show the project configuration |
101
+
102
+ `generate` and `add` accept `--dry-run` and `--diff`. Run `pyarch <command> --help`
103
+ for all options.
104
+
105
+ ## Documentation
106
+
107
+ - [Generated project](https://github.com/Allcode-1/pyarch/blob/main/docs/generated-project.md): layout, modules, naming, manifest
108
+ - [Configuration](https://github.com/Allcode-1/pyarch/blob/main/docs/configuration.md): settings, `.env`, ports
109
+ - [Integrations](https://github.com/Allcode-1/pyarch/blob/main/docs/integrations.md): auth, Redis and caching
110
+ - [Migrations](https://github.com/Allcode-1/pyarch/blob/main/docs/migrations.md): `pyarch db` and Docker Compose
111
+ - [How it works](https://github.com/Allcode-1/pyarch/blob/main/docs/how-it-works.md): rollback, dry-run, registration
112
+ - [Development](https://github.com/Allcode-1/pyarch/blob/main/docs/development.md): working on PyArch itself
113
+
114
+ ## Status
115
+
116
+ PyArch is in alpha: commands, templates and the manifest format may change.
117
+ Release notes are on [GitHub Releases](https://github.com/Allcode-1/pyarch/releases).
118
+
119
+ ## License
120
+
121
+ [MIT](https://github.com/Allcode-1/pyarch/blob/main/LICENSE)
@@ -0,0 +1,95 @@
1
+ # PyArch
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/PyArch-CLI)](https://pypi.org/project/PyArch-CLI/)
4
+ ![Python](https://img.shields.io/badge/Python-3.13%2B-blue)
5
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
6
+
7
+ PyArch is a CLI for creating and growing FastAPI projects.
8
+
9
+ Starting a FastAPI service usually means an hour of the same setup: project
10
+ layout, database session, Alembic, settings, Docker, tests, CI. Every new entity
11
+ then needs a model, schemas, a repository, a service, routes and tests, plus
12
+ registration in a few shared files. PyArch does this with one command and
13
+ produces ordinary, readable code you own and edit as usual.
14
+
15
+ It is not a one-shot template: PyArch remembers what it generated in
16
+ `pyarch.toml`, so you can keep adding modules and integrations to a project
17
+ that already has your code in it.
18
+
19
+ <p align="center">
20
+ <img src="https://raw.githubusercontent.com/Allcode-1/pyarch/main/assets/pyarch-demo.gif" alt="PyArch CLI demo" width="900">
21
+ </p>
22
+
23
+ ## Why PyArch?
24
+
25
+ - **Less boilerplate.** A working API with PostgreSQL or SQLite, Alembic,
26
+ Docker Compose, tests and CI in one command.
27
+ - **Full CRUD modules.** Model, schemas, repository, service, routes and tests,
28
+ wired into the app automatically.
29
+ - **Integrations on demand.** JWT auth with protected routes, Redis with
30
+ cache-aside reads.
31
+ - **Safe to run on a live project.** Preview changes with `--dry-run --diff`;
32
+ a failed command rolls back every file it touched.
33
+ - **No lock-in.** Generated code has no runtime dependency on PyArch.
34
+
35
+ ## Installation
36
+
37
+ Requires Python 3.13+ and [uv](https://docs.astral.sh/uv/).
38
+
39
+ ```bash
40
+ pip install pyarch-cli
41
+ ```
42
+
43
+ ## Quick Start
44
+
45
+ ```bash
46
+ pyarch init my_project # PostgreSQL by default, or --database sqlite
47
+ cd my_project
48
+ pyarch db init # create and apply the initial migration
49
+ docker compose up -d
50
+ ```
51
+
52
+ Open `http://127.0.0.1:8000/docs` for Swagger UI.
53
+
54
+ Add features as the project grows:
55
+
56
+ ```bash
57
+ pyarch generate module book # /api/v1/books
58
+ pyarch add integration auth
59
+ pyarch generate module order --protected # routes require a JWT
60
+ pyarch add integration redis
61
+ pyarch generate module author --cache # cached reads by id
62
+ pyarch db upgrade -m "add books, orders, authors"
63
+ ```
64
+
65
+ ## Commands
66
+
67
+ | Command | Description |
68
+ | --- | --- |
69
+ | `pyarch init <name>` | Create a project |
70
+ | `pyarch generate module <name>` | Add a CRUD module (`--protected`, `--cache`) |
71
+ | `pyarch add integration <auth\|redis>` | Add an integration |
72
+ | `pyarch db init` | Create and apply the initial migration |
73
+ | `pyarch db upgrade -m <message>` | Generate and apply a migration, restart the API |
74
+ | `pyarch info` | Show the project configuration |
75
+
76
+ `generate` and `add` accept `--dry-run` and `--diff`. Run `pyarch <command> --help`
77
+ for all options.
78
+
79
+ ## Documentation
80
+
81
+ - [Generated project](https://github.com/Allcode-1/pyarch/blob/main/docs/generated-project.md): layout, modules, naming, manifest
82
+ - [Configuration](https://github.com/Allcode-1/pyarch/blob/main/docs/configuration.md): settings, `.env`, ports
83
+ - [Integrations](https://github.com/Allcode-1/pyarch/blob/main/docs/integrations.md): auth, Redis and caching
84
+ - [Migrations](https://github.com/Allcode-1/pyarch/blob/main/docs/migrations.md): `pyarch db` and Docker Compose
85
+ - [How it works](https://github.com/Allcode-1/pyarch/blob/main/docs/how-it-works.md): rollback, dry-run, registration
86
+ - [Development](https://github.com/Allcode-1/pyarch/blob/main/docs/development.md): working on PyArch itself
87
+
88
+ ## Status
89
+
90
+ PyArch is in alpha: commands, templates and the manifest format may change.
91
+ Release notes are on [GitHub Releases](https://github.com/Allcode-1/pyarch/releases).
92
+
93
+ ## License
94
+
95
+ [MIT](https://github.com/Allcode-1/pyarch/blob/main/LICENSE)
@@ -0,0 +1,30 @@
1
+ # Configuration
2
+
3
+ ## Settings
4
+
5
+ `app/core/config.py` groups settings into sections:
6
+
7
+ | Section | Environment variables |
8
+ | --- | --- |
9
+ | `settings.database` | `DATABASE_URL` |
10
+ | `settings.pagination` | `PAGINATION__DEFAULT_LIMIT` (50), `PAGINATION__MAX_LIMIT` (100) |
11
+ | `settings.auth_jwt` | `AUTH_JWT__*`, e.g. `AUTH_JWT__ALGORITHM` |
12
+ | `settings.redis` | `REDIS__*`, e.g. `REDIS__URL`, `REDIS__TTL_SECONDS` |
13
+
14
+ Sections are nested with `__` as the delimiter. Integration sections appear only
15
+ after the integration is added.
16
+
17
+ ## `.env`
18
+
19
+ `pyarch init` creates `.env` from `.env.example` with working local defaults:
20
+ PostgreSQL user and password `postgres`, database `app`. `.env` is git-ignored;
21
+ `.env.example` is committed.
22
+
23
+ If host ports 5432 or 8000 are taken, change `POSTGRES_PORT` / `API_PORT` in
24
+ `.env` together with the port in `DATABASE_URL` and `TEST_DATABASE_URL`.
25
+
26
+ ## Tests
27
+
28
+ `uv run pytest` runs the generated tests. For PostgreSQL projects the test suite
29
+ uses `TEST_DATABASE_URL` and creates the `app_test` database on the same server
30
+ automatically.
@@ -0,0 +1,24 @@
1
+ # Development
2
+
3
+ ```bash
4
+ git clone https://github.com/Allcode-1/pyarch.git
5
+ cd pyarch
6
+ uv sync --group dev
7
+ uv run pyarch --help
8
+ ```
9
+
10
+ Install the checkout as an editable CLI tool:
11
+
12
+ ```bash
13
+ uv tool install --editable .
14
+ ```
15
+
16
+ Checks to run before a pull request:
17
+
18
+ ```bash
19
+ uv run pytest
20
+ uv run ruff check .
21
+ uv run ruff format --check .
22
+ uv run mypy src tests
23
+ uv build
24
+ ```
@@ -0,0 +1,91 @@
1
+ # Generated Project
2
+
3
+ ## Layout
4
+
5
+ ```text
6
+ my_project/
7
+ ├── app/
8
+ │ ├── api/v1/ # routers
9
+ │ ├── core/ # settings
10
+ │ ├── db/ # engine and sessions
11
+ │ ├── dependencies/
12
+ │ ├── models/
13
+ │ ├── repositories/
14
+ │ ├── schemas/
15
+ │ ├── services/
16
+ │ └── main.py
17
+ ├── tests/
18
+ ├── alembic/
19
+ ├── .github/workflows/ # lint and tests, PostgreSQL service for postgres projects
20
+ ├── Dockerfile # PostgreSQL projects
21
+ ├── docker-compose.yml # PostgreSQL projects
22
+ ├── .env # local defaults, git-ignored
23
+ ├── .env.example
24
+ ├── pyarch.toml # PyArch manifest
25
+ └── pyproject.toml
26
+ ```
27
+
28
+ The application, tests and migrations directories can be renamed at creation
29
+ time with `--app-dir`, `--tests-dir` and `--migrations-dir`. Every later command
30
+ uses the configured paths.
31
+
32
+ Integrations add their code under `app/infra/` (for example `app/infra/redis/`)
33
+ only when enabled. Auth lives in `app/auth/`.
34
+
35
+ ## CRUD Modules
36
+
37
+ `pyarch generate module <name>` adds:
38
+
39
+ - a SQLAlchemy model;
40
+ - create, update and response schemas;
41
+ - a repository and a service;
42
+ - list, get, create, update and delete routes;
43
+ - tests for every route;
44
+ - model and router registration in the existing application.
45
+
46
+ Options:
47
+
48
+ - `--protected` requires a valid access token on every route (needs the auth
49
+ integration);
50
+ - `--cache` caches reads by id in Redis (needs the redis integration), see
51
+ [Integrations](integrations.md#caching-crud-modules).
52
+
53
+ ## Naming
54
+
55
+ Module names are singular Python identifiers. PyArch derives the table and route
56
+ names: `book` produces the `books` table and `/api/v1/books`. Names that are
57
+ already plural (`books`, `people`, `news`) are kept as they are.
58
+ Two modules can not share a table: `book` and `books` both map to `books`, so
59
+ the second one is rejected. With the auth integration, names mapping to `users`
60
+ or `refresh_sessions` are rejected as well.
61
+
62
+ ## Manifest
63
+
64
+ `pyarch.toml` records the architecture, database, project paths, generated
65
+ modules and enabled integrations:
66
+
67
+ ```toml
68
+ schema_version = 1
69
+ pyarch_version = "0.4.1"
70
+
71
+ [project]
72
+ name = "my_project"
73
+ architecture = "layered"
74
+
75
+ [database]
76
+ engine = "postgres"
77
+ access = "sync"
78
+
79
+ [paths]
80
+ application = "app"
81
+ tests = "tests"
82
+ migrations = "alembic"
83
+
84
+ [state]
85
+ modules = ["book"]
86
+ integrations = ["auth"]
87
+ cached_modules = []
88
+ ```
89
+
90
+ Commands read it instead of guessing from the file tree and update it after a
91
+ successful change. Commit it with the rest of the project.
@@ -0,0 +1,50 @@
1
+ # How It Works
2
+
3
+ ```text
4
+ Typer CLI → application services → generators → Jinja2 templates → project
5
+ ↑
6
+ pyarch.toml
7
+ ```
8
+
9
+ The CLI parses input and calls application services. Generators render Jinja2
10
+ templates and edit existing files. The manifest gives later commands the
11
+ project context.
12
+
13
+ ## Safe Generation
14
+
15
+ `pyarch init` builds the project in a staging directory and moves it into place
16
+ only after every step succeeds; on failure the staging directory is removed.
17
+
18
+ `generate module` and `add integration` record every file they touch, including
19
+ the manifest and dependency files, and restore them if any step fails.
20
+
21
+ ## Dry Run
22
+
23
+ ```bash
24
+ pyarch generate module book --dry-run --diff
25
+ ```
26
+
27
+ With `--dry-run` the command runs against a temporary copy of the project and
28
+ prints the files it would create or modify and the dependency commands it would
29
+ run (`uv add ...`). The project is not changed and no commands are executed.
30
+ Validation errors are reported exactly as in a real run. `--diff` adds the full
31
+ unified diff. `pyarch init` has no dry run: it only creates a new directory.
32
+
33
+ ## Registration
34
+
35
+ New models, routers, settings sections and Compose services are inserted at
36
+ `# pyarch:*` markers in the generated files. When a marker is missing (older
37
+ projects or manual edits), PyArch falls back to the Python syntax tree: imports
38
+ go after the last import, settings fields into the `Settings` class, model names
39
+ into `__all__` and router includes to the end of the router module.
40
+
41
+ ## Manifest
42
+
43
+ Scanning the file tree shows which files exist, not which choices produced them.
44
+ `pyarch.toml` stores those choices, so commands never guess the architecture,
45
+ database or enabled features.
46
+
47
+ ## Templates
48
+
49
+ Templates are Jinja2 with `StrictUndefined`: missing template context fails
50
+ during generation instead of producing incomplete files.
@@ -0,0 +1,71 @@
1
+ # Integrations
2
+
3
+ Integrations are added with `pyarch add integration <name>`. Each one installs
4
+ its dependencies, generates its code and registers its settings section.
5
+
6
+ ## Auth
7
+
8
+ ```bash
9
+ pyarch add integration auth
10
+ ```
11
+
12
+ Adds JWT authentication with generated RSA keys and a `User` model.
13
+
14
+ | Route | Description |
15
+ | --- | --- |
16
+ | `POST /auth/register` | Create a user |
17
+ | `POST /auth/login` | Get an access and refresh token pair |
18
+ | `POST /auth/refresh` | Rotate the refresh token |
19
+ | `POST /auth/logout` | Revoke the refresh token |
20
+ | `GET /auth/users/me` | Current user |
21
+ | `GET /auth/users` | List users |
22
+
23
+ - Passwords need at least 8 characters with uppercase, lowercase, digit and
24
+ special characters, up to 72 bytes.
25
+ - Refresh tokens rotate on every use; reusing a revoked token revokes the whole
26
+ token family.
27
+
28
+ Protect a module's routes with `pyarch generate module <name> --protected`.
29
+
30
+ ## Redis
31
+
32
+ ```bash
33
+ pyarch add integration redis
34
+ ```
35
+
36
+ Adds:
37
+
38
+ - the `redis` dependency and `fakeredis` as a dev dependency;
39
+ - `app/infra/redis/` with the client and cache helpers;
40
+ - `RedisSettings` in `Settings` and `REDIS__URL` in `.env` / `.env.example`;
41
+ - for PostgreSQL projects, a `redis` service in `docker-compose.yml`; the api
42
+ service gets `REDIS__URL` and `depends_on: redis` (`service_started`, so an
43
+ unhealthy cache never blocks the API);
44
+ - a test fixture that replaces Redis with in-memory `fakeredis`.
45
+
46
+ ## Caching CRUD Modules
47
+
48
+ ```bash
49
+ pyarch generate module author --cache
50
+ ```
51
+
52
+ Requires the redis integration; can be combined with `--protected`.
53
+
54
+ - `GET /<items>/{id}` reads from Redis, falls back to the database on a miss and
55
+ stores the response for `REDIS__TTL_SECONDS` (300 by default).
56
+ - `PATCH` and `DELETE` invalidate the entry after a successful commit.
57
+ - `404` responses are not cached.
58
+ - An entry that no longer matches the response schema is dropped and reloaded.
59
+ - Redis errors never fail a request: they are logged and the request goes to
60
+ the database. After a failure reads and writes skip Redis for
61
+ `REDIS__FAILURE_COOLDOWN_SECONDS` (30 by default), so an unavailable Redis
62
+ costs one connection timeout instead of one per request; invalidation is
63
+ always attempted.
64
+
65
+ Limits:
66
+
67
+ - list endpoints are not cached;
68
+ - a read that races with an update can store the old value until the TTL
69
+ expires;
70
+ - changes made outside the generated service do not invalidate the cache;
71
+ - caching can not be enabled for an already generated module.
@@ -0,0 +1,51 @@
1
+ # Migrations
2
+
3
+ Projects use Alembic. The `pyarch db` commands wrap it for PostgreSQL projects
4
+ running in Docker Compose.
5
+
6
+ ## `pyarch db init`
7
+
8
+ Creates and applies the initial revision without starting the application. Run
9
+ it once after `pyarch init`.
10
+
11
+ ## `pyarch db upgrade`
12
+
13
+ ```bash
14
+ pyarch db upgrade -m "add books"
15
+ ```
16
+
17
+ After a model change:
18
+
19
+ 1. generates an Alembic revision from the models;
20
+ 2. applies it;
21
+ 3. rebuilds and restarts only the API service; the database keeps running and
22
+ PyArch waits until the API is healthy.
23
+
24
+ Without `-m` PyArch prompts for a message. If the models have not changed, no
25
+ empty revision is created.
26
+
27
+ Migration files are source code: review and commit them. Compose never runs
28
+ migrations on its own.
29
+
30
+ ## Compose Service Names
31
+
32
+ PyArch finds the services in `docker compose config`: the API is the service
33
+ with a `build` key, the database is the one running a `postgres` image.
34
+ Renaming them is fine. If detection is ambiguous, set the names in
35
+ `pyarch.toml`:
36
+
37
+ ```toml
38
+ [compose]
39
+ api_service = "api"
40
+ db_service = "db"
41
+ ```
42
+
43
+ ## SQLite
44
+
45
+ SQLite projects have no Docker Compose setup, and `pyarch db` commands are not
46
+ available. Run Alembic directly:
47
+
48
+ ```bash
49
+ uv run alembic revision --autogenerate -m "add books"
50
+ uv run alembic upgrade head
51
+ ```
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "PyArch-CLI"
3
- version = "0.4.0"
4
- description = "Stateful CLI generator for Layered FastAPI projects"
3
+ version = "0.4.1"
4
+ description = "CLI for creating and extending FastAPI projects"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
7
7
  license = "MIT"
@@ -26,7 +26,7 @@ dependencies = [
26
26
  ]
27
27
 
28
28
  [project.scripts]
29
- pyarch = "pyarch.cli.app:app"
29
+ pyarch = "pyarch.main:main"
30
30
 
31
31
  [project.urls]
32
32
  Homepage = "https://github.com/Allcode-1/PyArch"
@@ -0,0 +1 @@
1
+ __version__ = "0.4.1"
@@ -6,6 +6,7 @@ from typing import Annotated, Never
6
6
 
7
7
  import typer
8
8
  from rich.console import Console
9
+ from rich.markup import escape
9
10
 
10
11
  from pyarch.services.dry_run import ChangeKind, DryRunReport, dry_run
11
12
 
@@ -71,15 +72,14 @@ def execute_or_exit[ResultT](action: Callable[[], ResultT]) -> ResultT:
71
72
  try:
72
73
  return action()
73
74
  except (
74
- FileExistsError,
75
- FileNotFoundError,
75
+ OSError,
76
76
  NotImplementedError,
77
77
  subprocess.CalledProcessError,
78
78
  ValueError,
79
79
  ) as error:
80
- abort(str(error))
80
+ abort("\n".join((str(error), *getattr(error, "__notes__", ()))))
81
81
 
82
82
 
83
83
  def abort(message: str) -> Never:
84
- console.print(f"[bold red]Error:[/bold red] {message}")
84
+ console.print(f"[bold red]Error:[/bold red] {escape(message)}")
85
85
  raise typer.Exit(code=1)