8 Commits
Author SHA1 Message Date
moujitx 9c32571560 fix(backend): keep third-party loggers quiet while DEBUG is on
With the shipped local default (DEBUG=true) the root logger was set to DEBUG, so
aiosqlite printed every cursor operation and the console became unreadable
(hundreds of lines per request).

- only the `app` namespace follows DEBUG; the root logger stays at INFO
- SQLAlchemy / aiosqlite / asyncpg / asyncio are pinned to WARNING, or INFO when
  DB_ECHO is explicitly enabled (the engine already emits SQL at INFO then)
- uvicorn loggers are aligned to INFO and propagate to our handler as before

Observed on the running dev server: startup went from ~40 driver lines to 4
(Starting / Database target / connection established / Application startup
complete) and requests log a single uvicorn.access line.

docs: also document the Windows `--reload` caveat found while verifying: uvicorn
restarts the child with CTRL_C_EVENT, which cannot reach a child in a different
console / redirected-stdio environment, so the reloader prints "Reloading..."
and then blocks in process.join() while the old code keeps serving.

Verification: ruff + ruff format clean, pytest 14 passed, and the fix was proven
in isolation (aiosqlite effective level 30, app 10) and on the restarted server.
2026-10-02 14:03:11 +08:00
moujitx c81973acfb chore(docker): connect to an external PostgreSQL instead of bundling one
The database is no longer part of the stack, so the Compose project only builds
and runs the two application services.

- docker-compose.yml: drop the `postgres` service and the `postgres-data` volume;
  the backend now receives DATABASE_URL as a plain environment variable
  (default `postgresql+asyncpg://app:app@host.docker.internal:5432/app`, i.e. a
  database running on the Docker host)
- add `extra_hosts: host.docker.internal:host-gateway` so the host name also
  resolves on Linux, not just Docker Desktop
- plumb DB_WAIT_TIMEOUT through to the container; the entrypoint still waits for
  the database and then runs `alembic upgrade head` before serving traffic, so a
  slow or temporarily unreachable external instance no longer crash-loops the API
- .env.example: replace POSTGRES_USER/PASSWORD/DB/PORT with a single documented
  DATABASE_URL (host DB / sibling container / managed instance examples, plus the
  SQLite escape hatch and password percent-encoding note)
- README: prerequisites now create the role and database up front, the env table
  and Docker section describe the three external-database scenarios, and the FAQ
  covers "container cannot reach the database" and auth failures

Verification
- docker-compose.yml parsed and asserted: exactly {backend, frontend}, no volumes,
  backend has no depends_on, frontend gates on service_started, extra_hosts set,
  no nested ${} defaults
- repo-wide grep confirms no POSTGRES_* / postgres-data / `down -v` leftovers
2026-10-02 13:48:02 +08:00
moujitx be95b9593c fix(backend): let backend/.env override the Compose .env file
pydantic-settings merges multiple env files in order and the last one wins
(verified experimentally). Listing ".env" last means the backend-local file takes
precedence over the repository-root .env that drives Docker Compose, while real
environment variables still win over both. The comment now documents that rule.
2026-10-02 13:19:19 +08:00
moujitx ad348f589c docs: add the project README
- stack table, annotated directory tree and both quick-start paths
  (Docker Compose and native hot-reload development)
- environment variable reference for .env, backend/.env and frontend/.env
- v1 endpoint table, migration workflow and per-side command cheatsheet
- Docker service matrix plus the WAIT_FOR_DATABASE / RUN_MIGRATIONS switches
- step-by-step recipe for adding a new module (mirrors the items example)
- verification matrix and FAQ, including the honest note that Docker images
  could not be built in the initialization environment (no Docker CLI)
2026-10-02 13:18:37 +08:00
moujitx 68dd61e8bb chore(docker): containerize both services and add the Compose stack
Backend image (backend/Dockerfile)
- two stages: build-essential builder produces a venv, slim runtime carries only
  the venv (no compilers), runs as non-root user `app`
- docker-entrypoint.sh: optional DB wait -> `alembic upgrade head` -> exec CMD
- app/cli/wait_for_db.py: retry loop with timeout so the API no longer
  crash-loops when Postgres is still starting (run as a module so `app` is
  importable inside the container)
