Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/template-security-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,20 @@ jobs:
fi

req_file="$template_dir/requirements.txt-tpl"
dev_req_file="$template_dir/requirements-dev.txt-tpl"
if [ -f "$req_file" ]; then
echo "🔍 Scanning $template_name..."

# Create temp requirements file
# One temp requirements file with the runtime pins and, when the
# template splits them out, the dev pins. The dev file's
# "-r requirements.txt" line is dropped: the runtime pins are
# already in the file and the include would not resolve here.
temp_req=$(mktemp)
cp "$req_file" "$temp_req"
if [ -f "$dev_req_file" ]; then
printf '\n' >> "$temp_req"
grep -v -E '^[[:space:]]*-r[[:space:]]' "$dev_req_file" >> "$temp_req" || true
fi

audit_file="$TEMP_DIR/${template_name}.json"
err_file="$TEMP_DIR/${template_name}.err"
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f
- Projects created with Poetry now get a working virtual environment and install with `poetry install`; fastkit sets `package-mode = false` so Poetry installs the dependencies without packaging the application. Poetry 2 or later is required: with an older Poetry, fastkit stops before creating anything, reports the version it found and explains how to upgrade or choose another package manager.
- Projects created with PDM now get their `.venv` inside the project even when PDM is configured with `venv.in_project = false`, and `fastapi-hello` installs with PDM without being built as a package.
- `list-templates` lists templates from the simplest to the most involved, in the same order on every operating system. `fastkit --help` has a one-sentence description and a "Start here" section.
- `startdemo` shows the template's runtime dependencies in its dependency table and `--dry-run` list, without comment lines or test tools, and the `--dry-run` file list matches the files that are written. Shell scripts in generated projects (`scripts/*.sh`) are executable.
- With `--no-venv`, `init` output no longer depends on which package managers are installed. If the requested package manager is not installed and an environment is being created, fastkit prints a warning and sets the project up for an available one; the project's metadata records the one actually used.
- `addroute` sorts generated and inserted imports the way isort (black profile) does, for any route name, including names that differ only by a number, and wraps an over-long inserted import.
- `startdemo` and `init` refuse to write through a symbolic link in the target directory and list the links before writing anything.
- When `startdemo` or `init` fails or is interrupted after overwriting files in an existing directory, those files get their original content back and the files the run created are removed; a file that cannot be restored keeps its original copy in a backup directory whose path is printed. An existing `.env` is kept even when a custom template ships one.
- `addroute` no longer treats a router registration or import under `if TYPE_CHECKING:` or `if False:` as present, and inserts imports below `from __future__` imports when the import anchor sits above them.

### `fastkit init` options

Expand All @@ -60,6 +66,8 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f
- `classic-layered` and `domain-starter` wire every selected feature into the template's `main.py`.
- Generated tests run against in-memory SQLite and do not export telemetry.
- **Docker:** the image runs as a non-root user and has a healthcheck, `.dockerignore` is generated, compose points the app at its services, and `.env` is supplied at run time instead of copied into the image. **Loguru** is now configured at startup.
- **Dev tools:** test and lint tools (pytest and its plugins, ruff, pre-commit) stay out of runtime dependencies. They go to the dev dependency group and to a new `requirements-dev.txt` that includes `requirements.txt`. Generated Dockerfiles install runtime dependencies only; the Makefile, GitHub Actions workflow and devcontainer install `requirements-dev.txt`.
- **ruff:** projects created with the ruff option pass their own `ruff check`; generic classes use the Python 3.12 type parameter syntax.

### Templates

Expand All @@ -71,6 +79,7 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f
- `fastapi-llm-agent`: the SSE stream is declared in OpenAPI, the calculator tool and the conversation store are bounded (`MAX_CONVERSATIONS`, `MAX_MESSAGES_PER_CONVERSATION`), and there are hook points for authentication and rate limiting.
- Templates that store items in a JSON file no longer reuse ids, write atomically, and their tests no longer overwrite the shipped data.
- Unused dependencies and `setup.cfg` files are removed. Template Dockerfiles run as a non-root user and ship a `.dockerignore`.
- `fastapi-sqlmodel`, `fastapi-auth-jwt` and `fastapi-llm-agent` ship a `requirements-dev.txt` for test and lint tools, and their Docker images no longer contain them.

