Sets up the project skeleton: - FastAPI app factory with lifespan, request-id middleware, and RFC 9457 problem+json error handlers - Async SQLAlchemy 2.0 over MySQL (asyncmy), with a constraint naming convention in place before the first migration and async Alembic - Keycloak as a pure resource server: OIDC discovery, cached JWKS with rotation-aware refresh, and require_roles dependencies - Devcontainer running MySQL 8.4 and Keycloak 26.7 as compose siblings, with the realm (clients, roles, test users) imported on first boot - Test suite covering the endpoints plus the token validator itself, exercised against a locally generated RSA keypair - uv packaging, ruff, mypy --strict, pre-commit, Gitea CI, prod Dockerfile Two Keycloak-in-containers traps are handled explicitly and documented in the README: the issuer/internal-URL split (the browser sees localhost:8080, the API sees keycloak:8080) and the audience mapper that stops Keycloak issuing tokens with aud=account. The devices resource is a placeholder proving the routing -> auth -> ORM -> migration path end to end; replace it with the real domain. Co-Authored-By: Claude Opus 5 <[email protected]>
26 lines
1.1 KiB
Bash
26 lines
1.1 KiB
Bash
# Copy to .env only if you need to override the devcontainer defaults.
|
|
# The devcontainer supplies all of these through compose, so a fresh clone runs
|
|
# with no .env file at all.
|
|
|
|
APP_ENV=local
|
|
DEBUG=true
|
|
LOG_LEVEL=INFO
|
|
|
|
# --- database ---------------------------------------------------------------
|
|
DATABASE_URL=mysql+asyncmy://v2x:v2xpassword@mysql:3306/v2x?charset=utf8mb4
|
|
TEST_DATABASE_URL=mysql+asyncmy://v2x:v2xpassword@mysql:3306/v2x_test?charset=utf8mb4
|
|
|
|
# --- keycloak ---------------------------------------------------------------
|
|
# These two URLs differ on purpose in local development; see README, "The two
|
|
# URL traps". KEYCLOAK_ISSUER is compared against the token's `iss` claim and
|
|
# must match the URL the *client* used. KEYCLOAK_INTERNAL_URL is how this
|
|
# process reaches Keycloak on the container network.
|
|
KEYCLOAK_ISSUER=http://localhost:8080/realms/v2x
|
|
KEYCLOAK_INTERNAL_URL=http://keycloak:8080
|
|
KEYCLOAK_REALM=v2x
|
|
KEYCLOAK_AUDIENCE=v2x-api
|
|
KEYCLOAK_SWAGGER_CLIENT_ID=v2x-swagger
|
|
|
|
# --- http -------------------------------------------------------------------
|
|
CORS_ORIGINS=["http://localhost:3000","http://localhost:8000"]
|