diff --git a/AGENTS.md b/AGENTS.md index 287e0ff..60604b8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,7 +42,8 @@ Live docs: https://syntaxarc.github.io/ArchiPy/ - Models: data only. Logics: UoW + business rules. Services: thin transport. - Domain adapters under `repositories/{domain}/adapters/` — not a top-level app `adapters/` package. -- FastAPI/uvicorn from `config.FASTAPI`; prefer `AppUtils.create_fastapi_app` / gRPC factories. +- FastAPI app settings from `config.FASTAPI`, uvicorn server settings from `config.UVICORN` through + `AppUtils.uvicorn_config()` (archipy >= 5.25.0); prefer `AppUtils.create_fastapi_app` / gRPC factories. - Specific exceptions; always `raise ... from e`. - Python 3.14 typing, double quotes, Google docstrings, complete public annotations; follow app tooling when stricter. - No hardcoded secrets or logged credentials/tokens; parameterize queries and justify narrow security suppressions. diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d633fd..0c6d699 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- Rules, skills, the cheat sheet, README, `AGENTS.md` and `archipy-reviewer` follow ArchiPy 5.25: uvicorn runs with + `AppUtils.uvicorn_config()` from the new `UVICORN` config section (`archipy>=5.25.0`), host and port stay on + `FASTAPI.SERVE_HOST` and `SERVE_PORT`, `RELOAD` is set on `UVICORN`, and the reviewer flags reads of the deprecated + uvicorn fields of `FASTAPI`. + ## [0.23.0] - 2026-10-27 ### Changed diff --git a/README.md b/README.md index ede3480..a24c645 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ Prefer ArchiPy extras and thin domain wrappers under `repositories/{domain}/adap Pure utilities; prefer ArchiPy utils. **AppUtils** for FastAPI/gRPC factories. -- **Do:** Use `create_fastapi_app` / `create_grpc_app` / `create_async_grpc_app`; drive uvicorn from `config.FASTAPI`. +- **Do:** Use `create_fastapi_app` / `create_grpc_app` / `create_async_grpc_app`; drive uvicorn with `AppUtils.uvicorn_config()` (`config.UVICORN`, archipy >= 5.25.0). - **Don’t:** Hand-roll bare `FastAPI()` / `grpc.server()`; open DB/Redis clients in utils. ### `using-archipy-decorators` @@ -300,7 +300,7 @@ Cross-cutting hooks only; prefer AppUtils auto-registration for stock intercepto `BaseConfig`, `FastAPIConfig`, `customize()`, DI wire order `ports → adapters → repositories → logics → services`. -- **Do:** Call `BaseConfig.set_global` once; set FastAPI/uvicorn defaults via `config.FASTAPI`. +- **Do:** Call `BaseConfig.set_global` once; set FastAPI defaults via `config.FASTAPI` and uvicorn defaults via `config.UVICORN`. - **Don’t:** Commit secrets or scatter `os.environ` outside config. ### `using-archipy-models` @@ -326,7 +326,7 @@ Business rules + unit of work; domain isolation. ### `using-archipy-services` -Thin transport; AppUtils bootstrap; uvicorn from `FastAPIConfig`. +Thin transport; AppUtils bootstrap; uvicorn from `UvicornConfig` through `AppUtils.uvicorn_config()`. - **Do:** Map errors to HTTP/gRPC status; version routers under `v{n}/`. - **Don’t:** Put atomic / UoW decorators or business rules in services; hardcode host/port. diff --git a/agents/archipy-reviewer.md b/agents/archipy-reviewer.md index ed51f9a..b5e7aa1 100644 --- a/agents/archipy-reviewer.md +++ b/agents/archipy-reviewer.md @@ -119,7 +119,10 @@ makes it worse. - With OTel enabled, `OtelUtils.init_otel_if_needed(config)` runs after `set_global` and before the container creates engines, clients, or other instrumented adapters. - FastAPI/gRPC apps are built with `AppUtils.create_fastapi_app` / `create_grpc_app` / `create_async_grpc_app`, not - bare `FastAPI()` / `grpc.server()`; uvicorn host and port come from `config.FASTAPI`, never hardcoded. + bare `FastAPI()` / `grpc.server()`; uvicorn host and port come from `config.FASTAPI`, never hardcoded, and the server settings come from + `config.UVICORN` through `AppUtils.uvicorn_config()`; reading the deprecated uvicorn fields of `config.FASTAPI` + (`RELOAD`, `PROXY_HEADERS`, `FORWARDED_ALLOW_IPS`, `WORKERS_COUNT`, `TIMEOUT_*`, `WS_*`, …) is **Should fix** (needs + `archipy>=5.25.0`; say so when the app pins an older version). - Dependencies are wired through the DI container, not constructed at module import time. **ArchiPy version** diff --git a/rules/config-and-di.mdc b/rules/config-and-di.mdc index 78b3184..7ee32e4 100644 --- a/rules/config-and-di.mdc +++ b/rules/config-and-di.mdc @@ -1,5 +1,5 @@ --- -description: ArchiPy BaseConfig, FastAPIConfig/uvicorn, and DI container wiring +description: ArchiPy BaseConfig, FastAPIConfig/UvicornConfig, and DI container wiring globs: **/configs/**/*.py alwaysApply: false --- @@ -18,13 +18,13 @@ logger = logging.getLogger(__name__) class AppConfig(BaseConfig): - """Application configuration. Inherits ArchiPy sections (REDIS, FASTAPI, GRPC, ...).""" + """Application configuration. Inherits ArchiPy sections (REDIS, FASTAPI, UVICORN, GRPC, ...).""" def customize(self) -> None: """Apply service-specific defaults after sources load.""" super().customize() self.FASTAPI.PROJECT_NAME = "my-service" - self.FASTAPI.RELOAD = self.ENVIRONMENT == EnvironmentType.LOCAL + self.UVICORN.RELOAD = self.ENVIRONMENT == EnvironmentType.LOCAL config = AppConfig() @@ -35,20 +35,24 @@ logger.info("Config loaded for environment: %s", config.ENVIRONMENT) - Call `BaseConfig.set_global(config)` once at bootstrap (typically importing `app_config` from the DI container). - Read elsewhere via `BaseConfig.global_config()`. - Document required env vars in `.env.example`; never commit secrets. -- Env overrides use nested delimiter: `FASTAPI__PROJECT_NAME`, `FASTAPI__SERVE_PORT`, … +- Env overrides use nested delimiter: `FASTAPI__PROJECT_NAME`, `FASTAPI__SERVE_PORT`, `UVICORN__RELOAD`, … - Preserve ArchiPy's settings-source priority: secret files → Vault → pyproject → TOML → environment → `.env` → defaults. Do not add scattered `os.environ` reads that bypass it. - Raise `ConfigurationError` / `InvalidArgumentError` from `archipy.models.errors` for config validation failures; do not invent ad-hoc config exceptions. -## FastAPIConfig (`config.FASTAPI`) +## FastAPIConfig (`config.FASTAPI`) and UvicornConfig (`config.UVICORN`) -Drives both `AppUtils.create_fastapi_app` and uvicorn in `manage.py`: +`config.FASTAPI` drives `AppUtils.create_fastapi_app` and the bind address; `config.UVICORN` holds the server settings +that `AppUtils.uvicorn_config()` turns into `uvicorn.run` arguments (archipy >= 5.25.0; the same names on `FASTAPI` are +deprecated): | Area | Fields | |------|--------| -| Serve | `SERVE_HOST`, `SERVE_PORT`, `RELOAD`, `WORKERS_COUNT` | -| Proxy | `PROXY_HEADERS`, `FORWARDED_ALLOW_IPS` | +| Bind (`FASTAPI`) | `SERVE_HOST`, `SERVE_PORT` | +| Server (`UVICORN`) | `RELOAD`, `WORKERS_COUNT`, `TIMEOUT_KEEP_ALIVE`, `TIMEOUT_GRACEFUL_SHUTDOWN`, `BACKLOG`, `LIMIT_*`, `WS_*`, `ACCESS_LOG`, `DATE_HEADER`, `SERVER_HEADER` | +| Proxy (`UVICORN`) | `PROXY_HEADERS`, `FORWARDED_ALLOW_IPS` | +| TLS (`UVICORN`) | `SSL_KEYFILE`, `SSL_CERTFILE` (set together), `SSL_CA_CERTS` | | App / docs | `PROJECT_NAME`, `OPENAPI_URL`, `DOCS_URL`, `RE_DOC_URL`, … | | Middleware flags | `GZIP_MIDDLEWARE_IS_ENABLED`, `TRUSTED_HOST_MIDDLEWARE_*`, `HTTPS_REDIRECT_MIDDLEWARE_IS_ENABLED`, CORS fields | @@ -78,4 +82,4 @@ Bundled cheat sheet (BaseConfig + FastAPIConfig/uvicorn sketches): `skills/archi - Scatter `os.environ` reads outside config. - Construct adapters inside logics when a container exists — inject them. - Hardcode production secrets in defaults. -- Hardcode uvicorn host/port — use `config.FASTAPI`. +- Hardcode uvicorn host/port, or read the deprecated uvicorn fields of `config.FASTAPI` — use `AppUtils.uvicorn_config()`. diff --git a/rules/using-archipy-services.mdc b/rules/using-archipy-services.mdc index 544751a..c1abdbc 100644 --- a/rules/using-archipy-services.mdc +++ b/rules/using-archipy-services.mdc @@ -1,5 +1,5 @@ --- -description: ArchiPy app services — thin transport, AppUtils, uvicorn via FastAPIConfig +description: ArchiPy app services — thin transport, AppUtils, uvicorn via UvicornConfig globs: **/services/**/*.py,**/manage.py alwaysApply: false --- @@ -91,27 +91,22 @@ gRPC (adds servicers to an `AppUtils`-built server; never binds a port). ## manage.py / uvicorn -Bind from `config.FASTAPI` — never hardcode host/port/reload/proxy: +Build the uvicorn arguments with `AppUtils.uvicorn_config()` — host and port come from `config.FASTAPI` +(`SERVE_HOST`, `SERVE_PORT`), the server settings from `config.UVICORN` (archipy >= 5.25.0). Never hardcode +host/port/reload/proxy: ```python config = BaseConfig.global_config() -uvicorn.run( - "manage:create_app", - factory=True, - host=config.FASTAPI.SERVE_HOST, - port=config.FASTAPI.SERVE_PORT, - reload=config.FASTAPI.RELOAD, - proxy_headers=config.FASTAPI.PROXY_HEADERS, - forwarded_allow_ips=config.FASTAPI.FORWARDED_ALLOW_IPS or "127.0.0.1", -) +uvicorn.run("manage:create_app", factory=True, **AppUtils.uvicorn_config(config)) ``` -CLI flags may override for local runs; defaults always come from `FASTAPI`. +CLI flags may override for local runs (`AppUtils.uvicorn_config(config, host=host, port=port, reload=reload)`); defaults +always come from `FASTAPI` and `UVICORN`. ## Do Not - Put business rules or `@postgres_sqlalchemy_atomic` in services. - Hand-roll bare `FastAPI()` / `grpc.server()` when AppUtils extras are installed. -- Hardcode uvicorn host/port — use `FastAPIConfig`. +- Hardcode uvicorn host/port, or read the deprecated uvicorn fields of `FASTAPI` — use `AppUtils.uvicorn_config()`. - Use non-kebab literal path segments, verb paths (`/get-user`), or flat routes that hide the resource hierarchy. - Catch every domain error in each route/servicer when AppUtils already provides centralized mapping. diff --git a/rules/using-archipy-utils.mdc b/rules/using-archipy-utils.mdc index b6ad054..9f42082 100644 --- a/rules/using-archipy-utils.mdc +++ b/rules/using-archipy-utils.mdc @@ -56,7 +56,8 @@ Prefer ArchiPy factories — do **not** hand-roll bare `FastAPI()` / `grpc.serve Rules: - Pass `BaseConfig.global_config()` (or injected config); do not duplicate middleware/interceptor setup AppUtils already does. -- **FastAPI + uvicorn always driven by `config.FASTAPI` (`FastAPIConfig`)** — never hardcode host/port/reload/proxy settings. +- **FastAPI is driven by `config.FASTAPI`, uvicorn by `config.UVICORN` through `AppUtils.uvicorn_config()`** (archipy >= 5.25.0) + — never hardcode host/port/reload/proxy settings or read the deprecated uvicorn fields of `FASTAPI`. - Sync servicers → `create_grpc_app`; async servicers → `create_async_grpc_app` — do not mix. - Enable features through config (for example `OTEL.IS_ENABLED`, `OTEL.TRACES_ENABLED`, `OTEL.METRICS_ENABLED`, `FASTAPI.GZIP_MIDDLEWARE_IS_ENABLED`, and `GRPC_RATE_LIMIT.IS_ENABLED`) rather than manually appending stock diff --git a/skills/archipy-docs/reference/config.md b/skills/archipy-docs/reference/config.md index ed6f3fa..0f67532 100644 --- a/skills/archipy-docs/reference/config.md +++ b/skills/archipy-docs/reference/config.md @@ -12,7 +12,7 @@ class AppConfig(BaseConfig): def customize(self) -> None: super().customize() self.FASTAPI.PROJECT_NAME = "my-service" - self.FASTAPI.RELOAD = self.ENVIRONMENT == EnvironmentType.LOCAL + self.UVICORN.RELOAD = self.ENVIRONMENT == EnvironmentType.LOCAL config = AppConfig() BaseConfig.set_global(config) # auto-invokes customize() @@ -21,27 +21,24 @@ BaseConfig.set_global(config) # auto-invokes customize() - Env vars override defaults (`FASTAPI__SERVE_PORT`, …); document keys in `.env.example`. - Read with `BaseConfig.global_config()`. -### FastAPIConfig + uvicorn +### FastAPIConfig + UvicornConfig -`config.FASTAPI` drives `AppUtils.create_fastapi_app` **and** uvicorn — never hardcode host/port/reload: +`config.FASTAPI` drives `AppUtils.create_fastapi_app` and the bind address; `config.UVICORN` (archipy >= 5.25.0) holds the +server settings and `AppUtils.uvicorn_config()` builds the `uvicorn.run` arguments — never hardcode host/port/reload. +The same names on `FASTAPI` are deprecated since 5.25.0: -| Area | Fields | -|------------|---------------------------------------------------------| -| Serve | `SERVE_HOST`, `SERVE_PORT`, `RELOAD`, `WORKERS_COUNT` | -| Proxy | `PROXY_HEADERS`, `FORWARDED_ALLOW_IPS` | -| App / docs | `PROJECT_NAME`, `OPENAPI_URL`, `DOCS_URL`, `RE_DOC_URL` | +| Area | Fields | +|---------------------|---------------------------------------------------------------------------| +| Bind (`FASTAPI`) | `SERVE_HOST`, `SERVE_PORT` | +| Server (`UVICORN`) | `RELOAD`, `WORKERS_COUNT`, `TIMEOUT_KEEP_ALIVE`, `TIMEOUT_GRACEFUL_SHUTDOWN`, `WS_*` | +| Proxy (`UVICORN`) | `PROXY_HEADERS`, `FORWARDED_ALLOW_IPS` | +| TLS (`UVICORN`) | `SSL_KEYFILE`, `SSL_CERTFILE` (together), `SSL_CA_CERTS` | +| App / docs (`FASTAPI`) | `PROJECT_NAME`, `OPENAPI_URL`, `DOCS_URL`, `RE_DOC_URL` | ```python config = BaseConfig.global_config() -uvicorn.run( - "manage:create_app", - factory=True, - host=config.FASTAPI.SERVE_HOST, - port=config.FASTAPI.SERVE_PORT, - reload=config.FASTAPI.RELOAD, - proxy_headers=config.FASTAPI.PROXY_HEADERS, - forwarded_allow_ips=config.FASTAPI.FORWARDED_ALLOW_IPS or "127.0.0.1", -) +uvicorn.run("manage:create_app", factory=True, **AppUtils.uvicorn_config(config)) +# overrides: AppUtils.uvicorn_config(config, host="0.0.0.0", port=9000, reload=True) ``` gRPC bind (parallel): `config.GRPC.SERVE_HOST`, `config.GRPC.SERVE_PORT`. diff --git a/skills/scaffold-app/SKILL.md b/skills/scaffold-app/SKILL.md index f365355..be13164 100644 --- a/skills/scaffold-app/SKILL.md +++ b/skills/scaffold-app/SKILL.md @@ -68,8 +68,9 @@ features/ # optional — /scaffold-bdd 5. Add a minimal domain DTO + error following `../scaffold-models/SKILL.md`. 6. **When extras include `fastapi` (or user wants HTTP):** emit root `manage.py`: - `create_app()` uses `AppUtils.create_fastapi_app()` and includes domain routers. - - `uvicorn.run` binds from `config.FASTAPI` (`SERVE_HOST`, `SERVE_PORT`, `RELOAD`, `PROXY_HEADERS`, - `FORWARDED_ALLOW_IPS`) — never hardcode host/port. + - `uvicorn.run("manage:create_app", factory=True, **AppUtils.uvicorn_config(config))` — host and port come from + `config.FASTAPI` (`SERVE_HOST`, `SERVE_PORT`), the server settings from `config.UVICORN` (archipy >= 5.25.0). + Never hardcode host/port. 7. Document next steps: `/scaffold-domain`, `/scaffold-models`, `/scaffold-adapter`, `/scaffold-bdd`, `/scaffold-health-checks`, `/docs-quickstart`. diff --git a/skills/scaffold-service/SKILL.md b/skills/scaffold-service/SKILL.md index a6e49cc..de9aac2 100644 --- a/skills/scaffold-service/SKILL.md +++ b/skills/scaffold-service/SKILL.md @@ -70,8 +70,9 @@ app = AppUtils.create_fastapi_app() app.include_router(create__v1_router(container)) ``` -uvicorn in `manage.py` from `config.FASTAPI` (`SERVE_HOST`, `SERVE_PORT`, `RELOAD`, `PROXY_HEADERS`, -`FORWARDED_ALLOW_IPS`). +uvicorn in `manage.py` with `**AppUtils.uvicorn_config(config)`: host and port from `config.FASTAPI` (`SERVE_HOST`, +`SERVE_PORT`), the server settings (`RELOAD`, `PROXY_HEADERS`, `FORWARDED_ALLOW_IPS`, timeouts, workers, TLS) from +`config.UVICORN` (archipy >= 5.25.0). ## Do not