### Documentation

Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ recursive-exclude src/fastapi_fastkit/fastapi_project_template *.pyo
recursive-exclude src/fastapi_fastkit/fastapi_project_template __pycache__
recursive-include src/fastapi_fastkit/fragments *
recursive-exclude src/fastapi_fastkit/fragments __pycache__
recursive-include src/fastapi_fastkit/catalog *.toml
recursive-include src/fastapi_fastkit/catalog/i18n *
recursive-exclude src/fastapi_fastkit/catalog __pycache__
17 changes: 17 additions & 0 deletions docs/en/contributing/development-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ anchors — `fastkit addroute` inserts at them.
The authoritative procedure lives next to the fragments themselves, in
[`src/fastapi_fastkit/fragments/README.md`](https://github.com/bnbong/FastAPI-fastkit/blob/main/src/fastapi_fastkit/fragments/README.md).

### Options live in one catalog

The options `fastkit init` offers, their dependencies and the rules that
limit combinations come from `src/fastapi_fastkit/catalog/catalog.toml`. To
add an option:

1. Add it to its axis in `catalog.toml` (`[[axes.options]]`, with its
packages and tags), and to the matching `*Choice` enum in
`src/fastapi_fastkit/core/settings.py`. The enum and the catalog list the
same options in the same order.
2. Teach `DynamicConfigGenerator` to generate it (see the fragments above).
3. Run `tests/test_catalog/test_agreement.py`; it fails when the enums,
the catalog and the generator disagree.

Project generation is also available as a function without prompts or
subprocesses: `fastapi_fastkit.generation.generate(spec, target_dir)`.

### Documentation Commands

| Command | Description |
Expand Down
40 changes: 39 additions & 1 deletion docs/en/contributing/template-creation-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,35 @@ copy.
project. The CLI is a development tool; a template's dependency list should
contain only what the generated application itself imports.

### Register the Template in the Catalog

A template directory is not enough. Add a `[[templates]]` entry to
`src/fastapi_fastkit/catalog/catalog.toml`, in the position where the
template should appear in `fastkit list-templates` (the file's order is the
display order):

```toml
[[templates]]
id = "fastapi-your-template"
kind = "example"
description = "Your Template Title"
concepts = ["dependencies", "settings"]
```

- `id` is the template directory name. The entries and the directories under
`fastapi_project_template/` must be the same set.
- `description` must equal the first heading of `README.md-tpl` without the
`# `: with `# Your Template Title` on its first line, the description is
`Your Template Title`.
- `kind` is `level`, `example` or `internal`; new example projects use
`example`.
- `concepts` lists ids of the `[[concepts]]` entries in the same file; use
`[]` if none apply.

`tests/test_catalog/test_agreement.py` fails when an entry and its directory
or README heading disagree, and the catalog loader rejects unknown keys or
concepts.

### File Writing Guide

#### 1. Writing main.py-tpl
Expand Down Expand Up @@ -283,7 +312,10 @@ build-backend = "hatchling.build"
#### 3. Writing requirements.txt-tpl (optional)

Optional when `pyproject.toml-tpl` declares `[project].dependencies`. Still
useful for templates that prefer `pip`-only workflows.
useful for templates that prefer `pip`-only workflows. It lists runtime
dependencies only, because the Dockerfile installs it. Test and lint tools go
in `requirements-dev.txt-tpl`, which starts with `-r requirements.txt`, and
in the dev dependency group of `pyproject.toml-tpl`.

Packages that do not install on every platform need an environment marker.
`uvloop` does not support Windows, so templates pin it as
Expand All @@ -305,6 +337,12 @@ python-dotenv==1.0.0
sqlalchemy==2.0.23
alembic==1.13.0

```

```txt
# requirements-dev.txt-tpl
-r requirements.txt

# Development tools
pytest==7.4.3
pytest-asyncio==0.21.1
Expand Down
12 changes: 12 additions & 0 deletions docs/en/reference/translation-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ behaviour, the `doctor` output, and the `fastapi-hello` answer in
`user-guide/choosing-a-starter`. Translated pages that describe these still
show the earlier behaviour; follow the English pages.

**English pages changed for the development-dependency split (not yet
translated).** `fastkit init` projects and the `fastapi-sqlmodel`,
`fastapi-auth-jwt` and `fastapi-llm-agent` templates keep test and lint tools
out of `requirements.txt` and ship `requirements-dev.txt`. This is described
in the English pages only: `user-guide/cli-reference` (also the `testing`
default, `startdemo`, package manager fallback and `addroute` import order),
`user-guide/creating-projects`, `user-guide/quick-start`, `tutorial/sqlmodel`,
`tutorial/auth-jwt`, `tutorial/llm-agent`, `contributing/template-creation-guide`
(catalog entry for a new template) and `contributing/development-setup`
(adding an option). Translated pages still show the earlier behaviour; follow
the English pages.

*Snapshot verified 2026-10-14, after the v1.5.0 release. All six translated
locales were brought to parity with the English sources: the three tutorials
added in v1.4.0 were translated and every page that had drifted since its
Expand Down
5 changes: 4 additions & 1 deletion docs/en/tutorial/auth-jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ startup, so there is nothing to install or configure first. Docs are at
```
accounts-api/
├── pyproject.toml # PEP 621 metadata + [tool.fastapi-fastkit]
├── requirements.txt
├── requirements.txt # runtime dependencies (the Docker image installs these)
├── requirements-dev.txt # + test and lint tools
├── alembic.ini
├── Dockerfile
├── .env # SECRET_KEY, DATABASE_URL, token lifetimes (git-ignored)
Expand Down Expand Up @@ -320,6 +321,8 @@ comma-separated list of front-end origins.
$ bash scripts/test.sh # or: pytest
```

The test and lint tools are in `requirements-dev.txt` (and the dev dependency group), so install that file with pip. The Docker image installs `requirements.txt` only.

The suite runs `httpx.AsyncClient` against an in-memory SQLite database
and covers the whole happy path — register → login → me → refresh →
logout — plus the rejection paths that actually matter: wrong password,
Expand Down
5 changes: 4 additions & 1 deletion docs/en/tutorial/llm-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ $ bash scripts/chat.sh "What is 12 * 34?"
```
support-agent/
├── pyproject.toml # PEP 621 metadata + [tool.fastapi-fastkit]
├── requirements.txt
├── requirements.txt # runtime dependencies (the Docker image installs these)
├── requirements-dev.txt # + test and lint tools
├── Dockerfile
├── .env # local settings, git-ignored
├── .env.example # shareable copy with placeholder values
Expand Down Expand Up @@ -227,6 +228,8 @@ the concrete class.
$ bash scripts/test.sh # or: pytest
```

The test and lint tools are in `requirements-dev.txt` (and the dev dependency group), so install that file with pip. The Docker image installs `requirements.txt` only.

`tests/conftest.py` replays scripted turns through a fake that mimics
`AsyncAnthropic.messages.stream`. So the suite is deterministic, runs
offline, costs nothing, and still covers the paths that matter: the
Expand Down
5 changes: 4 additions & 1 deletion docs/en/tutorial/sqlmodel.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ no database server to install. Docs are at <http://127.0.0.1:8000/docs>.
```
catalog-api/
├── pyproject.toml # PEP 621 metadata + [tool.fastapi-fastkit]
├── requirements.txt
├── requirements.txt # runtime dependencies (the Docker image installs these)
├── requirements-dev.txt # + test and lint tools
├── alembic.ini
├── Dockerfile
├── docker-compose.yml # local PostgreSQL / MySQL (profiles)
Expand Down Expand Up @@ -305,6 +306,8 @@ changes: `src/app/db/url.py` picks the async driver for the URL, and
$ bash scripts/test.sh # or: pytest
```

The test and lint tools are in `requirements-dev.txt` (and the dev dependency group), so install that file with pip. The Docker image installs `requirements.txt` only.

Each test runs against a fresh in-memory SQLite database: no migrations,
no fixture files, no cleanup between tests. To run them on PostgreSQL or
MySQL, set `TEST_DATABASE_URL` to the `app_test` database the compose file
Expand Down
37 changes: 28 additions & 9 deletions docs/en/user-guide/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ CI or a piped run), fastkit refuses to overwrite anything unless `--yes`
is given: `init` and `startdemo` exit with status 1 before writing any file. An existing `.env` is never overwritten (see
[Generated `.env` file](#generated-env-file)).

fastkit never writes through a symbolic link in the target directory. If a
file it would write is a symlink, or one of its parent directories is a
symlink that leads outside the target, it lists those paths and exits with
status 1 before writing any file. If generation or the environment setup
fails after the overwrite (or you press Ctrl+C), the overwritten files get
their original content back and the files and directories the run created
are removed. If a file cannot be restored, its original copy stays in a
backup directory whose path fastkit prints. An existing `.venv` is not
restored.

#### Generated `.env` file

Templates ship a shareable `.env.example`. fastkit creates the project's
Expand Down Expand Up @@ -290,9 +300,10 @@ The `init` command will prompt you for:

`fastkit init --interactive` walks a different, axis-based catalog instead
of the minimal/standard/full stack above (source of truth:
`FastkitConfig.PACKAGE_CATALOG` in `core/settings.py`, and
`DynamicConfigGenerator.build_artifacts()` for what each choice generates).
Every axis defaults to `None` (skip); `utilities` and `tooling` are
`catalog/catalog.toml`, and `DynamicConfigGenerator.build_artifacts()` for
what each choice generates).
In the prompts every axis is pre-selected as `None` (skip) except `testing`,
which is pre-selected as `Coverage`; `utilities` and `tooling` are
multi-select.

Every selection now generates real code, not just installed packages — see
Expand All @@ -315,6 +326,8 @@ warnings) differ.
| `logging` | structured, None | None (stdlib `logging` + `json` only) | `<pkg>/logging_config.py` (structured JSON logging + request-id middleware), wired into `main.py` |
| `deployment` (multi-select) | Docker, docker-compose | none | `Dockerfile` (non-root user, healthcheck on `/health`, `ENVIRONMENT=production`, no `.env` in the image), `.dockerignore`; docker-compose adds `docker-compose.yml` with the database / cache services, healthchecks and service URLs, reading `.env` at run time |

