hezarfen_backend
Clone
0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits
hezarfen_backend
Rust/axum school-management API (auth, roles, exams, notes, messaging,
courses, attendance, pomodoro, meals) on PostgreSQL (sqlx). Swagger UI at /swagger.
Project docs — README.md, read sections not the whole file
README.md is ~355KB (~90k tokens). Never read it whole: grep for the ##
heading you need, then read that range. Its ## Endpoints table is GENERATED
(see Conventions); prose sections are hand-written.
Code map — orient here, skip discovery greps
Pattern: src/domain/<x>.rs = validated newtypes + entity. src/db/<x>.rs =
its SQL (the only layer that executes queries). src/service/<x>.rs =
workflows (one tx_with_retry transaction per invariant). src/web/<x>.rs =
DTOs + axum handlers, one file per resource, routes wired in lib.rs.
- core:
main(bootstrap)lib(build_router+OpenAPI)configconstant(limits)validateerrordatabase(PgPool + tx_with_retry + the two sqlx migrator sets)rate_limit(fixed-window per-IP)state domain/: user role session timestamp profile preferences note note_file message parent_link event attendance registration course course_session session_attendance enrollment subject term settings work_entry pomodoro exam exam_attempt exam_question exam_answer exam_result question_image menu menu_dish dietary_profile meal_booking meal_attendance meal_ledgerdb/: per-resource SQL;cap(count-cap CTE recipes + verdict types)field_updatepage(PagedList)service/: per-resource workflows (booking, minting, cascades)ai/: QUIC bridge to the out-of-process AI services (backend listens, services dial in).protocol(frames)server(AiBridge: listen+dispatch)registry(workers, capability routing)tlserror. Off unlessAI_QUIC_ADDRis set. Spec: README## AI bridge (QUIC).web/:extractor(CurrentUser/RequireTeacher/Manager/Admin)dto(shared responses)page(pagination)exam_ws(exam-room WebSocket) + per-resource: auth users notes messages events courses subjects sessions exams marks work pomodoro attendance settings terms mealstests/: integration(oneshot over per-test Postgres databases — tests/common mintsinit_test_tenants/init_test_db/deployment_with, template-clone) e2e(real TCP+cookies) rate_limit pagination persistence(idempotent re-migration over a live db) ai_bridge(real QUIC + fake AI service) ai_protocol(hab/2 wire contract; raw byte-level client, imports no protocol types — the only suite that catches a wire-format change)
Note: README ## Layout lags src/ (missing newer domain files); this map +
live ls src/ win on conflict.
Token discipline
- Open-ended "where/how does X work" sweeps: use the Explore subagent — keep exploration out of the main context.
- Quiet commands:
cargo test --quiet 2>&1 | tail -30,cargo build 2>&1 | tail -15. - Default for a small change: the scoped suite,
cargo test --test <file>(orcargo nextest run --test <file>). - Full suite:
cargo nextest run— runs the ~21 test binaries process-per-test in parallel instead of binary-serial. This repo has zero doctests, so nothing is lost vscargo test, which still works as a fallback.
Conventions
- No
PUT. Routes useGET/POST/DELETE/PATCHonly. - API contract changes move the utoipa annotations and the tag descriptions
in
lib.rsby hand. README's## Endpointstable is GENERATED — regen withUPDATE_DOCS=1 cargo test --test doc_sync; plaincargo test --test doc_syncfails on drift, so the suite gates it. README prose sections stay hand-written. - Pre-customer, so clean breaks are fine — but any validation change needs its stale-data impact analyzed first: existing rows may already violate the new rule.
- Commits are emoji + conventional type. Vocabulary in use:
feat,fix,docs,test,style,chore. Neverrefactor(unused in this repo's history).🎨 styleis reserved forcargo fmtcommits. - Code, comments and commit messages are English. Turkish survives only where it is the data under test (test fixtures, fold tables) or user-visible content (product defaults, OpenAPI examples and descriptions).
- Tests have two paths, and the DEFAULT one is GitHub's.
- DEFAULT — push, and GitHub does everything:
Clippy, the full suite on the runner, the release build, the pack and the deploy. - SPECIAL (faster) — run the full suite on this machine first, then GitHub
only packs and deploys.
scripts/gate-local.shruns Clippy + the whole nextest suite + the doc gate with CI's env (~10 min here vs ~55 min on a 4-core runner); on success it writes a stamp to.git/local-gate/<tree>.ok(inside.git, never committed) and prints aLocal-Gate: <tree> (<n> passed, <t>s)trailer. Put that line in the commit being pushed —scripts/gate-local.sh --amendappends it to HEAD, which cannot invalidate the stamp because an amend does not change the tree — and the workflow's "Decide test gate" step skips the runner suite. The step VERIFIES the trailer againstHEAD^{tree}; a stale or copy-pasted trailer silently falls back to running the suite. --scope <filter>is quick iteration only: a scoped run never produces the trailer, because the trailer is a claim about the full suite..githooks/pre-push(opt in per clone:git config core.hooksPath .githooks) refuses a forged or stale trailer — one whose tree is not the tree being pushed, or that claims a full-suite pass with no matching stamp on disk. It never blocks an ordinary untested push: that is the default path, and CI will test it.SKIP_LOCAL_GATE=1 git pushskips the hook's trailer check and says so. A manual redeploy'stestsdispatch input overrides the trailer logic in the other direction:forceruns the suite on the runner for that ref,auto/skipredeploy the newest green artifact.- A red local gate is the definition of not-done: never push on one.
- DEFAULT — push, and GitHub does everything: