From e802ad24f7b751c9ac9cc23bfa46cd4df169b1c3 Mon Sep 17 00:00:00 2001 From: bnbong Date: Fri, 4 Dec 2026 13:49:51 +0900 Subject: [PATCH] [DOCS, FEAT, FIX] rebuild the English docs, fix problems found while writing them --- .github/workflows/build-docs.yml | 2 +- .github/workflows/translate-docs.yml | 2 +- .github/workflows/web-generator.yml | 8 +- CHANGELOG.md | 19 +- CONTRIBUTING.md | 2 +- Makefile | 4 +- README.md | 221 +-- docs/css/custom.css | 14 + docs/de/start/web-generator.md | 4 +- docs/en/contributing/code-guidelines.md | 748 ------- docs/en/contributing/development-setup.md | 907 +-------- .../contributing/template-creation-guide.md | 781 ++------ docs/en/contributing/translation-guide.md | 426 +--- docs/en/how-to/choose-a-level.md | 78 + docs/en/how-to/customise-features.md | 143 ++ docs/en/how-to/doctor.md | 100 + docs/en/how-to/example-projects.md | 179 ++ docs/en/how-to/scripts-and-config.md | 116 ++ docs/en/how-to/troubleshooting.md | 111 ++ docs/en/how-to/upgrade-from-1x.md | 95 + docs/en/index.md | 554 +----- docs/en/learn/deploy.md | 204 ++ docs/en/learn/extend.md | 179 ++ docs/en/learn/generate.md | 132 ++ docs/en/learn/migrate.md | 189 ++ docs/en/learn/test.md | 141 ++ docs/en/learn/understand.md | 146 ++ docs/en/reference/cli.md | 542 +++++ docs/en/reference/faq.md | 799 -------- docs/en/reference/generated-projects.md | 145 ++ docs/en/reference/levels-and-features.md | 237 +++ docs/en/reference/preset-feature-matrix.md | 87 - .../reference/template-quality-assurance.md | 332 ---- docs/en/reference/translation-status.md | 220 --- docs/en/start/installation.md | 63 + docs/en/start/web-generator.md | 4 +- docs/en/tutorial/auth-jwt.md | 365 ---- docs/en/tutorial/basic-api-server.md | 402 ---- docs/en/tutorial/custom-response-handling.md | 1409 ------------- docs/en/tutorial/domain-starter.md | 457 ----- docs/en/tutorial/first-project.md | 1225 ------------ docs/en/tutorial/getting-started.md | 534 ----- docs/en/tutorial/llm-agent.md | 292 --- docs/en/tutorial/mcp-integration.md | 1745 ----------------- docs/en/tutorial/sqlmodel.md | 351 ---- docs/en/user-guide/adding-routes.md | 328 ---- docs/en/user-guide/choosing-a-starter.md | 259 --- docs/en/user-guide/cli-reference.md | 1387 ------------- docs/en/user-guide/creating-projects.md | 551 ------ docs/en/user-guide/installation.md | 237 --- docs/en/user-guide/quick-start.md | 381 ---- docs/en/user-guide/using-templates.md | 400 ---- docs/es/start/web-generator.md | 4 +- docs/fr/start/web-generator.md | 4 +- docs/img/2.0/customise-features-dialogue.svg | 244 +++ docs/img/2.0/customise-features-list.svg | 162 ++ docs/img/2.0/deploy-swagger-authorize.png | Bin 0 -> 207250 bytes docs/img/2.0/doctor-findings.svg | 168 ++ docs/img/2.0/generate-init-dialogue.svg | 253 +++ docs/img/2.0/generate-swagger-ui.png | Bin 0 -> 81187 bytes docs/img/2.0/index-web-generator.png | Bin 0 -> 259653 bytes docs/img/2.0/understand-post-201.png | Bin 0 -> 148690 bytes docs/img/2.0/understand-post-422.png | Bin 0 -> 178698 bytes docs/ja/start/web-generator.md | 4 +- docs/js/web-generator-strings/de.json | 1 + docs/js/web-generator-strings/en.json | 1 + docs/js/web-generator-strings/es.json | 1 + docs/js/web-generator-strings/fr.json | 1 + docs/js/web-generator-strings/ja.json | 1 + docs/js/web-generator-strings/ko.json | 1 + docs/js/web-generator-strings/zh.json | 1 + docs/js/web-generator.mjs | 6 +- docs/ko/start/web-generator.md | 4 +- docs/zh/start/web-generator.md | 4 +- mkdocs.yml | 84 +- scripts/docs_blocks.py | 575 ++++++ scripts/mkdocs_hooks/redirects.py | 116 ++ scripts/update_nav_translations.py | 71 +- .../backend/doctor/checks_files.py | 32 +- src/fastapi_fastkit/backend/doctor/context.py | 16 + .../backend/interactive/prompts.py | 26 +- .../backend/interactive/selectors.py | 58 +- .../backend/interactive/summary.py | 7 +- src/fastapi_fastkit/backend/main.py | 5 +- .../backend/package_managers/base.py | 16 +- .../project_builder/config_generator.py | 208 +- .../backend/route_generators.py | 220 ++- src/fastapi_fastkit/backend/scaffolder.py | 140 +- src/fastapi_fastkit/catalog/catalog.toml | 7 + src/fastapi_fastkit/catalog/i18n/de.toml | 6 + src/fastapi_fastkit/catalog/i18n/es.toml | 6 + src/fastapi_fastkit/catalog/i18n/fr.toml | 6 + src/fastapi_fastkit/catalog/i18n/ja.toml | 6 + src/fastapi_fastkit/catalog/i18n/ko.toml | 6 + src/fastapi_fastkit/catalog/i18n/zh.toml | 6 + src/fastapi_fastkit/catalog/loader.py | 1 + src/fastapi_fastkit/cli.py | 80 +- src/fastapi_fastkit/commands/init.py | 33 +- src/fastapi_fastkit/commands/startdemo.py | 136 +- .../fastapi-auth-jwt/pyproject.toml-tpl | 2 + .../fastapi-auth-jwt/requirements-dev.txt-tpl | 1 + .../fastapi-auth-jwt/scripts/lint.sh-tpl | 1 + .../fastapi-custom-response/README.md-tpl | 2 +- .../pyproject.toml-tpl | 2 + .../requirements-dev.txt-tpl | 1 + .../scripts/lint.sh-tpl | 1 + .../fastapi-default/README.md-tpl | 7 +- .../fastapi-default/pyproject.toml-tpl | 16 +- .../fastapi-default/requirements-dev.txt-tpl | 3 + .../fastapi-default/scripts/lint.sh-tpl | 2 + .../src/api/routes/items.py-tpl | 2 +- .../fastapi-domain-starter/README.md-tpl | 4 +- .../fastapi-domain-starter/pyproject.toml-tpl | 16 +- .../requirements-dev.txt-tpl | 3 + .../scripts/lint.sh-tpl | 1 + .../src/app/domains/items/router.py-tpl | 2 +- .../tests/test_health.py-tpl | 6 +- .../tests/test_items.py-tpl | 52 +- .../tests/test_pagination.py-tpl | 12 +- .../fastapi-hello/main.py-tpl | 4 +- .../fastapi-llm-agent/pyproject.toml-tpl | 2 + .../requirements-dev.txt-tpl | 1 + .../fastapi-llm-agent/scripts/lint.sh-tpl | 1 + .../fastapi-mcp/README.md-tpl | 2 +- .../fastapi-mcp/pyproject.toml-tpl | 2 + .../fastapi-mcp/requirements-dev.txt-tpl | 1 + .../fastapi-mcp/scripts/lint.sh-tpl | 6 +- .../fastapi-single-module/README.md-tpl | 23 +- .../fastapi-single-module/pyproject.toml-tpl | 23 + .../requirements-dev.txt-tpl | 12 + .../fastapi-single-module/setup.cfg-tpl | 8 - .../fastapi-sqlmodel/.env.example-tpl | 9 +- .../fastapi-sqlmodel/Dockerfile-tpl | 2 + .../fastapi-sqlmodel/README.md-tpl | 14 +- .../fastapi-sqlmodel/pyproject.toml-tpl | 2 + .../fastapi-sqlmodel/requirements-dev.txt-tpl | 1 + .../fastapi-sqlmodel/scripts/lint.sh-tpl | 1 + .../src/app/core/config.py-tpl | 8 +- .../modules/api/routes/new_route.py-tpl | 25 +- .../modules/domain/router.py-tpl | 25 +- .../fragments/docker/docker_compose.j2 | 6 + .../items_sql/conftest_items_sql.py.j2 | 3 +- .../fragments/items_sql/router.py.j2 | 2 +- .../fragments/items_sql/test_items.py.j2 | 92 +- .../items_sql_classic/conftest.py.j2 | 3 +- .../fragments/items_sql_classic/routes.py.j2 | 2 +- .../items_sql_classic/test_items.py.j2 | 2 + .../fragments/logging/structured.py.j2 | 61 +- .../fragments/test/_auth_settings_tests.j2 | 17 +- .../fragments/test/_auth_store_fixtures.j2 | 15 +- .../fragments/test/pytest_ini.j2 | 22 - .../fragments/test/pytest_toml.j2 | 28 + .../test/test_auth_fastapi_users.py.j2 | 12 +- .../fragments/test/test_auth_jwt.py.j2 | 13 +- .../fragments/test/test_auth_oauth2.py.j2 | 6 +- .../fragments/test/test_auth_session.py.j2 | 11 +- src/fastapi_fastkit/generation/__init__.py | 6 + src/fastapi_fastkit/generation/browser.py | 22 +- .../generation/dependencies.py | 69 +- src/fastapi_fastkit/generation/guide.py | 5 + src/fastapi_fastkit/generation/pipeline.py | 35 + src/fastapi_fastkit/utils/logging.py | 109 +- src/fastapi_fastkit/utils/main.py | 6 +- src/fastapi_fastkit/utils/project_meta.py | 21 + tests/conftest.py | 37 + ...nimal_leftovers.json.as-single-module.json | 1 - .../handwritten_minimal_leftovers.json.json | 1 - .../golden/handwritten_preset_alias.toml.json | 1 - .../golden/save_classic_layered.toml.json | 1 - .../golden/save_domain_starter.json.json | 1 - .../golden/save_domain_starter.yaml.json | 1 - .../save_minimal.json.as-single-module.json | 1 - .../configs_1x/golden/save_minimal.json.json | 1 - .../golden/save_single_module.json.json | 1 - .../test_backends/test_interactive_prompts.py | 46 +- .../test_backends/test_interactive_summary.py | 4 +- .../test_project_builder_config_generator.py | 262 ++- tests/test_backends/test_route_plan.py | 6 +- tests/test_backends/test_route_shared_deps.py | 317 +++ tests/test_backends/test_scaffolder.py | 41 +- tests/test_catalog/test_guide_entries.py | 10 + tests/test_catalog/test_i18n.py | 2 +- .../snapshots/root_help.txt | 3 +- .../snapshots/startdemo_help.txt | 16 +- .../test_cli_config_options.py | 9 +- .../test_cli_error_paths.py | 8 +- .../test_cli_init_no_terminal.py | 2 +- .../test_cli_interactive_integration.py | 15 +- .../test_cli_output_fixes.py | 1272 ++++++++++++ .../test_cli_rough_edges.py | 1 + .../test_cli_runserver_fallback.py | 1 + tests/test_docs/docs_support.py | 84 + tests/test_docs/test_generated_blocks.py | 272 +++ tests/test_docs/test_redirects.py | 119 ++ tests/test_docs/test_site_structure.py | 162 ++ tests/test_docs/test_web_generator_page.py | 14 +- tests/test_generation/test_browser.py | 32 + tests/test_generation/test_dependencies.py | 101 +- tests/test_generation/test_guide.py | 17 + tests/test_generation/test_legacy_configs.py | 3 +- tests/test_generation/test_levels.py | 37 + tests/test_generation/test_pipeline.py | 60 +- tests/test_templates/test_sql_items.py | 2 +- .../test_structured_logging_runtime.py | 127 ++ 204 files changed, 9441 insertions(+), 15510 deletions(-) delete mode 100644 docs/en/contributing/code-guidelines.md create mode 100644 docs/en/how-to/choose-a-level.md create mode 100644 docs/en/how-to/customise-features.md create mode 100644 docs/en/how-to/doctor.md create mode 100644 docs/en/how-to/example-projects.md create mode 100644 docs/en/how-to/scripts-and-config.md create mode 100644 docs/en/how-to/troubleshooting.md create mode 100644 docs/en/how-to/upgrade-from-1x.md create mode 100644 docs/en/learn/deploy.md create mode 100644 docs/en/learn/extend.md create mode 100644 docs/en/learn/generate.md create mode 100644 docs/en/learn/migrate.md create mode 100644 docs/en/learn/test.md create mode 100644 docs/en/learn/understand.md create mode 100644 docs/en/reference/cli.md delete mode 100644 docs/en/reference/faq.md create mode 100644 docs/en/reference/generated-projects.md create mode 100644 docs/en/reference/levels-and-features.md delete mode 100644 docs/en/reference/preset-feature-matrix.md delete mode 100644 docs/en/reference/template-quality-assurance.md delete mode 100644 docs/en/reference/translation-status.md create mode 100644 docs/en/start/installation.md delete mode 100644 docs/en/tutorial/auth-jwt.md delete mode 100644 docs/en/tutorial/basic-api-server.md delete mode 100644 docs/en/tutorial/custom-response-handling.md delete mode 100644 docs/en/tutorial/domain-starter.md delete mode 100644 docs/en/tutorial/first-project.md delete mode 100644 docs/en/tutorial/getting-started.md delete mode 100644 docs/en/tutorial/llm-agent.md delete mode 100644 docs/en/tutorial/mcp-integration.md delete mode 100644 docs/en/tutorial/sqlmodel.md delete mode 100644 docs/en/user-guide/adding-routes.md delete mode 100644 docs/en/user-guide/choosing-a-starter.md delete mode 100644 docs/en/user-guide/cli-reference.md delete mode 100644 docs/en/user-guide/creating-projects.md delete mode 100644 docs/en/user-guide/installation.md delete mode 100644 docs/en/user-guide/quick-start.md delete mode 100644 docs/en/user-guide/using-templates.md create mode 100644 docs/img/2.0/customise-features-dialogue.svg create mode 100644 docs/img/2.0/customise-features-list.svg create mode 100644 docs/img/2.0/deploy-swagger-authorize.png create mode 100644 docs/img/2.0/doctor-findings.svg create mode 100644 docs/img/2.0/generate-init-dialogue.svg create mode 100644 docs/img/2.0/generate-swagger-ui.png create mode 100644 docs/img/2.0/index-web-generator.png create mode 100644 docs/img/2.0/understand-post-201.png create mode 100644 docs/img/2.0/understand-post-422.png create mode 100755 scripts/docs_blocks.py create mode 100644 scripts/mkdocs_hooks/redirects.py delete mode 100644 src/fastapi_fastkit/fastapi_project_template/fastapi-single-module/setup.cfg-tpl delete mode 100644 src/fastapi_fastkit/fragments/test/pytest_ini.j2 create mode 100644 src/fastapi_fastkit/fragments/test/pytest_toml.j2 create mode 100644 tests/test_backends/test_route_shared_deps.py create mode 100644 tests/test_cli_operations/test_cli_output_fixes.py create mode 100644 tests/test_docs/docs_support.py create mode 100644 tests/test_docs/test_generated_blocks.py create mode 100644 tests/test_docs/test_redirects.py create mode 100644 tests/test_docs/test_site_structure.py create mode 100644 tests/test_templates/test_structured_logging_runtime.py diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 80e6cf6c..eb6d5752 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -65,4 +65,4 @@ jobs: path: .cache restore-keys: | mkdocs-material- - - run: mkdocs gh-deploy --force + - run: mkdocs gh-deploy --strict --force diff --git a/.github/workflows/translate-docs.yml b/.github/workflows/translate-docs.yml index 4ffadeef..a177e6f0 100644 --- a/.github/workflows/translate-docs.yml +++ b/.github/workflows/translate-docs.yml @@ -16,7 +16,7 @@ on: - anthropic default: openai specific_files: - description: 'Specific files to translate (space-separated, relative to docs/en/). Example: index.md user-guide/installation.md' + description: 'Specific files to translate (space-separated, relative to docs/en/). Example: index.md start/installation.md' required: false type: string create_pr: diff --git a/.github/workflows/web-generator.yml b/.github/workflows/web-generator.yml index dbd7e92f..34574816 100644 --- a/.github/workflows/web-generator.yml +++ b/.github/workflows/web-generator.yml @@ -9,9 +9,11 @@ on: pull_request: paths: - "src/**" - - "docs/js/**" - - "docs/css/web-generator.css" - - "docs/*/start/web-generator.md" + - "docs/**" + - "README.md" + - "CHANGELOG.md" + - "scripts/mkdocs_hooks/**" + - "scripts/docs_blocks.py" - "scripts/web_generator/**" - "tests/fixtures/web_generator/**" - "pyproject.toml" diff --git a/CHANGELOG.md b/CHANGELOG.md index d985f5cf..b819ca77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,13 +47,13 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f - 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]`. +- A prompt that gets 10 invalid answers, or whose input ends, exits with status 1. `startdemo -y` asks only for the project name, 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. -- `list-features` shows the utility and tooling options that `init` offers and lists CORS and pagination as built into every project. +- `list-features` shows the utility, tooling and deployment options that `init` offers, with package extras such as `pyjwt[crypto]`, 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. @@ -63,6 +63,10 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f - `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. +- `init` prints the summary, the files it created and the next steps; its internal steps are shown only with `fastkit --debug init`. +- `init` refuses a project name that is also the name of one of the project's dependencies (such as `sqlmodel` for `fastapi-sqlmodel`), because the package manager would then not install that dependency; the web generator refuses it too. +- `runserver` exits with the server's own exit status and a one-line message when the server stops with an error. Error tracebacks no longer show local variables, which could print environment variables and the secrets in them. +- In layered projects `addroute` adds the new resource's dependency to `src/api/deps.py`, and the routes it writes follow the example `items` routes: the return annotation is the response model and the 404 answer is documented. ### Web generator @@ -87,6 +91,9 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f - **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. +- **Testing:** pytest and coverage settings go to `pyproject.toml`; no `pytest.ini` is generated. +- **Structured logging** writes one JSON access line per request (logger `app.access`) with the request id, method, path, status code and duration, and turns off uvicorn's own access log. +- **Docker Compose:** a comment in `docker-compose.yml` and a sentence in the README explain that `.env` runs the containers in development mode and how to switch. ### Templates @@ -100,12 +107,14 @@ Every 401 carries `WWW-Authenticate`, and each project reads its configuration f - 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. +- `fastapi-single-module`, `fastapi-default` and `fastapi-domain-starter` ship pytest-cov with coverage settings and ruff in their dev dependencies, and keep their pytest settings in `pyproject.toml`. The `scripts/lint.sh` of `fastapi-default` and `fastapi-domain-starter` runs black, isort, mypy and ruff. +- `fastapi-sqlmodel` leaves the schema to Alembic by default (`CREATE_TABLES_ON_STARTUP=false`), so run `alembic upgrade head` before the first start. +- Every template except `fastapi-hello` ships the ruff configuration that `init`'s ruff option writes; the example templates also install ruff and run it from their lint scripts. `fastapi-single-module` projects pass isort and `mypy src`, and `fastapi-custom-response` uses Python 3.12 generic syntax for its response envelope. ### 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. +- The documentation is reorganised into Start, Learn, How-to, Reference and Contributing; the Learn track follows one project from `hello` to `production`, and old page addresses redirect to their new pages. +- CLI reference tables and help texts are generated from the catalog and the CLI, and the configuration-file and environment-variable sections that described settings fastkit never read are removed. ### Upgrade notes for existing projects diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b46df962..7dfee21e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -478,7 +478,7 @@ make translate LANG=ko PROVIDER=openai MODEL=gpt-4 python scripts/translate.py --target-lang ko --api-provider openai # Translate specific files (paths relative to docs/en/) -python scripts/translate.py --target-lang ko --files index.md user-guide/installation.md --api-provider openai +python scripts/translate.py --target-lang ko --files index.md start/installation.md --api-provider openai # Translate without creating PR (for local testing) python scripts/translate.py --target-lang ko --no-pr --api-provider openai diff --git a/Makefile b/Makefile index 3661f584..107461ef 100644 --- a/Makefile +++ b/Makefile @@ -102,11 +102,13 @@ serve-docs: ## Serve documentation locally mkdocs serve # Development workflow commands +# docs is a dependency group, not an extra: install its export, +# requirements-docs.txt, as the docs workflow does. dev-setup: ## Set up development environment from scratch @echo "Setting up development environment..." pip install --upgrade pip pip install -e ".[dev]" - pip install -e ".[docs]" || pip install -r requirements-docs.txt + pip install -r requirements-docs.txt pre-commit install @echo "Development environment setup complete!" diff --git a/README.md b/README.md index 0b03e6ee..95960883 100644 --- a/README.md +++ b/README.md @@ -25,194 +25,99 @@ This project was created to speed up the configuration of the development enviro This project was inspired by the `SpringBoot initializer` & Python Django's `django-admin` CLI operation. -## Key Features - -- **โšก Immediate FastAPI project creation** : Super-fast FastAPI workspace & project creation via CLI, inspired by `django-admin` feature of [Python Django](https://github.com/django/django) -- **โœจ Guided project builder**: Pick a level from one `main.py` to a production layout, then customise databases, authentication, caching, monitoring, and more with auto-generated code -- **๐ŸŽจ Prettier CLI output** : Beautiful CLI experience powered by [rich library](https://github.com/Textualize/rich) -- **๐Ÿ“‹ Standards-based FastAPI project templates** : Templates follow Python standards and common FastAPI patterns. -- **๐Ÿ” Automated template quality assurance** : Weekly automated testing ensures all templates remain functional and up-to-date -- **๐Ÿš€ Multiple project templates** : Choose from various pre-configured templates for different use cases (async CRUD, Docker, PostgreSQL, etc.) -- **๐Ÿ“ฆ Multiple package manager support** : Choose your preferred Python package manager (pip, uv, pdm, poetry) for dependency management -- **๐Ÿงพ Reproducible project configs** : Save a project's choices to a `.json` / `.toml` / `.yaml` file and replay it with `fastkit init --config` -- **๐Ÿท๏ธ Self-describing projects** : Every generated project records its template, preset, package manager, entrypoint and selected features in a `[tool.fastapi-fastkit]` block that `runserver` and `addroute` read back - ## Installation -Install `FastAPI-fastkit` in your Python environment. - -To try fastkit without installing anything, use the [web generator](https://bnbong.github.io/FastAPI-fastkit/start/web-generator/) in your browser. +Install `FastAPI-fastkit` in a Python 3.12+ environment: ```console -$ pip install FastAPI-fastkit +$ pip install fastapi-fastkit ``` +To try fastkit without installing anything, use the [web generator](https://bnbong.github.io/FastAPI-fastkit/start/web-generator/) in your browser. [Installation](https://bnbong.github.io/FastAPI-fastkit/start/installation/) covers uv and the other options. -## Usage +## Quick start -- Global options - - `--help`: Show help - - `--version`: Show version - - `--debug/--no-debug`: Toggle debug mode +`fastkit init` asks for a project name and a level, creates the project and installs its dependencies. Press Enter at every question to get the `hello` level: one `main.py` with three endpoints and their tests. The run ends with the next steps: -### Create a new FastAPI project ```console -fastkit init [OPTIONS] +$ fastkit init + +โšก Create a FastAPI project + +Project name: shop +... +โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Next steps โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ +โ”‚ 1. Go to the project folder. โ”‚ +โ”‚ cd shop โ”‚ +โ”‚ 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. โ”‚ +โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ ``` -> [!TIP] -> Asks for a project name and a level, then creates the project, sets up a virtual environment and installs the dependencies - -- Levels, each one adds structure to the one above: - - `hello` (default): one `main.py` with three endpoints, in-memory data and tests - - `single-file`: the whole app in one module, with settings and tests - - `layered`: separate layers for routes, CRUD, schemas and core configuration - - `domain`: one package per domain with router, service and repository - - `production`: `domain` plus PostgreSQL, Alembic, JWT, CI and Docker -- Asks only what the options leave open: the project name, the level, the database (levels after `hello`) and whether to customise. The customise step covers authentication, background tasks, caching, monitoring, logging, testing, migrations, utilities, tooling, deployment, package manager and custom packages -- Key options: - - `--project-name` (`--name`), `--level`, `--database` [PostgreSQL|MySQL|MongoDB|Redis|SQLite|None] - - `--feature AXIS=VALUE` (repeatable, e.g. `--feature authentication=JWT`; `fastkit list-features` shows the values) and `--extra-package`, for levels after `hello` - - `--template `: copy a bundled template as it is instead of choosing a level (see below) - - `--author`, `--author-email` (default to `git config user.name` / `user.email`), `--description` - - `--package-manager` [pip|uv|pdm|poetry]: defaults to uv when installed, otherwise pip - - `--config `: create the project from a saved config file (`.json` / `.toml`, and `.yaml` when PyYAML is installed) with no prompts - - `--save-config `: write the project's configuration to a file for reuse with `--config` - - `--in-place`: write into the current directory instead of a new folder - - `--dry-run`: print the files and packages that would be created, write nothing - - `--no-venv`: skip virtual environment creation (implies `--no-install`) - - `--no-install`: skip dependency installation - - `--yes` / `-y`: use the defaults for every question that has one and create the project without asking; with `--in-place`, also allow overwriting files -- Without a terminal nothing is asked: pass `--project-name` (or `--config`) and everything else takes its default. Exit status: 0 created, previewed or cancelled, 1 refused or failed, 2 invalid options -```console -fastkit init --project-name api --level domain --database SQLite --feature authentication=JWT --no-venv -y -``` +The [Learn track](https://bnbong.github.io/FastAPI-fastkit/learn/generate/) starts from this project and follows it up to the production level. -Every generated project serves `GET /health` at the root and mounts its API under `/api/v1`; with a database or cache it also serves `GET /ready`. Selected features come with real working code and tests, not just installed packages. See [the matrix](https://bnbong.github.io/FastAPI-fastkit/reference/preset-feature-matrix/) for where each feature lands per level. +## Levels -### Create a project from a template -```console -fastkit init --template