Test and lint tools (`pytest` and its plugins, `faker`, `factory-boy`, `ruff`, `pre-commit`) are development dependencies: they go to the dev dependency group and to `requirements-dev.txt` (which includes `requirements.txt`), not to the runtime dependencies. The generated `Dockerfile` installs `requirements.txt` only; the generated `Makefile`, GitHub Actions workflow and devcontainer install `requirements-dev.txt`.

CORS (off until `BACKEND_CORS_ORIGINS` is set) and pagination (`core/pagination.py`) are part of every project, so the menu does not offer them; saved configs that still list `CORS` or `Pagination` load and generate the same project.

Regardless of selection, every generated project serves `GET /health`
Expand Down Expand Up @@ -376,6 +389,7 @@ my-api/
├── tests/
├── scripts/
├── requirements.txt
├── requirements-dev.txt
├── setup.py
└── README.md
```
Expand Down Expand Up @@ -521,8 +535,9 @@ api_router.include_router(health.router)

Keep those comments in place when you edit the file. `addroute` registers
the router below `# fastkit:routes` and adds the import in sorted position
below `# fastkit:imports` (or in its isort section higher up), so ruff stays
clean. An import is skipped only when the same names are already imported.
below `# fastkit:imports` (or in its isort section higher up), in the order isort
(black profile) would sort it, so ruff stays clean; an import that would be too
long is wrapped. An import is skipped only when the same names are already imported.
A project that
lost them (or was generated before the anchors existed) still works: fastkit
falls back to an AST-based insertion that finds the import block and the
Expand Down Expand Up @@ -624,6 +639,8 @@ $ fastkit startdemo [OPTIONS]
| `--yes` / `-y` | Create the project without asking and, when deploying in place, overwrite existing files | off |
| `--help` | Show command help | - |