- HEALTHCHECK on /api/v1/health/live, uvicorn with proxy headers

Frontend image (frontend/Dockerfile)
- node:22-alpine builds the SPA with `yarn install --frozen-lockfile && yarn build`
- nginx:1.27-alpine serves dist, HEALTHCHECK via wget
- nginx.conf: history fallback, immutable caching for hashed assets, no-cache for
  index.html, and a reverse proxy for /api, /docs, /redoc using Docker DNS with a
  resolver variable so nginx still boots when the backend is down

Compose stack (docker-compose.yml)
- postgres:17-alpine with pg_isready healthcheck and a named volume
- backend built from ./backend, gated on `service_healthy`, DATABASE_URL composed
  from POSTGRES_* so credentials stay in sync with the database service
- frontend published on ${FRONTEND_PORT}, all ports/credentials from .env
- documented external-database path via a git-ignored docker-compose.override.yml

Verification
- compose YAML parsed and asserted (services, deps, ports, no nested ${} defaults)
- `sh -n` clean for the entrypoint; `python -m app.cli.wait_for_db` tested against
  SQLite (ready, exit 0) and an unreachable Postgres (retries, exit 1)
- ruff clean on the new CLI module
- NOTE: no Docker CLI in this environment, so images were not built here.
2026-10-02 13:18:33 +08:00
moujitx e1a14abff6 feat(frontend): Vue 3 + Vite + TypeScript SPA managed with Yarn
Stack
- Vue 3.5 SPA built by Vite 6 with @vitejs/plugin-vue
- Yarn (classic 1.22) as the package manager, yarn.lock committed
- TypeScript in strict mode, vue-tsc project references for type checking
- vue-router 4 (lazy loaded routes, per-route titles) and Pinia 3 stores
- axios client with normalised ApiError handling

Structure
- src/api: client.ts (axios instance, error normalisation), health.ts, items.ts
- src/stores: app store (service metadata + health) and items store (CRUD state)
- src/views: HomeView (health dashboard), ItemsView (full CRUD demo), 404
- src/components: AppHeader, AppFooter, StatusBadge
- src/assets/styles/main.css: design tokens, light/dark themes, layout primitives
- dev server proxies /api, /docs and /redoc to the FastAPI backend

Tooling
- ESLint 9 flat config (vue + typescript-eslint + prettier integration)
- Prettier with a shared config
- scripts: dev, build, build-only, preview, type-check, lint, format

Verification (all green)
- yarn install: lockfile generated, exit 0
- yarn type-check: vue-tsc clean
- yarn build-only: production bundle emitted (dist)
- yarn lint:check and yarn format:check: clean
2026-10-02 13:16:41 +08:00
moujitx 12a456d9e7 feat(backend): FastAPI service with async SQLAlchemy and Alembic
Application layout
- app/main.py: app factory, lifespan (logging, SQLite folder, DB probe), CORS,
  versioned router mounted at /api/v1
- app/core: pydantic-settings configuration + structured logging
- app/db: declarative Base with naming conventions, TimestampMixin, async engine,
  request-scoped session dependency, health ping helpers
- app/models/item.py: example ORM model
- app/api/v1: health (liveness/readiness) and items CRUD reference endpoints
- app/schemas: pydantic request/response models

Database support
- async SQLAlchemy 2.x driving PostgreSQL (asyncpg) or SQLite (aiosqlite) by
  changing DATABASE_URL only; pool options applied for non-SQLite drivers
- Alembic wired to the app settings with autogenerate enabled (async env.py) plus
  an initial "create items table" migration
- the startup probe never blocks boot; readiness reports degraded on DB failure

Verification (all green)
- ruff check + ruff format: clean
- pytest: 14 passed (health, validation, CRUD, pagination, degraded DB path)
- alembic upgrade head / downgrade base / upgrade head against SQLite
- live uvicorn smoke test: health ok, CRUD round trip, /docs and OpenAPI 200
2026-10-02 13:16:36 +08:00
moujitx 9fa41c1bce chore: initialize repository scaffolding
- git repo on main branch
- .gitignore for Python/FastAPI + Node/Vue + env + Docker
- .gitattributes with LF normalization for container-safe text files
- .editorconfig, VS Code recommendations and settings example
- root .env.example documenting Compose variables
2026-10-02 13:08:07 +08:00