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
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f
- New `init` options: `--level`, `--database`, `--feature AXIS=VALUE`, `--extra-package`, `--template`, `--in-place`, and `--name` for `--project-name`. `--database` matches its choices in any case.
- Author and email default to `git config user.name` / `user.email`, and the package manager to uv when it is installed, otherwise pip. An empty author is left out of `pyproject.toml` for every package manager (Poetry also leaves out an email without a name).
- `--save-config` works for every `init` run except `--dry-run` and records the level or template; `project_name` is the only required config key, a config can name a `level` or a `template`, and `--project-name`, `--author`, `--author-email` and `--description` override the file's values.
- A config file may set `version` (a PEP 440 version such as `1.2.0`, quoted in YAML) to give the generated project that version instead of `0.1.0`; an invalid value is reported and nothing is written.
- A prompt that gets 10 invalid answers, or whose input ends, exits with status 1. `startdemo -y` also skips the creation prompt, and `runserver` rejects an invalid `app_module` in `[tool.fastapi-fastkit]`.
- `init --template` and `startdemo` check the template name before they ask anything, suggest close matches and point to `fastkit list-templates`; the internal template path is shown only with `--debug`.
- After `init` or `startdemo` creates a project, fastkit prints a "Next steps" panel with the commands that apply to that run (project folder, environment, reviewing `.env`, database, server, tests, `addroute`, the next level), and puts the same list in the project's `README.md`. The old "To start your project" line is gone.
- `runserver` in a project without `.venv` prints the commands that create it for the project's package manager (for PDM, ones that keep the `.venv` inside the project) before offering to continue. If you continue, it runs the uvicorn of the Python that runs fastkit and exits with a clear message if that Python has none.
- `addroute` on a real single-file project such as `fastapi-hello` explains how to extend it by hand instead of adding packages. Projects that keep `main.py` at the root with their code in packages are handled as before.
- `doctor` passed checks say only what was verified, with no severity, and checks that do not apply to a project (secrets, settings, `.gitattributes`) are skipped. JSON output is unchanged.
Expand All @@ -69,9 +71,15 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f
- **Session-based:** logout invalidates the session, sessions have an absolute lifetime (`SESSION_ABSOLUTE_MAX_AGE`), and the demo account needs `ENABLE_DEMO_USERS=true` (refused outside development). **OAuth2** requires `OAUTH_REDIRECT_BASE_URL` outside development.
- **Rate-Limiting** applies `RATE_LIMIT_DEFAULT` to every route and the stricter `RATE_LIMIT_AUTH` to the auth endpoints, using `limits` instead of slowapi.
- **MongoDB** uses PyMongo's async client instead of Motor. The SQL session dependency no longer commits; services commit.
- The `layered`, `domain` and `production` levels (presets `classic-layered` and `domain-starter`) wire every selected feature into the template's `main.py`.
- The `single-file`, `layered`, `domain` and `production` levels (presets `single-module`, `classic-layered` and `domain-starter`) wire every selected feature into the template's `main.py`.
- **`single-file`** keeps its `src/main.py` when you add features. When a generated module reads the settings (database, authentication, tasks, cache, rate limiting, logging, telemetry), the settings move from `src/main.py` to `src/core/config.py` and the summary says so; with tooling-only selections `src/main.py` is unchanged.
- **Docker Compose with Alembic:** the generated compose file migrates the database in a one-shot step before the app (and worker) start, so `docker compose up --build` gives a working API with its tables. With SQLite and Docker Compose the database file is kept in a volume.
- **Selected features** each get a section in the project's `README.md` with the files and settings they add and a link to the FastAPI documentation.
- **Example `/items` with a database:** at the `layered`, `domain` and `production` levels with PostgreSQL, MySQL or SQLite, the example `/items` API stores its items in that database, and its tests run on in-memory SQLite; with MongoDB or Redis the items stay in their existing store and the README says so. `addroute` in such a project still adds an in-memory resource and prints a note that points to the database-backed items example.
- **Dependency versions:** a project generated from a feature selection keeps the minimum versions its template sets (for example `fastapi>=0.141.1`); a version you pin for the same package wins. Projects with PostgreSQL or MySQL list `aiosqlite` among the dev dependencies, because their tests run on in-memory SQLite, and MySQL projects install `aiomysql[rsa]`, which MySQL 8's default authentication needs.
- 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.
- **Docker Compose:** the containers always reach the compose database at its service name (a `DATABASE_URL` or `MONGODB_URL` in `.env` or the shell no longer redirects them), and the app, `migrate` and worker services share one image built once.
- **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.

