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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
87 changes: 87 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,92 @@
# Changelog

## v2.0.0

### Breaking changes

Every template except `fastapi-hello`, the code `fastkit init` generates for its options, and `fastkit addroute` output now share one HTTP contract:

| | v1.5.2 | v2.0.0 |
|---|---|---|
| Business routes | `/items` at the root in `fastapi-default` and `fastapi-custom-response`; `init` auth routes at `/auth/...` | Under `API_V1_PREFIX` (default `/api/v1`), e.g. `/api/v1/items`, `/api/v1/auth/...` |
| Liveness | `/api/v1/health` in `fastapi-domain-starter`, `fastapi-sqlmodel`, `fastapi-auth-jwt`, `fastapi-llm-agent`; elsewhere `/health` returning `{"status": "healthy"}` | `GET /health` at the root, always `{"status": "ok"}` |
| Readiness | none | `GET /ready` where a database or cache exists: 200 `{"status": "ok"}` or 503 `{"status": "unavailable"}` |
| List endpoints | Plain JSON array (`fastapi-mcp`: `page` / `page_size`) | `limit` (1-100, default 20) and `offset`; body `{"items", "total", "limit", "offset"}` |
| Create | 201 | 201 with a `Location` header |
| Delete | 200 with a message (most templates) | 204, empty body |
| Update | PUT applied partial updates in some templates | PUT replaces the resource; PATCH updates the fields sent |
| Not found | Varies | 404 `{"detail": "<Resource> not found"}` |
| Collection path | `/items/` in `fastapi-mcp` and `fastapi-custom-response` | `/items` (no trailing slash) |
| Schemas | `ItemResponse`, `ItemPublic` | `ItemCreate`, `ItemUpdate`, `ItemRead` |

Every 401 carries `WWW-Authenticate`, and each project reads its configuration from one settings module that loads `.env`.

- **Removed templates:** `fastapi-async-crud`, `fastapi-dockerized` and `fastapi-psql-orm` are gone, together with their tutorials. Projects generated from them keep working, and `fastkit doctor` still recognises their example secrets. Use `fastapi-sqlmodel` (async; SQLite, PostgreSQL or MySQL) or `fastapi-default` for new projects.
- **Secrets outside development:** every template and generated settings module now refuses to start with any `ENVIRONMENT` other than `development` (`staging` or `production`) and a missing, example, or shorter than 32-byte `SECRET_KEY`. In `development` an example key only warns.
- **`fastapi-mcp`:** `API_V1_STR` is renamed `API_V1_PREFIX`, and the OpenAPI schema moves to `/openapi.json`. `POST /api/v1/auth/login` is removed (use `POST /api/v1/auth/token`), `/auth/me` becomes `GET /api/v1/users/me`, and `/auth/users` becomes `GET /api/v1/users` (superusers only). `/mcp-routes/*` is replaced by `GET /api/v1/mcp-server`. Only the six item operations are MCP tools. Send the MCP key as `X-MCP-API-Key` (`Authorization: Bearer <MCP_API_KEY>` still works) so `Authorization` can carry a user token and write tools work in API-key mode.
- **`fastapi-auth-jwt`:** a rejected refresh token returns 400 `{"error": "invalid_grant"}` instead of 401; token responses add `expires_in`; `GET /api/v1/users` returns the page envelope.
- **`fastapi-sqlmodel`:** `ItemPublic` is renamed `ItemRead`.
- **`fastapi-llm-agent`:** the server generates conversation ids. Send `conversation_id` only to continue a conversation; an unknown id returns 404.
- **`fastapi-custom-response`:** errors, including validation errors and unhandled exceptions, use the response envelope; 500 responses no longer contain exception text.
- **`init` Session-based / OAuth2:** `GET /auth/me` moves to `GET /api/v1/users/me`, and logout returns 204.
- **`init` FastAPI-Users** needs PostgreSQL, MySQL or SQLite; other database choices are rejected.
- **`init` WebSocket:** the connection list moves from `/api/v1/ws/connections` to `/api/v1/connections`; `/ws` is unchanged.
- **CLI:** `startdemo` exits with status 1 when it refuses to run or fails, including an in-place overwrite without a terminal or `--yes`. `addroute` exits with status 1 on errors and refuses route names that are not lower-case ASCII. `deleteproject` exits with status 1 when the project does not exist, is not a fastkit project or cannot be deleted (declining the confirmation still exits 0). `runserver` in a project without `.venv` exits with status 1 unless you choose to continue with the current Python.
- **`init` utilities menu:** CORS and Pagination are no longer offered, because every project includes them; the menu is now 1 = Rate-Limiting, 2 = WebSocket. Saved configs that list them still load.

