fastgen-cli 0.7.0__py3-none-win_amd64.whl

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.
@@ -0,0 +1,359 @@
1
+ Metadata-Version: 2.4
2
+ Name: fastgen-cli
3
+ Version: 0.7.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Environment :: Console
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Programming Language :: Rust
8
+ Classifier: Topic :: Software Development :: Code Generators
9
+ License-File: LICENSE
10
+ Summary: FastAPI feature-based module manager (nest-cli style for FastAPI), written in Rust
11
+ Keywords: fastapi,code-generator,scaffold,cli,nest-cli
12
+ Author: 一白开水
13
+ License: MIT
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
16
+ Project-URL: Homepage, https://github.com/YIbaikaishui/fastgen-cli
17
+ Project-URL: Issues, https://github.com/YIbaikaishui/fastgen-cli/issues
18
+ Project-URL: Repository, https://github.com/YIbaikaishui/fastgen-cli
19
+
20
+ <div align="center">
21
+
22
+ # ⚡ fastgen-cli
23
+
24
+ **A nest-cli style module manager for FastAPI** — scaffold modules, keep the project tidy, and let AI agents see the whole structure at a glance.
25
+
26
+ Zero-config. One command. Fill in the business logic yourself.
27
+
28
+ [![crates.io](https://img.shields.io/crates/v/fastgen-cli.svg)](https://crates.io/crates/fastgen-cli)
29
+ [![crates.io downloads](https://img.shields.io/crates/d/fastgen-cli.svg)](https://crates.io/crates/fastgen-cli)
30
+ [![Rust](https://img.shields.io/badge/written%20in-Rust-dea584.svg)](https://www.rust-lang.org/)
31
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
32
+ [![PyPI downloads](https://img.shields.io/pypi/dm/fastgen-cli)](https://pypi.org/project/fastgen-cli/)
33
+
34
+ [English](README.md) | [简体中文](README.zh-CN.md)
35
+
36
+ </div>
37
+
38
+ <p align="center">
39
+ <img src="./assets/readme/hero.svg" width="100%" alt="fastgen-cli: a nest-cli style module manager for FastAPI — scaffold projects and modules, keep structure tidy, keep an auto-maintained registry.">
40
+ </p>
41
+
42
+ ---
43
+
44
+ ## ✨ Why fastgen-cli?
45
+
46
+ FastAPI is famously unopinionated — which is great for freedom, but bad for *structure*. Projects drift into chaos: routers scattered, entities everywhere, no one knows what modules exist.
47
+
48
+ **fastgen-cli** fixes exactly that. It manages **module structure**, not your business code:
49
+
50
+ - 🏗️ **Scaffold whole projects** — `fastgen new my-app` creates a best-practice `src/`-layout FastAPI project (`.env`, `src/main.py`, `src/core/`, module registry, `tests/`, Alembic migrations) ready to run
51
+ - 🗂️ **One module = one folder** (`<src>/modules/<feature>/`), with a consistent shape every time
52
+ - ⚡ **Rust binary** — one self-contained executable, starts instantly, no Python runtime needed to run the tool
53
+ - 🧩 **Minimal skeleton** — ORM model, schemas, service boundary, router + shared session dependency. Just enough to *see* the module, never enough to get in the way
54
+ - 📇 **Auto-maintained registry** — `<src>/modules/__init__.py` maps every module to its import path; AI agents and devs read it to understand the project instantly
55
+ - 🔌 **Shared DB core** generated once — `<src>/core/` with pydantic-settings config + async SQLAlchemy `get_session` (best-practice, `expire_on_commit=False`, `AsyncAttrs`)
56
+ - 🔁 **Alembic migrations out of the box** — `alembic upgrade head` evolves your schema instead of deleting `app.db`; autogenerate picks up model changes automatically
57
+ - 🛡️ **Never overwrites your code** — only generates what's missing or empty
58
+
59
+ ---
60
+
61
+ ## 📦 Installation
62
+
63
+ ```bash
64
+ # From crates.io (any platform with a Rust toolchain)
65
+ cargo install fastgen-cli
66
+
67
+ # Or download a prebuilt binary from GitHub Releases:
68
+ # https://github.com/YIbaikaishui/fastgen-cli/releases/latest
69
+ ```
70
+
71
+ `fastgen` is a single self-contained binary — running it needs no Python runtime
72
+ at all. The projects it scaffolds are ordinary **Python 3.11+** FastAPI apps.
73
+
74
+ ---
75
+
76
+ ## 🚀 Quick start
77
+
78
+ ```bash
79
+ # Scaffold a whole project (src/ layout: .env, src/main.py, src/core/, tests/, Alembic)
80
+ fastgen new my-app
81
+ cd my-app && uv sync && uv run alembic upgrade head && uv run uvicorn src.main:app --reload
82
+
83
+ # Scaffold a user module (creates src/modules/user/ + src/core/ + registry + tests)
84
+ fastgen make module user
85
+
86
+ # See all registered modules and their boundaries
87
+ fastgen list
88
+ ```
89
+
90
+ That's it. No config file, no YAML, no spec — run a command, get the skeleton:
91
+
92
+ ```
93
+ $ fastgen list
94
+ Registered modules
95
+ ┏━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
96
+ ┃ module ┃ path ┃ description ┃
97
+ ┡━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
98
+ │ user │ src.modules.user │ User module. │
99
+ └────────┴──────────────────┴────────────────┘
100
+ ```
101
+
102
+ ---
103
+
104
+ ## 🔧 How it works
105
+
106
+ <p align="center">
107
+ <img src="./assets/readme/workflow.svg" width="100%" alt="Four steps: fastgen make module user scaffolds the skeleton, writes the registry entry, auto-mounts the router in main.py, then fastgen list verifies it.">
108
+ </p>
109
+
110
+ Every `fastgen make module <feature>` command does four things, in order:
111
+
112
+ 1. **Scaffold** — render the module skeleton into `<src>/modules/<feature>/` (model / schemas / service / router / tests). It only ever writes missing or empty files; anything already there stays untouched.
113
+ 2. **Register** — add the module to the auto-maintained registry (`<src>/modules/__init__.py`), a plain `modules: dict[str, str]` mapping each module name to its import path.
114
+ 3. **Auto-mount** — idempotently sync `<src>/main.py` so it imports the registry and calls `app.include_router(module.router)` for each entry, guarded by a `# --- fastgen: auto-mount (do not remove) ---` marker. No hand-editing `main.py` when adding modules.
115
+ 4. **Verify** — `fastgen list` prints the registry as a table, so both you and AI agents see the whole module structure at a glance.
116
+
117
+ > `fastgen new <name>` is the same mechanism applied to a whole project: it scaffolds `src/core/`, the registry, `tests/`, Alembic migrations and `.fastgen.json`, then lets `make module` grow the app from there.
118
+
119
+ The registry is deliberately boring — one plain dict, no metadata, no framework:
120
+
121
+ ```python
122
+ # src/modules/__init__.py — auto-maintained by fastgen
123
+ modules: dict[str, str] = {
124
+ "user": "src.modules.user",
125
+ }
126
+
127
+ __all__ = ["modules"]
128
+ ```
129
+
130
+ Because nothing generated by fastgen depends on fastgen at runtime, you can drop the tool anytime and keep a completely ordinary FastAPI project.
131
+
132
+ ---
133
+
134
+ ## 🧱 What it generates
135
+
136
+ ### `fastgen new <name>`
137
+
138
+ A complete, runnable best-practice FastAPI project:
139
+
140
+ ```
141
+ my-app/
142
+ ├── .env / .env.example # DATABASE_URL etc.
143
+ ├── .gitignore # ignores .env, venv, __pycache__, *.db
144
+ ├── .python-version # 3.11
145
+ ├── pyproject.toml # deps + ruff / pytest config
146
+ ├── README.md
147
+ ├── .fastgen.json # {"source_dir": "src"} — layout used by fastgen
148
+ ├── src/
149
+ │ ├── __init__.py
150
+ │ ├── main.py # FastAPI app; module routers auto-load from the registry
151
+ │ ├── core/ # shared infra (never overwritten)
152
+ │ │ ├── __init__.py
153
+ │ │ ├── config.py # pydantic-settings Settings, reads .env
154
+ │ │ └── database.py # Base (AsyncAttrs), async engine, get_session
155
+ │ └── modules/
156
+ │ └── __init__.py # 📇 module registry (auto-maintained)
157
+ ├── migrations/ # Alembic migrations (alembic.ini at project root)
158
+ │ ├── env.py # async env; DATABASE_URL from settings, models from the registry
159
+ │ ├── script.py.mako
160
+ │ └── versions/
161
+ │ └── 0001_initial.py # empty baseline revision
162
+ └── tests/
163
+ ├── __init__.py
164
+ ├── conftest.py # httpx ASGI client fixture
165
+ └── test_health.py # /health smoke test
166
+ ```
167
+
168
+ ### `fastgen make module <feature>`
169
+
170
+ ```
171
+ src/ (or app/ for a legacy project; fastgen auto-detects the layout)
172
+ ├── core/ # auto-created on first use (never overwritten)
173
+ │ ├── __init__.py
174
+ │ ├── config.py # pydantic-settings Settings, DATABASE_URL from .env
175
+ │ └── database.py # Base (AsyncAttrs), async engine, get_session
176
+ └── modules/ # 📇 vertical slices: one folder per business domain
177
+ ├── __init__.py # module registry (auto-maintained)
178
+ └── user/ # each module is internally layered
179
+ ├── __init__.py # re-exports the router from .api.router
180
+ ├── domain/ # entities + repository port (no I/O or framework)
181
+ │ ├── model.py # SQLAlchemy entity on Base (__tablename__ = plural)
182
+ │ └── repository.py # UserRepository Protocol (add/get/list/delete)
183
+ ├── application/ # use cases + DTOs (free of HTTP)
184
+ │ ├── schemas.py # UserBase / UserCreate / UserUpdate / UserRead
185
+ │ │ # UserRead has from_attributes=True so ORM objects serialize
186
+ │ └── user_service.py # UserService (constructor-injected repo) + UserError hierarchy
187
+ ├── infrastructure/ # SQLAlchemy adapter for the repository port
188
+ │ └── user_repository.py
189
+ ├── api/ # FastAPI layer: SessionDep + router, maps exceptions to HTTP
190
+ │ └── router.py # APIRouter (prefix="/users")
191
+ └── tests/ # in-memory SQLite test DB + get_session override
192
+ ├── conftest.py
193
+ └── test_user.py
194
+ ```
195
+
196
+ Routers are **auto-mounted**: `fastgen make module` idempotently syncs `main.py`
197
+ to import registered modules from the registry and `app.include_router(...)` each —
198
+ no hand-editing `main.py` when adding a module (guarded by a `fastgen: auto-mount` marker).
199
+
200
+ `fastgen make module` scaffolds the full vertical-slice skeleton above; every layer
201
+ already wires the shared session dependency, so you just add endpoints and business
202
+ logic. The generated `router.py` looks like:
203
+
204
+ ```python
205
+ from typing import Annotated
206
+
207
+ from fastapi import APIRouter, Depends, HTTPException
208
+ from sqlalchemy.ext.asyncio import AsyncSession
209
+
210
+ from src.core.database import get_session
211
+ from src.modules.user.application.user_service import UserNotFound, UserService
212
+ from src.modules.user.domain.model import User
213
+ from src.modules.user.infrastructure.user_repository import SqlUserRepository
214
+
215
+ SessionDep = Annotated[AsyncSession, Depends(get_session)]
216
+
217
+ router = APIRouter(prefix="/users", tags=["users"])
218
+
219
+
220
+ def _service(session: AsyncSession) -> UserService:
221
+ return UserService.from_repository(SqlUserRepository(session))
222
+
223
+
224
+ @router.get("", response_model=list[User])
225
+ async def list_users(session: SessionDep) -> list[User]:
226
+ ...
227
+ ```
228
+
229
+ ---
230
+
231
+ ## 🔁 Migrations (Alembic)
232
+
233
+ `fastgen new` ships Alembic scaffolding (`alembic.ini` + `migrations/`) wired to your
234
+ settings and models — schema is managed by migrations, not `create_all` at startup, so
235
+ you evolve the dev DB instead of deleting `app.db`.
236
+
237
+ ```bash
238
+ uv run alembic upgrade head # apply all pending migrations (baseline included)
239
+ uv run alembic revision --autogenerate -m "add user email" # diff models -> new migration
240
+ uv run alembic upgrade head # apply it
241
+ uv run alembic downgrade -1 # roll back one step
242
+ ```
243
+
244
+ - `migrations/env.py` imports every registered module's `model` so autogenerate sees all tables.
245
+ - Adding Alembic to an **existing** project: `fastgen init alembic` writes the scaffolding
246
+ idempotently (never overwrites). If the DB was already created via `create_all`, adopt it
247
+ with `uv run alembic stamp head`, or drop the dev DB and re-create via `upgrade head`.
248
+
249
+ ---
250
+
251
+ ## ⚖️ How does it compare?
252
+
253
+ ### vs. other FastAPI module generators & frameworks
254
+
255
+ | Tool | What it is | Runtime dependency you must keep | Generated module |
256
+ | --- | --- | --- | --- |
257
+ | **fastgen-cli** | Generator only — plain FastAPI (Rust CLI) | None | Model / schemas / service / router + tests + auto-maintained registry; Alembic migrations |
258
+ | **PyNest** | Framework on FastAPI (NestJS-style) | `pynest-api` (`nest.core`) | Module with `@Module` / `@Controller` / `@Injectable`, DI container |
259
+ | **FastKit** | Meta-framework + CLI (Laravel-style) | `fastkit-core` | Full CRUD module (model / schema / repository / service / router) |
260
+ | **Gondola** | CLI with Rails-like conventions | `gondola-cli` + default PostgreSQL stack | Models / routers / services / mailers / tests, Alembic migrations |
261
+ | **FastStack** | Full framework (Django-like) | `faststack-frame` | App module (models / routes / schemas / services / admin) |
262
+ | **RapidKit** | Module engine + CLI (FastAPI & NestJS) | `rapidkit-core` + npx/poetry toolchain | Kits (`fastapi.standard` / `fastapi.ddd`) + installable module catalog |
263
+
264
+ #### Where fastgen stands out
265
+
266
+ - **Zero runtime lock-in.** Everything fastgen generates is plain Python on top of vanilla FastAPI + SQLAlchemy — nothing requires `fastgen` at runtime. The others all ship their own framework/runtime that your project keeps depending on.
267
+ - **No new concepts to learn.** No `@Module`/`@Injectable` decorators, no DI container, no repository base classes, no workspace metadata. The skeleton uses idioms you already know (`SessionDep = Annotated[AsyncSession, Depends(get_session)]`).
268
+ - **Incremental, not all-or-nothing.** `fastgen make module` grows an *existing* project (`src/` or `app/` layout) instead of forcing you to start inside a framework — you can adopt it on top of any FastAPI project, including the ones above.
269
+ - **AI/agent-friendly.** An auto-maintained registry (`src/modules/__init__.py`) plus `fastgen list` means both humans and AI agents see the whole module structure at a glance.
270
+ - **Never overwrites.** `src/core/` is only generated when missing or empty.
271
+
272
+ #### Honest trade-off
273
+
274
+ The others generate **more for you**: FastKit's full CRUD router, Gondola's mailers, PyNest's dependency injection for complex enterprise apps, RapidKit's module upgrade/rollback lifecycle. Choose them when you want those batteries and can accept their runtime and conventions. Choose fastgen when you want a lean, standard, zero-coupling base that you shape yourself.
275
+
276
+ > **Contract-first generators** (`fastapi-code-generator`, OpenAPI Generator `python-fastapi`) are a different category: they turn an OpenAPI spec into code and complement fastgen when your spec is the source of truth.
277
+
278
+ ### vs. starting with `uv init`
279
+
280
+ `uv init my-app` is the natural baseline — minimal, universal, no lock-in. The trade-offs:
281
+
282
+ | | `uv init` | `fastgen new` |
283
+ | --- | --- | --- |
284
+ | What you get | `pyproject.toml` + `main.py` hello world | Complete FastAPI app: `.env`, `src/main.py` (lifespan + `/health`), `src/core/` (pydantic-settings + async SQLAlchemy), module registry, `tests/`, Alembic migrations, ruff/pytest config |
285
+ | Then you must | Add deps, build the `src/` layout, write lifespan/config/DB/tests by hand | Add your business logic |
286
+ | Resulting structure | Differs per developer | Identical across projects |
287
+ | Module management later | None | `fastgen make module` keeps a registry you can `fastgen list` |
288
+ | Lock-in | None | Layout is plain files; drop fastgen anytime, nothing generated forces it |
289
+
290
+ **Pros of `uv init`**: universal, minimal, zero opinion, and you already have `uv` installed.
291
+ **Cons**: every FastAPI-specific decision (layout, DB session wiring, config, tests) is left to you, so each project ends up structured differently.
292
+
293
+ **Pros of `fastgen new`**: one command yields a complete best-practice base; consistent across the whole org; modules stay discoverable via the registry; never overwrites your code; easy for AI agents to reason about.
294
+ **Cons**: opinionated layout (`src/` + `core/` + registry) — if you need a non-standard structure you adapt it yourself; FastAPI-only.
295
+
296
+ **They're complementary, not competing**: a `fastgen new` project is still managed by `uv` (`uv sync`, `uv run`). And if you *did* start from `uv init`, you can adopt fastgen later — run `fastgen make module <feature>` in the project and it creates `core/`, `modules/` and the registry for you (it auto-detects the layout).
297
+
298
+ ---
299
+
300
+ ## 🛠️ CLI reference
301
+
302
+ | Command | Description |
303
+ | --- | --- |
304
+ | `fastgen new <name>` | Scaffold a new best-practice `src/`-layout FastAPI project (core + registry + tests + Alembic) |
305
+ | `fastgen make module <feature>` | Scaffold a feature module (model / schemas / service / router / tests), auto-mount its router, register it |
306
+ | `fastgen init alembic` | Add Alembic migration scaffolding to an existing project (idempotent) |
307
+ | `fastgen list` | List registered modules, import paths, and purposes |
308
+ | `fastgen --version` / `-V` | Show version |
309
+
310
+ ### Options
311
+
312
+ | Flag | Applies to | Description |
313
+ | --- | --- | --- |
314
+ | `--dir <path>` / `-d` | `new`, `make module`, `init alembic`, `list` | Target project root (default: current dir) |
315
+ | `--title <name>` | `new` | Human-readable app title (defaults to the project name) |
316
+ | `--description <text>` | `new` | Short project description |
317
+ | `--dry-run` | `new`, `make module`, `init alembic` | Preview files without writing anything |
318
+ | `--force` / `-f` | `new`, `make module` | Overwrite existing files |
319
+
320
+ ---
321
+
322
+ ## 📐 Conventions (fixed)
323
+
324
+ - **Layout** — `fastgen new` creates a `src/` layout and records it in `.fastgen.json`. `fastgen` resolves `src` from `.fastgen.json`, then by auto-detection, and finally falls back to `app/` for existing projects.
325
+ - **Modules** live in `<src>/modules/<feature>/` — one business unit per folder, scaffolded as a **vertical slice**: `domain/` (`model.py` + `repository.py` port), `application/` (`schemas.py` `XBase`/`XCreate`/`XUpdate`/`XRead` with `from_attributes` on `XRead`, plus `<feature>_service.py`), `infrastructure/` (`Sql*Repository`), `api/` (`router.py`), and `tests/`.
326
+ - **Router** exposes `prefix="/<plural>"` (REST-style), reuses `SessionDep` from `<src>.core.database`, is **auto-mounted** into `main.py` from the registry (guarded by a `fastgen: auto-mount` marker — don't remove it), and maps domain exceptions to `HTTPException`.
327
+ - **Registry** — `<src>/modules/__init__.py` maps module name → import path. Always kept in sync by fastgen; don't hand-edit.
328
+ - **Core** — `<src>/core/config.py` and `database.py` are generated only when **missing or empty**. Existing code is never touched, even with `--force`.
329
+ - **Schema** — managed by Alembic migrations (not `create_all` at startup).
330
+
331
+ ---
332
+
333
+ ## 🔭 Roadmap
334
+
335
+ - [x] `new` — scaffold a whole best-practice `src/`-layout project
336
+ - [x] `make module` — model / schemas / service / router / tests + auto-mount
337
+ - [x] Module registry + `fastgen list`
338
+ - [x] Alembic migrations (`init alembic`, autogenerate, upgrade)
339
+ - [ ] `make resource` — full CRUD router generation
340
+
341
+ ---
342
+
343
+ ## 🧑‍💻 Development
344
+
345
+ ```bash
346
+ git clone https://github.com/YIbaikaishui/fastgen-cli.git
347
+ cd fastgen-cli
348
+ cargo build --release
349
+ cargo test
350
+ ```
351
+
352
+ Lint / format: `cargo clippy --all-targets` and `cargo fmt --check`.
353
+
354
+ ---
355
+
356
+ ## 📄 License
357
+
358
+ MIT © 一白开水
359
+
@@ -0,0 +1,6 @@
1
+ fastgen_cli-0.7.0.data/scripts/fastgen.exe,sha256=6c7aBkM7fGtfmQk3T3dURRWyIjQGQq-s2t3ZKEcY1YY,3758080
2
+ fastgen_cli-0.7.0.dist-info/METADATA,sha256=UGgy5FZyQ5Lqbba8Hq9Pe4nM1DW1YeY-hRFDJ_ZUmEY,19443
3
+ fastgen_cli-0.7.0.dist-info/WHEEL,sha256=8Aej0W0a6Cz6apA3IzJrTnxLRVLAt-w0Oh8SA3Con_c,94
4
+ fastgen_cli-0.7.0.dist-info/licenses/LICENSE,sha256=xNr_TN-E0pRcd6aNdgRKrXVdDLHYYAzLD_3JN2pDWpI,1069
5
+ fastgen_cli-0.7.0.dist-info/sboms/fastgen-cli.cyclonedx.json,sha256=1jQPQo6SgfPwkNB6KnNVfvgy34NaXaygMJvy3CdocZU,54979
6
+ fastgen_cli-0.7.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.15.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 一白开水
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.