# Campus and Domain Model ## Purpose Campus is the top-level administrative and language-default boundary. Domain is the host-selected subdomain space presented to a request. Every Domain belongs to exactly one Campus. This slice intentionally stops before ZoneTree. Quartier, Street, Spot, and SpotGraph remain later topology work. ## Identity Both Campus and Domain have: - an integer SQLite row ID for local administration; - a stable UUID for relationships; - a normalized, unique machine name; - a human-readable title; - an enabled flag; - a creation timestamp. Campus additionally has a BCP 47 default language, authority mode, and FQDN. Domain additionally has a host selector. A selector can be a full host (`docs.example.test`), a subdomain label (`docs`), or empty to select the Campus FQDN itself. ## Ownership invariants - Every Domain `campus_uuid` resolves to an existing Campus. - At least one Campus exists and at least one Campus remains enabled. - A Campus referenced by a Domain cannot be deleted. - A Campus referenced by a Domain cannot be disabled. - Creating or moving a Domain requires an enabled target Campus. - Disabled Domains do not participate in request-host selection. - Request-host resolution is exact and has no last-resort Domain fallback. - An empty Domain host matches only its owning Campus FQDN. - The request Campus is derived from the resolved Domain; it is not selected independently. SQLite does not currently rebuild legacy tables to add a foreign-key constraint. These invariants are enforced by store operations so existing installations can migrate without destructive table replacement. ## Schema ```sql CREATE TABLE campuses ( id INTEGER PRIMARY KEY AUTOINCREMENT, uuid TEXT NOT NULL UNIQUE, name TEXT NOT NULL UNIQUE, title TEXT NOT NULL, default_lang TEXT NOT NULL DEFAULT 'en', authority_mode TEXT NOT NULL DEFAULT 'standalone', fqdn TEXT NOT NULL, enabled INTEGER NOT NULL DEFAULT 1, created_at INTEGER NOT NULL ); -- Added to domains during initialization: ALTER TABLE domains ADD COLUMN campus_uuid TEXT; CREATE INDEX idx_domains_campus_uuid ON domains(campus_uuid); ``` ## Startup migration Initialization is idempotent: 1. The existing District-to-Domain compatibility migration runs. 2. If no Campus exists, `Default Campus` is created. 3. The nullable `domains.campus_uuid` column is added when absent. 4. Empty, unknown, and legacy Campus references are assigned to the enabled default Campus. UUIDs, Domain host selectors, and existing paths are preserved. ## Request context The server resolves one Domain from the HTTP Host and then resolves its owning Campus. Both values are exposed as `RequestContext.Domain` and `RequestContext.Campus`. Revision language selection uses this order: 1. explicit language request; 2. request language preferences; 3. Campus default language; 4. system locale; 5. language-neutral revision; 6. latest revision. ## Administration The Config view supports Campus create, update, and delete, as well as Domain assignment to a Campus. The last enabled Campus cannot be disabled. A Campus must first have its Domains moved or deleted before it can be deleted. The data CLI remains object/path/revision/asset oriented. Campus and Domain administration is therefore not added to the CLI in this slice.