arclith-cli 0.7.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.
- arclith_cli-0.7.1/.gitignore +6 -0
- arclith_cli-0.7.1/Makefile +27 -0
- arclith_cli-0.7.1/PKG-INFO +191 -0
- arclith_cli-0.7.1/README.md +139 -0
- arclith_cli-0.7.1/arclith_cli/__init__.py +2 -0
- arclith_cli-0.7.1/arclith_cli/adapter_templates.py +173 -0
- arclith_cli-0.7.1/arclith_cli/add_adapter.py +288 -0
- arclith_cli-0.7.1/arclith_cli/entity_scanner.py +67 -0
- arclith_cli-0.7.1/arclith_cli/export_config.py +69 -0
- arclith_cli-0.7.1/arclith_cli/main.py +199 -0
- arclith_cli-0.7.1/arclith_cli/rename.py +159 -0
- arclith_cli-0.7.1/arclith_cli/scaffold.py +65 -0
- arclith_cli-0.7.1/arclith_cli/updater.py +33 -0
- arclith_cli-0.7.1/pyproject.toml +38 -0
- arclith_cli-0.7.1/tests/__init__.py +0 -0
- arclith_cli-0.7.1/tests/e2e_manual.sh +76 -0
- arclith_cli-0.7.1/tests/test_e2e_scaffold.py +148 -0
- arclith_cli-0.7.1/uv.lock +1274 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
.PHONY: help setup test test-fast clean install
|
|
2
|
+
|
|
3
|
+
help:
|
|
4
|
+
@echo "arclith-cli — Makefile"
|
|
5
|
+
@echo ""
|
|
6
|
+
@echo " setup Install dependencies (uv sync --group dev)"
|
|
7
|
+
@echo " test Run E2E tests (scaffold + validation)"
|
|
8
|
+
@echo " test-fast Run tests excluding slow markers"
|
|
9
|
+
@echo " install Install CLI globally (uv tool install .)"
|
|
10
|
+
@echo " clean Remove test artifacts"
|
|
11
|
+
|
|
12
|
+
setup:
|
|
13
|
+
uv sync --group dev
|
|
14
|
+
|
|
15
|
+
test:
|
|
16
|
+
uv run pytest tests/ -v
|
|
17
|
+
|
|
18
|
+
test-fast:
|
|
19
|
+
uv run pytest tests/ -v -m "not slow"
|
|
20
|
+
|
|
21
|
+
install:
|
|
22
|
+
uv tool install .
|
|
23
|
+
|
|
24
|
+
clean:
|
|
25
|
+
rm -rf .pytest_cache
|
|
26
|
+
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
|
|
27
|
+
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arclith-cli
|
|
3
|
+
Version: 0.7.1
|
|
4
|
+
Summary: CLI scaffolding tool for arclith — hexagonal architecture framework
|
|
5
|
+
Author-email: Killian KOPP <killiankopp@gmail.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship made available under
|
|
41
|
+
the License, as indicated by a copyright notice that is included in
|
|
42
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
43
|
+
|
|
44
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
45
|
+
form, that is based on (or derived from) the Work and for which the
|
|
46
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
47
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
48
|
+
of this License, Derivative Works shall not include works that remain
|
|
49
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
50
|
+
the Work and its Derivative Works thereof.
|
|
51
|
+
|
|
52
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
53
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
54
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
55
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
56
|
+
or written communication sent to the Licensor or its representatives,
|
|
57
|
+
including but not limited to communication on electronic mailing lists,
|
|
58
|
+
source code control systems, and issue tracking systems that are managed
|
|
59
|
+
by, or on behalf of, the Licensor for the purpose of developing and
|
|
60
|
+
refining the Work, but excluding communication that is conspicuously
|
|
61
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
62
|
+
Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
65
|
+
whom a Contribution has been received by the Licensor and included
|
|
66
|
+
within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent contributions
|
|
81
|
+
Licensable by such Contributor that are necessarily infringed by
|
|
82
|
+
their Contribution(s) alone or by the combination of their
|
|
83
|
+
Contribution(s) with the Work to which such Contribution(s) was
|
|
84
|
+
submitted. If You institute patent litigation against any entity
|
|
85
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
86
|
+
the Work or any Contribution embodied within the Work constitutes
|
|
87
|
+
direct or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate as
|
|
89
|
+
of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
97
|
+
Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, You must include a readable copy of the
|
|
110
|
+
attribution notices contained within such NOTICE file, in
|
|
111
|
+
at least one of the following places: within a NOTICE text
|
|
112
|
+
file distributed as part of the Derivative Works; within
|
|
113
|
+
the Source form or documentation, if provided along with the
|
|
114
|
+
Derivative Works; or, within a display generated by the
|
|
115
|
+
Derivative Works, if and wherever such third-party notices
|
|
116
|
+
normally appear. The contents of the NOTICE file are for
|
|
117
|
+
informational purposes only and do not modify the License.
|
|
118
|
+
You may add Your own attribution notices within Derivative
|
|
119
|
+
Works that You distribute, alongside or in addition to the
|
|
120
|
+
NOTICE text from the Work, provided that such additional
|
|
121
|
+
attribution notices cannot be construed as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own license statement for Your modifications and
|
|
124
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
125
|
+
publish, distribute, sublicense, and/or sell copies of the Work.
|
|
126
|
+
|
|
127
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
128
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
129
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
130
|
+
this License, without any additional terms or conditions.
|
|
131
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
132
|
+
the terms of any separate license agreement you may have executed
|
|
133
|
+
with Licensor regarding such Contributions.
|
|
134
|
+
|
|
135
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
136
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
137
|
+
except as required for reasonable and customary use in describing the
|
|
138
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
139
|
+
|
|
140
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
141
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
142
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
143
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
144
|
+
implied, including, without limitation, any warranties or conditions
|
|
145
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
146
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
147
|
+
appropriateness of using or reproducing the Work and assume any
|
|
148
|
+
risks associated with Your exercise of permissions under this License.
|
|
149
|
+
|
|
150
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
151
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
152
|
+
unless required by applicable law (such as deliberate and grossly
|
|
153
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
154
|
+
liable to You for damages, including any direct, indirect, special,
|
|
155
|
+
incidental, or exemplary damages of any character arising as a
|
|
156
|
+
result of this License or out of the use or inability to use the
|
|
157
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
158
|
+
work stoppage, computer failure or malfunction, or all other
|
|
159
|
+
commercial damages or losses), even if such Contributor has been
|
|
160
|
+
advised of the possibility of such damages.
|
|
161
|
+
|
|
162
|
+
9. Accepting Warranty or Liability. While redistributing the Work or
|
|
163
|
+
Derivative Works thereof, You may choose to offer, and charge a fee
|
|
164
|
+
for, acceptance of support, warranty, indemnity, or other liability
|
|
165
|
+
obligations and/or rights consistent with this License. However, in
|
|
166
|
+
accepting such obligations, You may offer only conditions that
|
|
167
|
+
You alone are responsible for, and not on behalf of any other
|
|
168
|
+
Contributor.
|
|
169
|
+
|
|
170
|
+
END OF TERMS AND CONDITIONS
|
|
171
|
+
|
|
172
|
+
Copyright 2026 Killian KOPP
|
|
173
|
+
|
|
174
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
175
|
+
you may not use this file except in compliance with the License.
|
|
176
|
+
You may obtain a copy of the License at
|
|
177
|
+
|
|
178
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
179
|
+
|
|
180
|
+
Unless required by applicable law or agreed to in writing, software
|
|
181
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
182
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
183
|
+
See the License for the specific language governing permissions and
|
|
184
|
+
limitations under the License.
|
|
185
|
+
|
|
186
|
+
Keywords: arclith,cli,ddd,hexagonal-architecture,scaffold
|
|
187
|
+
Requires-Python: >=3.13
|
|
188
|
+
Requires-Dist: arclith>=0.7.0
|
|
189
|
+
Requires-Dist: httpx>=0.27.0
|
|
190
|
+
Requires-Dist: rich>=13.0.0
|
|
191
|
+
Requires-Dist: typer>=0.15.0
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# arclith-cli
|
|
2
|
+
|
|
3
|
+
`arclith-cli` génère instantanément un projet Python en architecture hexagonale prêt à démarrer, en téléchargeant le template officiel `_sample` depuis GitHub et en remplaçant l'entité de démo `Ingredient` par le nom de votre choix. Tout type de projet peut être scaffoldé — service REST, agent IA, API MCP — avec les ports, le nom de projet et le backend de persistance configurés d'emblée.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv tool install "git+https://github.com/karned-rekipe/framework.git#subdirectory=cli"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commandes
|
|
12
|
+
|
|
13
|
+
### `new` — Créer un projet
|
|
14
|
+
|
|
15
|
+
Scaffold un nouveau projet arclith depuis le template officiel `_sample`.
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Mode interactif — l'outil pose les questions
|
|
19
|
+
arclith-cli new
|
|
20
|
+
|
|
21
|
+
# Mode direct
|
|
22
|
+
arclith-cli new Recipe my-recipe-service
|
|
23
|
+
arclith-cli new RecipeStep meal-planner --port 8400
|
|
24
|
+
arclith-cli new MealPlan meal-plan-service --dir ~/projects --port 8500
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Option | Défaut | Description |
|
|
28
|
+
|--------|--------|-------------|
|
|
29
|
+
| `--port` / `-p` | `8000` | Port REST (MCP = port+1) |
|
|
30
|
+
| `--dir` / `-d` | `.` | Répertoire parent |
|
|
31
|
+
| `--ref` | `main` | Branche/tag du template |
|
|
32
|
+
|
|
33
|
+
Le projet généré utilise un dossier `config/` structuré par adapter (voir section [Configuration](#configuration)).
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### `add-adapter` — Ajouter un adapter output
|
|
38
|
+
|
|
39
|
+
Wizard interactif à lancer **depuis la racine du projet cible**. Scaffold le code Python et le fichier de configuration pour un nouvel adapter de persistance.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
cd my-recipe-service
|
|
43
|
+
arclith-cli add-adapter
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Étapes du wizard :**
|
|
47
|
+
|
|
48
|
+
1. **Type d'adapter** — `memory` · `mongodb` · `duckdb`
|
|
49
|
+
2. **Entité(s) cible(s)** — détectées automatiquement depuis `domain/models/` via AST ; sélection individuelle ou « toutes »
|
|
50
|
+
3. **Paramètres** — questions spécifiques à l'adapter :
|
|
51
|
+
- `mongodb` → `db_name`, `multitenant`
|
|
52
|
+
- `duckdb` → `path`
|
|
53
|
+
- `memory` → aucun paramètre
|
|
54
|
+
4. **Activation** — met à jour `config/adapters/adapters.yaml` (`repository: <adapter>`)
|
|
55
|
+
5. **Récapitulatif** — liste des fichiers créés ou remplacés avant confirmation
|
|
56
|
+
|
|
57
|
+
**Fichiers générés par entité :**
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
config/adapters/output/<adapter>.yaml # config scopée (mongodb/duckdb uniquement)
|
|
61
|
+
adapters/output/<adapter>/__init__.py
|
|
62
|
+
adapters/output/<adapter>/repository.py # re-export
|
|
63
|
+
adapters/output/<adapter>/repositories/<entity>_repository.py # sous-classe à compléter
|
|
64
|
+
infrastructure/containers/<entity>_container.py # AdapterRegistry régénéré
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
> ⚠️ `infrastructure/containers/<entity>_container.py` est **régénéré intégralement** si le fichier existe déjà — un avertissement est affiché dans le récapitulatif.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
### `export-config` — Générer `config.yaml` pour K8s
|
|
72
|
+
|
|
73
|
+
Fusionne le dossier `config/` en un fichier YAML unique, à lancer **depuis la racine du projet**.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
arclith-cli export-config # → ./config.yaml
|
|
77
|
+
arclith-cli export-config --output dist/app.yaml # chemin personnalisé
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Le fichier généré peut être monté directement comme **ConfigMap** Kubernetes.
|
|
81
|
+
Arclith le lit au même titre que le dossier `config/` :
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
# dev
|
|
85
|
+
arclith = Arclith("config/")
|
|
86
|
+
|
|
87
|
+
# K8s (ConfigMap monté sur /app/config.yaml)
|
|
88
|
+
arclith = Arclith("config.yaml")
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
> ⚠️ `config.yaml` est un **artefact généré** — l'ajouter à `.gitignore`.
|
|
92
|
+
> La source de vérité reste `config/`.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### `update` — Mettre à jour le CLI
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
arclith-cli update
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### `version` — Afficher la version
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
arclith-cli version
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Configuration
|
|
111
|
+
|
|
112
|
+
Les projets arclith utilisent un dossier `config/` à la place d'un `config.yaml` monolithique. Chaque fichier est **scopé** : son chemin détermine la section `AppConfig` dans laquelle son contenu est injecté.
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
config/
|
|
116
|
+
app.yaml # app: { name, version, description }
|
|
117
|
+
soft_delete.yaml # soft_delete: { retention_days }
|
|
118
|
+
secrets.yaml # secrets: { resolver, mappings, vault, yaml }
|
|
119
|
+
adapters/
|
|
120
|
+
adapters.yaml # adapters: { logger, repository } ← adapter actif
|
|
121
|
+
output/
|
|
122
|
+
mongodb.yaml # adapters.mongodb: { db_name, multitenant }
|
|
123
|
+
duckdb.yaml # adapters.duckdb: { path, multitenant }
|
|
124
|
+
input/
|
|
125
|
+
fastapi.yaml # api: { host, port, reload }
|
|
126
|
+
fastmcp.yaml # mcp: { host, port }
|
|
127
|
+
probe.yaml # probe: { host, port, enabled }
|
|
128
|
+
keycloak.yaml # keycloak: { url, realm }
|
|
129
|
+
tenant.yaml # tenant: { vault_addr, … }
|
|
130
|
+
license.yaml # license: { role }
|
|
131
|
+
cache.yaml # cache: { backend, redis_url, … }
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Pour changer l'adapter actif sans passer par le wizard :
|
|
135
|
+
|
|
136
|
+
```yaml
|
|
137
|
+
# config/adapters/adapters.yaml
|
|
138
|
+
repository: duckdb # memory | mongodb | duckdb
|
|
139
|
+
```
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
# ── Supported adapters ────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
SUPPORTED_ADAPTERS = ["memory", "mongodb", "duckdb"]
|
|
8
|
+
|
|
9
|
+
# ── Config YAML templates (scoped — no root key) ──────────────────────────────
|
|
10
|
+
|
|
11
|
+
CONFIG_YAML: dict[str, str] = {
|
|
12
|
+
"memory": "", # memory needs no config file
|
|
13
|
+
"mongodb": """\
|
|
14
|
+
multitenant: false # true = URI + db_name résolus par requête via JWT → Vault
|
|
15
|
+
db_name: {db_name} # uri → secrets.yaml ou Vault (fallback single-tenant)
|
|
16
|
+
""",
|
|
17
|
+
"duckdb": """\
|
|
18
|
+
multitenant: false
|
|
19
|
+
path: {path}
|
|
20
|
+
""",
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# ── Python repository subclass templates ─────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
REPO_PYTHON: dict[str, str] = {
|
|
26
|
+
"memory": """\
|
|
27
|
+
from arclith.adapters.output.memory.repository import InMemoryRepository
|
|
28
|
+
from domain.models.{snake} import {pascal}
|
|
29
|
+
from domain.ports.output.{snake}_repository import {pascal}Repository
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class InMemory{pascal}Repository(InMemoryRepository[{pascal}], {pascal}Repository):
|
|
33
|
+
pass # TODO: add custom query methods if needed
|
|
34
|
+
""",
|
|
35
|
+
"mongodb": """\
|
|
36
|
+
from arclith.adapters.output.mongodb.config import MongoDBConfig
|
|
37
|
+
from arclith.adapters.output.mongodb.repository import MongoDBRepository
|
|
38
|
+
from arclith.domain.ports.logger import Logger
|
|
39
|
+
from domain.models.{snake} import {pascal}
|
|
40
|
+
from domain.ports.output.{snake}_repository import {pascal}Repository
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class MongoDB{pascal}Repository(MongoDBRepository[{pascal}], {pascal}Repository):
|
|
44
|
+
def __init__(self, config: MongoDBConfig, logger: Logger) -> None:
|
|
45
|
+
super().__init__(config, {pascal}, logger)
|
|
46
|
+
|
|
47
|
+
# TODO: add custom query methods here
|
|
48
|
+
# async def find_by_name(self, name: str) -> list[{pascal}]:
|
|
49
|
+
# async with self._collection() as col:
|
|
50
|
+
# return [
|
|
51
|
+
# self._from_doc(doc)
|
|
52
|
+
# async for doc in col.find({{"name": name, "deleted_at": None}})
|
|
53
|
+
# ]
|
|
54
|
+
""",
|
|
55
|
+
"duckdb": """\
|
|
56
|
+
from arclith.adapters.output.duckdb.repository import DuckDBRepository
|
|
57
|
+
from domain.models.{snake} import {pascal}
|
|
58
|
+
from domain.ports.output.{snake}_repository import {pascal}Repository
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class DuckDB{pascal}Repository(DuckDBRepository[{pascal}], {pascal}Repository):
|
|
62
|
+
def __init__(self, path: str) -> None:
|
|
63
|
+
super().__init__(path, {pascal})
|
|
64
|
+
|
|
65
|
+
# TODO: add custom query methods here
|
|
66
|
+
# async def find_by_name(self, name: str) -> list[{pascal}]:
|
|
67
|
+
# rows = self._fetch(
|
|
68
|
+
# f"SELECT * FROM {{self._table}} WHERE deleted_at IS NULL AND lower(name) LIKE ?",
|
|
69
|
+
# [f"%{{name.lower()}}%"],
|
|
70
|
+
# )
|
|
71
|
+
# return [self._row_to_entity(r) for r in rows]
|
|
72
|
+
""",
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# ── repository.py re-export template ─────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
REPO_REEXPORT: dict[str, str] = {
|
|
78
|
+
"memory": """\
|
|
79
|
+
from adapters.output.memory.repositories.{snake}_repository import InMemory{pascal}Repository
|
|
80
|
+
|
|
81
|
+
__all__ = ["InMemory{pascal}Repository"]
|
|
82
|
+
""",
|
|
83
|
+
"mongodb": """\
|
|
84
|
+
from adapters.output.mongodb.repositories.{snake}_repository import MongoDB{pascal}Repository
|
|
85
|
+
|
|
86
|
+
__all__ = ["MongoDB{pascal}Repository"]
|
|
87
|
+
""",
|
|
88
|
+
"duckdb": """\
|
|
89
|
+
from adapters.output.duckdb.repositories.{snake}_repository import DuckDB{pascal}Repository
|
|
90
|
+
|
|
91
|
+
__all__ = ["DuckDB{pascal}Repository"]
|
|
92
|
+
""",
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
# ── Container template (full file, regenerated with all installed adapters) ───
|
|
96
|
+
|
|
97
|
+
_CONTAINER_HEADER = """\
|
|
98
|
+
from __future__ import annotations
|
|
99
|
+
|
|
100
|
+
from application.services.{snake}_service import {pascal}Service
|
|
101
|
+
from arclith import Arclith, AdapterRegistry
|
|
102
|
+
from arclith.infrastructure.config import AppConfig
|
|
103
|
+
from arclith.domain.ports.logger import Logger
|
|
104
|
+
from domain.models.{snake} import {pascal}
|
|
105
|
+
from domain.ports.output.{snake}_repository import {pascal}Repository
|
|
106
|
+
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
_CONTAINER_FACTORY: dict[str, str] = {
|
|
110
|
+
"memory": """\
|
|
111
|
+
def _build_memory(cfg: AppConfig, log: Logger) -> {pascal}Repository:
|
|
112
|
+
from adapters.output.memory.repository import InMemory{pascal}Repository
|
|
113
|
+
return InMemory{pascal}Repository()
|
|
114
|
+
|
|
115
|
+
""",
|
|
116
|
+
"mongodb": """\
|
|
117
|
+
def _build_mongodb(cfg: AppConfig, log: Logger) -> {pascal}Repository:
|
|
118
|
+
from adapters.output.mongodb.repository import MongoDB{pascal}Repository
|
|
119
|
+
from arclith.adapters.output.mongodb.config import MongoDBConfig
|
|
120
|
+
mongo = cfg.adapters.mongodb
|
|
121
|
+
if mongo is None:
|
|
122
|
+
raise RuntimeError("MongoDB settings are required when repository=mongodb")
|
|
123
|
+
return MongoDB{pascal}Repository(MongoDBConfig(uri=mongo.uri, db_name=mongo.db_name), log)
|
|
124
|
+
|
|
125
|
+
""",
|
|
126
|
+
"duckdb": """\
|
|
127
|
+
def _build_duckdb(cfg: AppConfig, log: Logger) -> {pascal}Repository:
|
|
128
|
+
from adapters.output.duckdb.repository import DuckDB{pascal}Repository
|
|
129
|
+
duckdb = cfg.adapters.duckdb
|
|
130
|
+
if duckdb is None:
|
|
131
|
+
raise RuntimeError("DuckDB settings are required when repository=duckdb")
|
|
132
|
+
return DuckDB{pascal}Repository(duckdb.path)
|
|
133
|
+
|
|
134
|
+
""",
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_CONTAINER_FOOTER = """\
|
|
138
|
+
_registry: AdapterRegistry[{pascal}] = (
|
|
139
|
+
AdapterRegistry()
|
|
140
|
+
{registrations}
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def build_{snake}_service(arclith: Arclith) -> tuple[{pascal}Service, Logger]:
|
|
145
|
+
arclith.logger.info("🗄️ Repository adapter selected", adapter=arclith.config.adapters.repository)
|
|
146
|
+
repo: {pascal}Repository = _registry.build(arclith.config, arclith.logger)
|
|
147
|
+
return {pascal}Service(repo, arclith.logger, arclith.config.soft_delete.retention_days), arclith.logger
|
|
148
|
+
"""
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def render_container(pascal: str, snake: str, installed_adapters: list[str]) -> str:
|
|
152
|
+
"""Generate the full container file content for a given entity and its adapters."""
|
|
153
|
+
# memory is always included (arclith built-in, needs no extra files)
|
|
154
|
+
adapters = list(dict.fromkeys(["memory"] + installed_adapters))
|
|
155
|
+
|
|
156
|
+
header = _CONTAINER_HEADER.format(pascal=pascal, snake=snake)
|
|
157
|
+
factories = "".join(
|
|
158
|
+
_CONTAINER_FACTORY[a].format(pascal=pascal, snake=snake)
|
|
159
|
+
for a in adapters
|
|
160
|
+
if a in _CONTAINER_FACTORY
|
|
161
|
+
)
|
|
162
|
+
registrations = "\n".join(
|
|
163
|
+
f" .register(\"{a}\", _build_{a})"
|
|
164
|
+
for a in adapters
|
|
165
|
+
if a in _CONTAINER_FACTORY
|
|
166
|
+
)
|
|
167
|
+
footer = _CONTAINER_FOOTER.format(pascal=pascal, snake=snake, registrations=registrations)
|
|
168
|
+
return header + factories + footer
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def render(template: str, vars: dict[str, Any]) -> str:
|
|
172
|
+
return template.format(**vars)
|
|
173
|
+
|