Docs Platform
Data model
How tenants, courses, customers, enrollments and events relate, and what the database guarantees.
Principles#
- Explicit over implicit. Access, grouping and completion are real, typed rows. No tag silently drives behaviour.
- One way to do each thing. Enrollment is the only access mechanism. A question lives in exactly one bank.
- Published content is frozen. Learners and their results always point at exactly what they saw.
- The database enforces the invariants. They are constraints, not conventions, and tests prove them.
- API-first. Every state change emits an event.
Map#
tenant ─┬─ organization ─┬─ organization_member ─► member_role ─► role_course_assignment
│ ├─ license ─► product ─► product_course ─► course ; license_seat
│ └─ invitation
├─ app_user, api_key, asset, certificate_template
├─ course ─► course_version ─► module ─► lesson ─► lesson_block ─► assessment ─► assessment_item
├─ question_bank ─► question ─► question_version (immutable)
├─ enrollment ─┬─ lesson_progress
│ ├─ assessment_attempt ─► attempt_question (frozen paper)
│ └─ certificate (snapshot)
└─ outbox_event ─► webhook_delivery ─► webhook_endpoint ; audit_log
Guarantees the database makes#
- Tenant isolation. Every tenant-owned table carries
tenant_id, and children reference parents with composite foreign keys(tenant_id, id). A row cannot reference another tenant’s row, even if application code has a bug. - One draft and one published version per course.
- One active enrollment per person per course. Retakes are allowed after completion.
- A role-driven enrollment must trace to a license and a membership. The learner must be, or have been, a member of the organization that holds the license.
- Licenses are idempotent on
externalRef, and a person can occupy a seat only once. - One pending invitation per email per organization.
- Question versions are immutable. Updates and deletes are rejected by a trigger.
- A quiz item is exactly a question or a pool.
Conventions#
- Text plus
CHECKconstraints instead of native enums. timestamptzeverywhere. UUID primary keys.- Mutable aggregates carry a
versionfor optimistic locking. - History is never hard-deleted: content and people are archived, certificates revoked, members marked removed.
- Reordering is one transaction using deferrable unique constraints.
Enrollment sources#
DIRECT, COHORT, ROLE, API, SELF. Each enrollment records why it exists, and for role-driven ones, the organization, license and role.