A derived, mostly-computed model of how programs, deployments, and repos relate,
plus the git-sync surfaces that motivated it. See docs/relationships.md.
Core:
- `requires: [{kind, ref, version?, bind?}]` on programs + deployments — one
precondition relation; `system_dependencies` is its `{kind: system}` alias.
kind fixes meaning + check (system=installed, deployment=exists).
- relations.py: derives repos (git toplevel / monorepo), fan-in, and the
predicates functional?/fresh?/deployed? — nothing stored.
- env is generated FROM a `{kind: deployment, bind}` requirement (target URL →
consumer env), never scraped back into one; explicit defaults.env still wins.
- git.py: working-copy status/pull, repo toplevel + remote url.
Surfaces:
- `castle graph` + GET /graph — the relationship diagnostic.
- GET /repos, /repos/{key}/git|sync — repo-scoped sync (a repo is the sync unit;
a monorepo backs several programs). GET /programs/{name}/git|sync + repo context.
- Dashboard: Graph screen, program-page git status + repo-aware Sync, and a
monorepo banner on Programs.
Governing principle: predicates are derived; encode only the non-derivable, as a
node or edge property. Pull-only sync — converge stays a separate step.
31 lines
926 B
Python
31 lines
926 B
Python
"""The relationship model as JSON — repos, `requires` edges, derived status.
|
|
|
|
Read-only diagnostic (see docs/relationships.md). Everything is computed on the
|
|
fly: repos from git, predicates (functional/fresh) from config + git. Nothing
|
|
stored.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import dataclasses
|
|
|
|
from fastapi import APIRouter
|
|
|
|
from castle_core.relations import build_model
|
|
|
|
from castle_api.config import get_config
|
|
|
|
graph_router = APIRouter(tags=["graph"])
|
|
|
|
|
|
@graph_router.get("/graph")
|
|
def get_graph() -> dict:
|
|
"""The whole relationship model: repos (with freshness), deployment nodes (with
|
|
`functional?`), and `requires` edges."""
|
|
model = build_model(get_config(), check=True, freshness=True)
|
|
return {
|
|
"repos": [dataclasses.asdict(r) for r in model.repos],
|
|
"nodes": [dataclasses.asdict(n) for n in model.nodes],
|
|
"edges": [dataclasses.asdict(e) for e in model.edges],
|
|
}
|