arclith-cli 0.7.1__tar.gz → 0.9.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 (29) hide show
  1. arclith_cli-0.9.0/LICENSE +180 -0
  2. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/PKG-INFO +3 -2
  3. arclith_cli-0.9.0/README.md +205 -0
  4. arclith_cli-0.9.0/arclith_cli/__init__.py +1 -0
  5. arclith_cli-0.9.0/arclith_cli/adapter_templates.py +194 -0
  6. arclith_cli-0.9.0/arclith_cli/add_adapter.py +609 -0
  7. arclith_cli-0.9.0/arclith_cli/capabilities.py +377 -0
  8. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/arclith_cli/entity_scanner.py +6 -5
  9. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/arclith_cli/main.py +118 -5
  10. arclith_cli-0.9.0/arclith_cli/project_paths.py +45 -0
  11. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/arclith_cli/rename.py +22 -11
  12. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/arclith_cli/scaffold.py +17 -2
  13. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/arclith_cli/updater.py +1 -3
  14. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/pyproject.toml +8 -3
  15. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/tests/e2e_manual.sh +18 -6
  16. arclith_cli-0.9.0/tests/test_add_adapter.py +280 -0
  17. arclith_cli-0.9.0/tests/test_capabilities.py +113 -0
  18. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/tests/test_e2e_scaffold.py +106 -8
  19. arclith_cli-0.9.0/tests/test_project_paths.py +27 -0
  20. arclith_cli-0.9.0/tests/test_rename.py +32 -0
  21. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/uv.lock +106 -8
  22. arclith_cli-0.7.1/README.md +0 -139
  23. arclith_cli-0.7.1/arclith_cli/__init__.py +0 -2
  24. arclith_cli-0.7.1/arclith_cli/adapter_templates.py +0 -173
  25. arclith_cli-0.7.1/arclith_cli/add_adapter.py +0 -288
  26. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/.gitignore +0 -0
  27. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/Makefile +0 -0
  28. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/arclith_cli/export_config.py +0 -0
  29. {arclith_cli-0.7.1 → arclith_cli-0.9.0}/tests/__init__.py +0 -0
@@ -0,0 +1,180 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and its Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of developing and
55
+ refining the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent contributions
76
+ Licensable by such Contributor that are necessarily infringed by
77
+ their Contribution(s) alone or by the combination of their
78
+ Contribution(s) with the Work to which such Contribution(s) was
79
+ submitted. If You institute patent litigation against any entity
80
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
81
+ the Work or any Contribution embodied within the Work constitutes
82
+ direct or contributory patent infringement, then any patent licenses
83
+ granted to You under this License for that Work shall terminate as
84
+ of the date such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the Work.
121
+
122
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
123
+ any Contribution intentionally submitted for inclusion in the Work
124
+ by You to the Licensor shall be under the terms and conditions of
125
+ this License, without any additional terms or conditions.
126
+ Notwithstanding the above, nothing herein shall supersede or modify
127
+ the terms of any separate license agreement you may have executed
128
+ with Licensor regarding such Contributions.
129
+
130
+ 6. Trademarks. This License does not grant permission to use the trade
131
+ names, trademarks, service marks, or product names of the Licensor,
132
+ except as required for reasonable and customary use in describing the
133
+ origin of the Work and reproducing the content of the NOTICE file.
134
+
135
+ 7. Disclaimer of Warranty. Unless required by applicable law or
136
+ agreed to in writing, Licensor provides the Work (and each
137
+ Contributor provides its Contributions) on an "AS IS" BASIS,
138
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
139
+ implied, including, without limitation, any warranties or conditions
140
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
141
+ PARTICULAR PURPOSE. You are solely responsible for determining the
142
+ appropriateness of using or reproducing the Work and assume any
143
+ risks associated with Your exercise of permissions under this License.
144
+
145
+ 8. Limitation of Liability. In no event and under no legal theory,
146
+ whether in tort (including negligence), contract, or otherwise,
147
+ unless required by applicable law (such as deliberate and grossly
148
+ negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special,
150
+ incidental, or exemplary damages of any character arising as a
151
+ result of this License or out of the use or inability to use the
152
+ Work (including but not limited to damages for loss of goodwill,
153
+ work stoppage, computer failure or malfunction, or all other
154
+ commercial damages or losses), even if such Contributor has been
155
+ advised of the possibility of such damages.
156
+
157
+ 9. Accepting Warranty or Liability. While redistributing the Work or
158
+ Derivative Works thereof, You may choose to offer, and charge a fee
159
+ for, acceptance of support, warranty, indemnity, or other liability
160
+ obligations and/or rights consistent with this License. However, in
161
+ accepting such obligations, You may offer only conditions that
162
+ You alone are responsible for, and not on behalf of any other
163
+ Contributor.
164
+
165
+ END OF TERMS AND CONDITIONS
166
+
167
+ Copyright 2026 Killian KOPP
168
+
169
+ Licensed under the Apache License, Version 2.0 (the "License");
170
+ you may not use this file except in compliance with the License.
171
+ You may obtain a copy of the License at
172
+
173
+ http://www.apache.org/licenses/LICENSE-2.0
174
+
175
+ Unless required by applicable law or agreed to in writing, software
176
+ distributed under the License is distributed on an "AS IS" BASIS,
177
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
178
+ See the License for the specific language governing permissions and
179
+ limitations under the License.
180
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: arclith-cli
3
- Version: 0.7.1
3
+ Version: 0.9.0
4
4
  Summary: CLI scaffolding tool for arclith — hexagonal architecture framework
5
5
  Author-email: Killian KOPP <killiankopp@gmail.com>
6
6
  License: Apache License
@@ -183,9 +183,10 @@ License: Apache License
183
183
  See the License for the specific language governing permissions and
184
184
  limitations under the License.
185
185
 
186
+ License-File: LICENSE
186
187
  Keywords: arclith,cli,ddd,hexagonal-architecture,scaffold
187
188
  Requires-Python: >=3.13
188
- Requires-Dist: arclith>=0.7.0
189
+ Requires-Dist: arclith>=0.12.0
189
190
  Requires-Dist: httpx>=0.27.0
190
191
  Requires-Dist: rich>=13.0.0
191
192
  Requires-Dist: typer>=0.15.0
@@ -0,0 +1,205 @@
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/arclith.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 layout `src/<package>/...` pour le code applicatif et un dossier `config/` structuré par adapter (voir section [Configuration](#configuration)).
34
+
35
+ ---
36
+
37
+ ### `add-adapter` — Ajouter un adapter
38
+
39
+ Wizard interactif à lancer **depuis la racine du projet cible**. Scaffold le code Python et/ou les fichiers de configuration pour un nouvel adapter. Par défaut, la capacité cible est `repository`.
40
+
41
+ ```bash
42
+ cd my-recipe-service
43
+ arclith-cli add-adapter
44
+ ```
45
+
46
+ Mode direct, utile pour CI, scripts de migration ou commandes reproductibles :
47
+
48
+ ```bash
49
+ arclith-cli add-adapter --adapter mongodb --entity Recipe --db-name my_recipe_service --yes
50
+ arclith-cli add-adapter --adapter duckdb --all-entities --path data/ --no-activate --yes
51
+ arclith-cli add-adapter --adapter mariadb --entity Recipe --param database=my_recipe_service --param user=app --yes
52
+ arclith-cli add-adapter --capability agent --adapter langgraph --param graph_name=recipe_agent --yes
53
+ arclith-cli add-adapter --capability observability --adapter langsmith
54
+ arclith-cli add-adapter --capability repository --adapter memory --entity Recipe --yes
55
+ ```
56
+
57
+ **Étapes du wizard :**
58
+
59
+ 1. **Type d'adapter** — selon la capacité : `memory` · `mongodb` · `duckdb` · `mariadb` · `langgraph` · `langsmith`
60
+ 2. **Entité(s) cible(s)** — détectées automatiquement pour les adapters entity-scoped ; ignorées pour `agent/langgraph` et `observability/langsmith`
61
+ 3. **Paramètres** — questions spécifiques à l'adapter :
62
+ - `mongodb` → `db_name`, `multitenant`
63
+ - `duckdb` → `path`
64
+ - `mariadb` → `host`, `port`, `database`, `user`, `driver`, `table_prefix`
65
+ - `langgraph` → `graph_name`
66
+ - `langsmith` → `tracing`, `project`, `endpoint`, `LANGSMITH_API_KEY`
67
+ - `memory` → aucun paramètre
68
+ 4. **Activation** — met à jour `config/adapters/adapters.yaml` pour les capacités à sélecteur (`repository: <adapter>` ou `observability: langsmith`) ; `agent/langgraph` est exposé par `langgraph.json` et `config/adapters/inbound/langgraph.yaml`
69
+ 5. **Récapitulatif** — liste des fichiers créés ou remplacés avant confirmation
70
+
71
+ | Option | Défaut | Description |
72
+ |--------|--------|-------------|
73
+ | `--capability` | `repository` | Capacité cible du catalogue standardisé (`repository`, `agent`, `observability`) |
74
+ | `--adapter` / `-a` | interactif | Adapter du catalogue : `memory`, `mongodb`, `duckdb`, `mariadb`, `langgraph`, `langsmith` |
75
+ | `--entity` / `-e` | auto si une seule entité | Entité cible, liste séparée par virgule acceptée |
76
+ | `--all-entities` | `false` | Génère l'adapter pour toutes les entités détectées |
77
+ | `--activate/--no-activate` | `--activate` | Met à jour `config/adapters/adapters.yaml` quand la capacité expose une clé d'activation |
78
+ | `--db-name` | nom du projet | Nom de base pour MongoDB |
79
+ | `--multitenant/--single-tenant` | `--single-tenant` | Mode MongoDB multitenant |
80
+ | `--path` | `data/` | Chemin DuckDB |
81
+ | `--param` | - | Paramètre adapter `key=value`, répétable pour les adapters du catalogue |
82
+ | `--yes` / `-y` | `false` | Skip la confirmation et utilise les valeurs fournies ou par défaut |
83
+
84
+ **Fichiers générés par entité :**
85
+
86
+ ```
87
+ config/adapters/outbound/<adapter>.yaml # config scopée si l'adapter en a besoin
88
+ src/<package>/adapters/outbound/<adapter>/__init__.py
89
+ src/<package>/adapters/outbound/<adapter>/repository.py # re-export
90
+ src/<package>/adapters/outbound/<adapter>/repositories/<entity>_repository.py # sous-classe à compléter
91
+ src/<package>/infrastructure/containers/<entity>_container.py # RepositoryRegistry régénéré
92
+ ```
93
+
94
+ > ⚠️ `src/<package>/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.
95
+
96
+ **LangGraph / LangSmith :**
97
+
98
+ ```bash
99
+ uv add "arclith[langgraph]"
100
+ arclith-cli add-adapter --capability agent --adapter langgraph
101
+ arclith-cli add-adapter --capability observability --adapter langsmith
102
+ uv run langgraph dev --no-browser --allow-blocking --port 2024
103
+ ```
104
+
105
+ L'adapter `agent/langgraph` génère `langgraph.json`, `config/adapters/inbound/langgraph.yaml` et
106
+ `src/<package>/adapters/inbound/langgraph/agent.py`. Le projet ne modifie ensuite que ce fichier pour
107
+ son agent. Comme `fastapi` et `fastmcp`, LangGraph est configuré par son nom produit dans
108
+ `AppConfig.langgraph`, sans `adapters.agent`. L'adapter `observability/langsmith` génère
109
+ `config/adapters/outbound/langsmith.yaml`, met
110
+ à jour `.env` et ajoute `.env` au `.gitignore` si besoin. LangSmith Studio devient l'endroit standard
111
+ pour tester les agents. Une `LANGSMITH_API_KEY` déjà présente est conservée si aucune nouvelle valeur
112
+ n'est fournie.
113
+
114
+ Parcours complet avec entité, API, LangGraph, LangSmith et LM Studio:
115
+ [`docs/agent-quickstart.md`](../docs/agent-quickstart.md).
116
+
117
+ ---
118
+
119
+ ### `capabilities` — Lister le catalogue standardisé
120
+
121
+ Affiche les capacités et adapters connus par la CLI.
122
+
123
+ ```bash
124
+ arclith-cli capabilities
125
+ arclith-cli capabilities --json
126
+ ```
127
+
128
+ Le catalogue est la source de vérité pour les adapters supportés, leurs paramètres, leur chemin de configuration et la clé d'activation.
129
+
130
+ ---
131
+
132
+ ### `export-config` — Générer `config.yaml` pour K8s
133
+
134
+ Fusionne le dossier `config/` en un fichier YAML unique, à lancer **depuis la racine du projet**.
135
+
136
+ ```bash
137
+ arclith-cli export-config # → ./config.yaml
138
+ arclith-cli export-config --output dist/app.yaml # chemin personnalisé
139
+ ```
140
+
141
+ Le fichier généré peut être monté directement comme **ConfigMap** Kubernetes.
142
+ Arclith le lit au même titre que le dossier `config/` :
143
+
144
+ ```python
145
+ # dev
146
+ arclith = Arclith("config/")
147
+
148
+ # K8s (ConfigMap monté sur /app/config.yaml)
149
+ arclith = Arclith("config.yaml")
150
+ ```
151
+
152
+ > ⚠️ `config.yaml` est un **artefact généré** — l'ajouter à `.gitignore`.
153
+ > La source de vérité reste `config/`.
154
+
155
+ ---
156
+
157
+ ### `update` — Mettre à jour le CLI
158
+
159
+ ```bash
160
+ arclith-cli update
161
+ ```
162
+
163
+ ### `version` — Afficher la version
164
+
165
+ ```bash
166
+ arclith-cli version
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Configuration
172
+
173
+ 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é.
174
+
175
+ ```
176
+ config/
177
+ app.yaml # app: { name, version, description }
178
+ soft_delete.yaml # soft_delete: { retention_days }
179
+ secrets.yaml # secrets: { resolver, mappings, vault, yaml }
180
+ adapters/
181
+ adapters.yaml # adapters: { logger, repository } ← adapter actif
182
+ outbound/
183
+ mongodb.yaml # adapters.mongodb: { db_name, multitenant }
184
+ duckdb.yaml # adapters.duckdb: { path, multitenant }
185
+ mariadb.yaml # adapters.mariadb: { host, port, database, user, ... }
186
+ langsmith.yaml # adapters.langsmith: { tracing, project, endpoint, ... }
187
+ inbound/
188
+ fastapi.yaml # api: { host, port, reload }
189
+ fastmcp.yaml # mcp: { host, port }
190
+ probe.yaml # probe: { host, port, enabled }
191
+ keycloak.yaml # keycloak: { url, realm }
192
+ tenant.yaml # tenant: { vault_addr, … }
193
+ license.yaml # license: { role }
194
+ cache.yaml # cache: { backend, redis_url, … }
195
+ ```
196
+
197
+ Pour changer l'adapter actif sans passer par le wizard :
198
+
199
+ ```yaml
200
+ # config/adapters/adapters.yaml
201
+ repository: duckdb # memory | mongodb | duckdb | mariadb
202
+ observability: langsmith
203
+ ```
204
+
205
+ Pour MariaDB, ne committez pas le mot de passe. Mappez `adapters.mariadb.password` ou `adapters.mariadb.url` via `config/secrets.yaml`, un resolver `env` ou Vault.
@@ -0,0 +1 @@
1
+ __version__ = "0.9.0"
@@ -0,0 +1,194 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ # ── Python repository subclass templates ─────────────────────────────────────
6
+
7
+ REPO_PYTHON: dict[str, str] = {
8
+ "memory": """\
9
+ from arclith.adapters.outbound.memory.repository import InMemoryRepository
10
+ from {domain_import}.models.{snake} import {pascal}
11
+ from {domain_import}.ports.outbound.{snake}_repository import {pascal}Repository
12
+
13
+
14
+ class InMemory{pascal}Repository(InMemoryRepository[{pascal}], {pascal}Repository):
15
+ pass # TODO: add custom query methods if needed
16
+ """,
17
+ "mongodb": """\
18
+ from arclith.adapters.outbound.mongodb.config import MongoDBConfig
19
+ from arclith.adapters.outbound.mongodb.repository import MongoDBRepository
20
+ from arclith.domain.ports.outbound.logger import Logger
21
+ from {domain_import}.models.{snake} import {pascal}
22
+ from {domain_import}.ports.outbound.{snake}_repository import {pascal}Repository
23
+
24
+
25
+ class MongoDB{pascal}Repository(MongoDBRepository[{pascal}], {pascal}Repository):
26
+ def __init__(self, config: MongoDBConfig, logger: Logger) -> None:
27
+ super().__init__(config, {pascal}, logger)
28
+
29
+ # TODO: add custom query methods here
30
+ # async def find_by_name(self, name: str) -> list[{pascal}]:
31
+ # async with self._collection() as col:
32
+ # return [
33
+ # self._from_doc(doc)
34
+ # async for doc in col.find({{"name": name, "deleted_at": None}})
35
+ # ]
36
+ """,
37
+ "duckdb": """\
38
+ from arclith.adapters.outbound.duckdb.repository import DuckDBRepository
39
+ from {domain_import}.models.{snake} import {pascal}
40
+ from {domain_import}.ports.outbound.{snake}_repository import {pascal}Repository
41
+
42
+
43
+ class DuckDB{pascal}Repository(DuckDBRepository[{pascal}], {pascal}Repository):
44
+ def __init__(self, path: str) -> None:
45
+ super().__init__(path, {pascal})
46
+
47
+ # TODO: add custom query methods here
48
+ # async def find_by_name(self, name: str) -> list[{pascal}]:
49
+ # rows = self._fetch(
50
+ # f"SELECT * FROM {{self._table}} WHERE deleted_at IS NULL AND lower(name) LIKE ?",
51
+ # [f"%{{name.lower()}}%"],
52
+ # )
53
+ # return [self._row_to_entity(r) for r in rows]
54
+ """,
55
+ "mariadb": """\
56
+ from arclith.adapters.outbound.mariadb.config import MariaDBConfig
57
+ from arclith.adapters.outbound.mariadb.repository import MariaDBRepository
58
+ from arclith.domain.ports.outbound.logger import Logger
59
+ from {domain_import}.models.{snake} import {pascal}
60
+ from {domain_import}.ports.outbound.{snake}_repository import {pascal}Repository
61
+
62
+
63
+ class MariaDB{pascal}Repository(MariaDBRepository[{pascal}], {pascal}Repository):
64
+ def __init__(self, config: MariaDBConfig, logger: Logger) -> None:
65
+ super().__init__(config, {pascal}, logger)
66
+
67
+ # TODO: add custom query methods here
68
+ """,
69
+ }
70
+
71
+ # ── repository.py re-export template ─────────────────────────────────────────
72
+
73
+ REPO_REEXPORT: dict[str, str] = {
74
+ "memory": """\
75
+ from {adapters_import}.outbound.memory.repositories.{snake}_repository import InMemory{pascal}Repository
76
+
77
+ __all__ = ["InMemory{pascal}Repository"]
78
+ """,
79
+ "mongodb": """\
80
+ from {adapters_import}.outbound.mongodb.repositories.{snake}_repository import MongoDB{pascal}Repository
81
+
82
+ __all__ = ["MongoDB{pascal}Repository"]
83
+ """,
84
+ "duckdb": """\
85
+ from {adapters_import}.outbound.duckdb.repositories.{snake}_repository import DuckDB{pascal}Repository
86
+
87
+ __all__ = ["DuckDB{pascal}Repository"]
88
+ """,
89
+ "mariadb": """\
90
+ from {adapters_import}.outbound.mariadb.repositories.{snake}_repository import MariaDB{pascal}Repository
91
+
92
+ __all__ = ["MariaDB{pascal}Repository"]
93
+ """,
94
+ }
95
+
96
+ # ── Container template (full file, regenerated with all installed adapters) ───
97
+
98
+ _CONTAINER_HEADER = """\
99
+ from {application_import}.services.{snake}_service import {pascal}Service
100
+ from arclith import Arclith, RepositoryRegistry
101
+ from arclith.domain.ports.outbound.logger import Logger
102
+ from arclith.infrastructure.config import AppConfig
103
+ from {domain_import}.models.{snake} import {pascal}
104
+ from {domain_import}.ports.outbound.{snake}_repository import {pascal}Repository
105
+
106
+ """
107
+
108
+ _CONTAINER_FACTORY: dict[str, str] = {
109
+ "memory": """\
110
+ def _build_memory(_cfg: AppConfig, _entity_class: type[{pascal}], _log: Logger) -> {pascal}Repository:
111
+ from {adapters_import}.outbound.memory.repository import InMemory{pascal}Repository
112
+ return InMemory{pascal}Repository()
113
+
114
+ """,
115
+ "mongodb": """\
116
+ def _build_mongodb(cfg: AppConfig, _entity_class: type[{pascal}], log: Logger) -> {pascal}Repository:
117
+ from {adapters_import}.outbound.mongodb.repository import MongoDB{pascal}Repository
118
+ from arclith.adapters.outbound.mongodb.config import MongoDBConfig
119
+ mongo = cfg.adapters.mongodb
120
+ if mongo is None:
121
+ raise ValueError("MongoDB settings are required when repository=mongodb")
122
+ return MongoDB{pascal}Repository(MongoDBConfig(uri=mongo.uri, db_name=mongo.db_name), log)
123
+
124
+ """,
125
+ "duckdb": """\
126
+ def _build_duckdb(cfg: AppConfig, _entity_class: type[{pascal}], _log: Logger) -> {pascal}Repository:
127
+ from {adapters_import}.outbound.duckdb.repository import DuckDB{pascal}Repository
128
+ duckdb = cfg.adapters.duckdb
129
+ if duckdb is None:
130
+ raise ValueError("DuckDB settings are required when repository=duckdb")
131
+ return DuckDB{pascal}Repository(duckdb.path)
132
+
133
+ """,
134
+ "mariadb": """\
135
+ def _build_mariadb(cfg: AppConfig, _entity_class: type[{pascal}], log: Logger) -> {pascal}Repository:
136
+ from {adapters_import}.outbound.mariadb.repository import MariaDB{pascal}Repository
137
+ from arclith.adapters.outbound.mariadb.config import MariaDBConfig
138
+ mariadb = cfg.adapters.mariadb
139
+ if mariadb is None:
140
+ raise ValueError("MariaDB settings are required when repository=mariadb")
141
+ return MariaDB{pascal}Repository(
142
+ MariaDBConfig(
143
+ url=mariadb.url,
144
+ host=mariadb.host,
145
+ port=mariadb.port,
146
+ database=mariadb.database,
147
+ user=mariadb.user,
148
+ password=mariadb.password,
149
+ driver=mariadb.driver,
150
+ table_prefix=mariadb.table_prefix,
151
+ ),
152
+ log,
153
+ )
154
+
155
+ """,
156
+ }
157
+
158
+ _CONTAINER_FOOTER = """\
159
+ _repository_registry: RepositoryRegistry[{pascal}, {pascal}Repository] = (
160
+ RepositoryRegistry[{pascal}, {pascal}Repository]()
161
+ {registrations}
162
+ )
163
+
164
+
165
+ def build_{snake}_service(arclith: Arclith) -> tuple[{pascal}Service, Logger]:
166
+ arclith.logger.info("🗄️ Repository adapter selected", adapter=arclith.config.adapters.repository)
167
+ repo: {pascal}Repository = arclith.repository({pascal}, registry=_repository_registry)
168
+ return {pascal}Service(repo, arclith.logger, arclith.config.soft_delete.retention_days), arclith.logger
169
+ """
170
+
171
+
172
+ def render_container(pascal: str, snake: str, installed_adapters: list[str], import_vars: dict[str, str]) -> str:
173
+ """Generate the full container file content for a given entity and its adapters."""
174
+ # memory is always included (arclith built-in, needs no extra files)
175
+ adapters = list(dict.fromkeys(["memory"] + installed_adapters))
176
+ vars = {"pascal": pascal, "snake": snake, **import_vars}
177
+
178
+ header = _CONTAINER_HEADER.format(**vars)
179
+ factories = "".join(
180
+ _CONTAINER_FACTORY[a].format(**vars)
181
+ for a in adapters
182
+ if a in _CONTAINER_FACTORY
183
+ )
184
+ registrations = "\n".join(
185
+ f" .register(\"{a}\", _build_{a})"
186
+ for a in adapters
187
+ if a in _CONTAINER_FACTORY
188
+ )
189
+ footer = _CONTAINER_FOOTER.format(**vars, registrations=registrations)
190
+ return header + factories + footer
191
+
192
+
193
+ def render(template: str, vars: dict[str, Any]) -> str:
194
+ return template.format(**vars)