Expand All @@ -85,6 +93,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`.
- Generated code carries short comments that explain a FastAPI concept at its first use, each ending with a link to the matching FastAPI documentation page; a concept is explained once per project.
- Every template ships a `requirements-dev.txt` for test and lint tools and keeps them out of `requirements.txt`, so the Docker images of `fastapi-sqlmodel`, `fastapi-auth-jwt` and `fastapi-llm-agent` no longer contain them.
- Every template except `fastapi-hello` ships the ruff configuration that `init`'s ruff option writes. `fastapi-single-module` projects pass isort and `mypy src`, and `fastapi-custom-response` uses Python 3.12 generic syntax for its response envelope.

Expand All @@ -104,7 +113,8 @@ Upgrading fastkit does not change an existing project. Run `fastkit doctor` in i
5. **Saved `--config` files** keep working: the CORS and Pagination options are accepted, and a `minimal` preset (or none) creates a `fastapi-single-module` project.
6. **Scripts that pipe answers into `fastkit init`** (or use `--interactive`) need options instead: `fastkit init --project-name api --level layered --database SQLite -y`, or `--config`.
7. **`startdemo` scripts** keep working. To switch, use `fastkit init --template <name> --project-name <name>`; `init` does not ask for author, email or description, so pass `--author`, `--author-email` and `--description`, or let git config fill author and email.
8. **The old stacks** added packages without code. The closest replacements are `--level single-file` for `minimal`, and a level with `--database` and `--feature migrations=Alembic` or `--feature async_tasks=Celery` for `standard` and `full`, which generate the code for those packages.
8. **`single-file` projects generated with features** now keep the template's `/health`, so in the OpenAPI schema its operation id is `health_health_get` and its summary is "Health" instead of `health_check_health_get` and "Health Check"; regenerate API clients that use operation ids. `tests/test_main.py` is the template's own.
9. **The old stacks** added packages without code. The closest replacements are `--level single-file` for `minimal`, and a level with `--database` and `--feature migrations=Alembic` or `--feature async_tasks=Celery` for `standard` and `full`, which generate the code for those packages.

## v1.5.2 (2026-12-01)

Expand Down
43 changes: 34 additions & 9 deletions docs/de/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,25 @@ Installing dependencies...
╭─────────────────────── Success ───────────────────────╮
│ ✨ Dependencies installed successfully │
╰───────────────────────────────────────────────────────╯
╭─────────────────────── Success ───────────────────────╮
│ ✨ FastAPI project 'my-awesome-project' has been │
│ created successfully and saved to │
│ ~your-project-path~! │
╰───────────────────────────────────────────────────────╯
╭──────────────────────── Info ────────────────────────╮
│ ℹ To start your project, run 'fastkit runserver' at │
│ newly created FastAPI project directory │
╰──────────────────────────────────────────────────────╯
╭──────────────────────────────── Success ─────────────────────────────────╮
│ ✨ FastAPI project 'my-awesome-project' from 'fastapi-hello' has been │
│ created and saved to ~your-project-path~! │
╰──────────────────────────────────────────────────────────────────────────╯
╭───────────────────────────────── Next steps ─────────────────────────────────╮
│ 1. Go to the project folder. │
│ cd my-awesome-project │
│ 2. Start the development server and open http://127.0.0.1:8000/docs. │
│ fastkit runserver │
│ 3. Run the tests. │
│ uv run pytest │
│ 4. Add a resource by imitation: copy the `Item` models, `create_item`, │
│ `read_item` and their tests, and rename them for `/users`. │
│ 5. Read `main.py` from top to bottom: each comment links the FastAPI │
│ tutorial page that explains it. │
│ 6. When you want more structure, create a project at the next level. │
│ fastkit init --level single-file │
│ README.md lists the steps for a fresh checkout of the project. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

</div>
Expand Down Expand Up @@ -442,6 +452,7 @@ Legen Sie sofort ein strukturiertes FastAPI-Demoprojekt an mit:

```console
$ fastkit startdemo
Note: 'fastkit startdemo' is now 'fastkit init --template fastapi-default'. startdemo keeps working.
Enter the project name: my-awesome-demo
Enter the author name: John Doe
Enter the author email: john@example.com
Expand Down Expand Up @@ -490,6 +501,20 @@ FastAPI template project will deploy at '~your-project-path~'
│ 'fastapi-default' has been created and saved to │
│ ~your-project-path~! │
╰───────────────────────────────────────────────────────╯
╭───────────────────────────────── Next steps ─────────────────────────────────╮
│ 1. Go to the project folder. │
│ cd my-awesome-demo │
│ 2. Review .env: fastkit wrote it from .env.example with a unique SECRET_KEY. │
│ 3. Start the development server and open http://127.0.0.1:8000/docs. │
│ fastkit runserver │
│ 4. Run the tests. │
│ uv run pytest │
│ 5. Add a resource with its route, schemas, data layer and tests. │
│ fastkit addroute orders │
│ 6. Read `src/main.py`, then `src/api/routes/items.py`, `src/crud/items.py` │
│ and `src/schemas/items.py`. │
│ README.md lists the steps for a fresh checkout of the project. │
╰──────────────────────────────────────────────────────────────────────────────╯
```

</div>
Expand Down
31 changes: 15 additions & 16 deletions docs/en/contributing/development-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,31 +230,30 @@ $ python scripts/inspect-templates.py --templates fastapi-sqlmodel --offline --n

### Generated code lives in Jinja2 fragments

Everything `fastkit init` writes into a project — `main.py`,
database and auth modules, Docker files, pytest configuration — is rendered
from templates under `src/fastapi_fastkit/fragments/`, not assembled from
strings in Python. `main.py.j2` hard-codes no feature: it iterates over the
`import_fragments`, `lifespan_fragments` and `setup_fragments` lists supplied
by `DynamicConfigGenerator` and includes each one, so features compose
freely.
Everything `fastkit init` writes into a project (database and auth modules,
Docker files, pytest configuration, the SQL-backed example `/items` in
`fragments/items_sql/` and `fragments/items_sql_classic/`) is rendered from templates under
`src/fastapi_fastkit/fragments/`, not assembled from strings in Python. No
`main.py` is generated: every level keeps its template's `main.py`, and
fastkit wires each selected feature into it at the `# fastkit:imports` /
`# fastkit:routes` anchors, so features compose freely.

Adding a feature is roughly:

1. Drop the pieces into `main/imports/`, `main/lifespan/` and/or
`main/setup/` (lifespan fragments are indented by four spaces; the other
two are not).
2. Register them in `DynamicConfigGenerator._main_fragments()`, guarded by
the relevant config lookup.
3. For a standalone module, add `<area>/<feature>.py.j2` and render it with
`self._render(...)`.
1. Add the option to `catalog/catalog.toml`.
2. For a standalone module, add `<area>/<feature>.py.j2` and return it from
the generator, keyed by its project-relative path.
3. Add an `OverlayTarget` in `preset_layout.py` with the import and the
module-level lines that mount the feature in `main.py`.
4. Extend the combination matrix in
`tests/test_backends/test_project_builder_config_generator.py` — it
asserts every rendered Python file parses with `ast.parse`.

Two constraints that are easy to trip over: every fragment must end with a
trailing newline (the environment is built with `keep_trailing_newline=True`),
and `main.py.j2` must keep its `# fastkit:imports` / `# fastkit:routes`
anchors — `fastkit addroute` inserts at them.
and a template's `main.py` must keep its `# fastkit:imports` /
`# fastkit:routes` anchors, because `fastkit init` and `fastkit addroute`
insert 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).
Expand Down
Loading
Loading