### CLI

- New `fastkit doctor [PATH]` checks a generated project for problems that newer templates fixed: a committed or unignored `.env`, a missing `.env.example`, example secrets, an MCP server without authentication, CORS `*` with credentials, Prometheus set up inside the lifespan, `sqlalchemy` without `greenlet`, CRLF scripts, a missing `.gitattributes`, an old `requires-python`, a pinned pre-commit Python, a commit after `yield`, `SlowAPIMiddleware`, Motor, the old pagination demo router and configuration read outside the settings module. It never prints secret values.
- `doctor --fix` shows the diff of the safe fixes and asks once (`--yes` skips the question and is required without a terminal); `--dry-run` / `--diff` only previews. `--format json` is for CI, and `--force` checks projects generated before 1.4.0. Exit status: 0 no problem left, 1 problems remain, 2 doctor could not run.
- `fastkit addroute` generates a typed CRUD resource with tests in both layouts (schemas, 201 with `Location`, 204, 404, paginated list) and adds `core/pagination.py` to older projects. The domain layout is chosen when the project has a `domains/` package. New options: `--entity` (class name), `--dry-run` (list files) and `--diff` (show changes). It refuses a route whose files already exist.
- `startdemo -y` also skips the creation prompt. `runserver` rejects an invalid `app_module` in `[tool.fastapi-fastkit]`.
- `startdemo` checks the template name before it asks anything, suggests close matches and points to `fastkit list-templates`; the internal template path is shown only with `--debug`.
- `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.
- `list-features` shows the utility and tooling options that `init` offers and lists CORS and pagination as built into every project.
- 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.

### `fastkit init` options

- **JWT** generates an OAuth2 password flow: `POST /api/v1/auth/register`, `POST /api/v1/auth/token` and `GET /api/v1/users/me`, with users stored in the selected SQL database or MongoDB (in memory otherwise).
- **FastAPI-Users** generates working routes (`/api/v1/auth/jwt/*`, `/api/v1/auth/register`, `/api/v1/users/*`) with tests.
- **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.
- **CORS and Pagination** are built into every project and no longer offered in the menu; `fastapi-pagination` is no longer installed.
- **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.
- `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.

### Templates

- New `fastapi-hello`: a single `main.py` and its tests, for people who have never written a FastAPI app. `POST /items` stores an item in memory and returns it with an id, and `GET /items/{item_id}` returns it or 404. It has no settings module and no secrets.
- `fastapi-sqlmodel` runs on SQLite, PostgreSQL or MySQL, selected by `DATABASE_URL`. Install the `postgresql` or `mysql` driver extra, start a local server with the new docker compose file, and use the migrations, which work on all three. A malformed `DATABASE_URL` is reported without echoing credentials.
- `fastapi-mcp`: item reads are public; PUT and PATCH work as specified.
- `fastapi-auth-jwt`: login, register and refresh are rate limited (`AUTH_RATE_LIMIT_*`); timestamps are timezone-aware (new migration); `GET /api/v1/users/{user_id}` (superusers only) is added.
- `fastapi-sqlmodel`: timestamps are timezone-aware (new migration) and PUT is added.
- `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`.

### Documentation

- The English docs cover the changes above, including a `fastkit doctor` section in the CLI reference and the conventions a new template must follow.
- The translated locales are not re-synced in this release; `reference/translation-status` lists the affected pages.

### Upgrade notes for existing projects

Upgrading fastkit does not change an existing project. Run `fastkit doctor` in it to see what can be checked and fixed automatically, then:

1. **Clients of a regenerated project:** apply the contract changes above (paths under `/api/v1`, `/health`, the list envelope, 204 on delete).
2. **Docker:** new images set `ENVIRONMENT=production` and do not contain `.env`; pass `SECRET_KEY` (at least 32 bytes) and the other settings at run time, e.g. `docker run --env-file .env ...`.
3. **`fastapi-auth-jwt` and `fastapi-sqlmodel` projects that adopt the new template code:** run `alembic upgrade head` for the new migration.
4. **Projects from the removed templates** need no change. To move to PostgreSQL or MySQL with `fastapi-sqlmodel`, set `DATABASE_URL` and install the matching driver extra.
5. **Saved `--config` files** with the CORS or Pagination option still work.

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

### Security
Expand Down
21 changes: 14 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,20 @@ When adding a new FastAPI template project, follow these guidelines:
template-name/
├── src/
│ ├── main.py-tpl
│ ├── config/
│ ├── models/
│ ├── routes/
│ └── utils/
│ ├── api/
│ ├── core/ # config.py-tpl, pagination.py-tpl, responses.py-tpl
│ ├── crud/
│ └── schemas/
├── tests/
├── scripts/
├── pyproject.toml-tpl
├── requirements.txt-tpl
├── README.md-tpl
├── .env.example-tpl
├── .gitattributes-tpl
└── .gitignore-tpl
├── .gitignore-tpl
├── Dockerfile-tpl # optional
└── .dockerignore-tpl # required with a Dockerfile
```

2. File Extensions:
Expand All @@ -258,11 +260,16 @@ template-name/
- `.gitignore-tpl` must ignore `.env` and `.env.*` and keep `!.env.example`

3. Dependencies:
- Declare dependencies in `pyproject.toml-tpl` (`requires-python = ">=3.12"`); no `setup.py-tpl`, no `FastAPI-fastkit` dependency
- Declare dependencies and tool settings in `pyproject.toml-tpl` (`requires-python = ">=3.12"`); no `setup.py-tpl` or `setup.cfg-tpl`, no `FastAPI-fastkit` dependency
- Specify version numbers in requirements.txt
- Use latest stable versions of dependencies

See [Template Creation Guide](docs/en/contributing/template-creation-guide.md) for the full rules.
4. API conventions:
- Business routes under `API_V1_PREFIX` (`/api/v1`), `GET /health` returning `{"status": "ok"}` at the root, paginated lists (`limit` / `offset`, `{"items", "total", "limit", "offset"}`), 201 with `Location`, 204 on delete, `XCreate` / `XUpdate` / `XRead` schemas
- `core/pagination.py-tpl` and `core/responses.py-tpl` identical to `fastapi_project_template/modules/core/`
- Every `ENVIRONMENT` except `development` (`staging`, `production`) refuses a missing, example, or shorter than 32-byte `SECRET_KEY`

See [Template Creation Guide](docs/en/contributing/template-creation-guide.md) for the full rules and the conventions checklist.

### Security Requirements

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inspect-templates-verbose: ## Run template inspection with verbose output
inspect-template: ## Inspect specific template(s) - Usage: make inspect-template TEMPLATES="template-name"
@if [ -z "$(TEMPLATES)" ]; then \
echo "Usage: make inspect-template TEMPLATES=\"template-name1,template-name2\""; \
echo "Example: make inspect-template TEMPLATES=\"fastapi-default,fastapi-async-crud\""; \
echo "Example: make inspect-template TEMPLATES=\"fastapi-default,fastapi-hello\""; \
exit 1; \
fi
python scripts/inspect-templates.py --templates "$(TEMPLATES)"
Expand Down
Loading
Loading