The dependency table and the `--dry-run` list show the template's runtime dependencies (no comments, no test tools), and the `--dry-run` file list matches the files that are written. Shell scripts in the generated `scripts/` directory are executable.

Like `init`, `startdemo` refuses to run when the target project directory
already exists (`Error: Project '{name}' already exists.`). `--dry-run` is
the exception: since it never writes to disk, it is still allowed to target
Expand Down Expand Up @@ -1019,7 +1036,7 @@ If virtual environment creation fails:
```console
$ python -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
$ pip install -r requirements-dev.txt
```
</div>

Expand Down Expand Up @@ -1174,7 +1191,9 @@ owns and keeps everything else, including the template's `requires-python`,
dependency groups, other `[tool.*]` tables and comments. If fastkit cannot
edit the file safely, it stops with an error; a `pyproject.toml` that is not
valid TOML is kept as `pyproject.toml.bak` and replaced. These projects
also get a `requirements.txt` with the same dependencies.
also get a `requirements.txt` with the same runtime dependencies and a `requirements-dev.txt` that includes it and adds the test and lint tools.

If the package manager you request is not installed and fastkit is creating an environment, `init` prints a warning and sets the project up for an available one; the `package_manager` in the project's `[tool.fastapi-fastkit]` block is the one actually used. With `--no-venv` the result does not depend on which package managers are installed.

Generated Poetry projects require Poetry 2 or later.

Expand Down Expand Up @@ -1254,7 +1273,7 @@ $ fastkit init --package-manager poetry

```console
$ fastkit init --package-manager pip
# Creates requirements.txt
# Creates requirements.txt and requirements-dev.txt
```

</div>
Expand Down Expand Up @@ -1292,7 +1311,7 @@ poetry run pytest # Run commands in environment
cd my-project
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install -r requirements.txt
pip install -r requirements-dev.txt
pip install requests
pytest
```
Expand Down
Loading
Loading