This file is read first by Claude Code (and any other agent following the convention). It tells you what this project is, what state it is in, and the conventions you must follow when contributing.
LearnStack is a white-label platform for multi-branch education businesses that teach live. Its endorsed product direction adds an optional LearnStack-branded Course Marketplace while preserving independent institution sites. ADR-0049 and Phase 09a remain Proposed; marketplace architecture, commerce and delivery are not implemented or Accepted. One binary, one schema, and one set of container images serve a language school, a yoga studio, a music school, or a coding bootcamp. What differs between them is tenant customization data loaded at provisioning, not code (ADR-0018).
That claim has a stated edge, and the edge lives in exactly one place: Platform Vision § Genericity boundary. Content shape, presentation, and pure rule evaluation are tenant data. Stateful entitlement (credit packs, session quotas) and external capability invocation (running submitted code, scoring speech) are platform features gated by plan — they need a release, not a customization row. Link to that section; do not restate it.
LearnStack targets three production deployment modes — SaaS, Dedicated,
Self-Hosted — with current readiness recorded in
Deployment Models.
The companion LearnStack Hub control plane lives in a separate repository (see
ADR-0019). On developer
workstations the Hub repo is the sibling directory ../LearnStack-Hub;
GitHub: https://github.com/HodeTech/LearnStack-Hub. The Hub repository
owns its own roadmap at ../LearnStack-Hub/docs/roadmap/; this
repository holds only LearnStack's side of the boundary, in
Phase 02c.
Phase 01, Phase 02a, Phase 02d and Phase 02b are complete; Phase 03 is in progress. Phase 02d owns the two-tenant walking skeleton. Phase 02b owns the delivered events, background jobs, API authentication and session baseline. Phase 03 owns identity, membership and authorization work; its Status block records current packet state. Acceptance of a contract does not complete its implementation. Phase 06 owns the full renderer/Studio expansion.
Status lives in one place. Each phase document's Status block owns packet
state and its decision register owns gate state; the phase's delivery log
(docs/roadmap/phase-<id>-delivery-log.md) owns the dated decision packages, step
records, reviews and closeouts
(ADR-0069). This
section stays a pointer: it links phase documents, never a delivery log, and does
not restate a packet's history.
What the kernel already guarantees — tenancy and Row Level Security isolation, the audit write path, the entitlement socket, the API conventions and the foundation ports — is recorded packet by packet in Phase 02a, whose delivery records are frozen history, together with the 2026-08-08 restructure that moved correctness earlier, additive infrastructure later and proof earlier.
Five modules hold domain code: Tenancy, Customization, Audit, Education and
Identity. Content and Media remain scaffolded. Module-level references in the docs
to types such as ILiveClassProvider or ITenantSearch describe intended shape
owned by their named phases.
For any task, read in this order:
- README.md — direction at a glance.
- docs/architecture/01-platform-vision.md — what we build and why.
- docs/architecture/05-mvp-scope.md — what is in / out / deferred.
- docs/roadmap/README.md — phased plan with explicit dependencies and the one-way-door sequencing principle.
- docs/standards/00-principles.md — the beliefs every other standard descends from.
- docs/glossary.md — terminology; the single source of truth for project-specific terms.
Then read the current phase and the completed baselines it stands on:
- docs/roadmap/phase-03-identity-admin.md — the current phase. Read its identity, membership, authorization and first-writer decisions before planning code.
- docs/roadmap/phase-02b-events-auth.md — complete. Its Status block owns packet state; its decision register owns gate state and links each Accepted decision package in the delivery log, which is normative — read it before writing the code its gate governs. Navigate a delivery log by the generated index at its top; never read the whole file.
- docs/roadmap/phase-02d-walking-skeleton.md —
complete; the delivered public-site baseline. It sorts after
02b/02cbut runs before them: the roadmap dependency map, not filename order, is authoritative. - docs/roadmap/phase-02a-kernel-tenancy.md — complete; the authority on what the kernel already guarantees, not on what to build next.
Once the high-level reading is done, pick exactly one skill entry point based on the user's intent. The entry point dispatches the rest internally; do not chain entry points yourself.
| Intent | Entry point |
|---|---|
| "Implement / geliştir / yap / ekle / refactor X" (substantive work) | implement-task — the default. Dispatches start-task in Step 1, then the workflow-specific add-* skill(s), then runs linter + tests, updates docs, commits, and emits a review-agent prompt. |
| "Plan / scope / orient / araştır / kapsamı çıkar" (no implementation yet) | start-task — standalone scoping pass. Stops at the plan. |
| "Review this diff / PR" | standards-check first (5-min mechanical gate), then code-review (security + bugs + optimisation + refactor + LearnStack-specific lenses). |
| "Explain / what is X" (informational) | No skill — answer directly. |
| One-line typo / comment fix | No skill — edit directly. |
The full skills catalogue lists every workflow skill
(add-tenant-owned-entity, wire-dapr-pubsub, add-tenant-scoring-rule, …) the
entry points dispatch to. You almost never invoke a workflow skill directly —
let the entry point pick it.
| Directory | Purpose | Mutability |
|---|---|---|
docs/architecture/ |
Conceptual descriptions of what we are building. Numbered NN-topic.md linearly. |
Editable as the system evolves. |
docs/decisions/ |
ADRs — one-time decisions with status, context, decision, consequences. Redirect / superseded ADRs live under _redirects/. |
Accepted ADRs are immutable except for dated Amendments and the two bounded corrections in Documentation Standards § Correcting and Amending ADRs (ADR-0041). |
docs/standards/ |
Engineering rules (NN-topic.md, 00 – 21). Each anchored standard carries a **Derives from:** ADR-NNNN header. |
Editable as the team learns; standard changes cite an ADR. |
docs/roadmap/ |
Phased plan (phase-NN-topic.md, 00 – 12 with 02a/02b/02c/02d, 08a/08b/08c, and 09/09b splits). Every phase doc carries the same six sections — Goal, Scope, Deliverables, Completion Criteria, Risks, Phase Exit Decision — with three declared exceptions listed in the roadmap index: Phase 09b and Phase 12 are pointer documents into the Hub repository, and Phase 01 predates the convention. A phase with packets keeps its dated records — decision packages, step records, reviews, closeouts — in a sibling phase-NN-delivery-log.md (ADR-0069); Phase 02a keeps its legacy single-file shape. |
Phase doc editable per phase, its Status block holding packet state only. The delivery log is append-only: a shipped packet's records are not rewritten, and an Accepted decision package there is normative. |
docs/modules/ |
Per-module specifications (<module>/README.md + permissions.md + audit.md), one directory per module, created with the first spec — Tenancy, Phase 02a Packet 6, Customization, Packet 8, and Audit, Packet 9. The ten sections are fixed by Documentation Standards. |
Editable with the module. |
docs/glossary.md |
Terminology source of truth. | Editable; new term goes here first, then used. |
docs/analysis/exists locally but is gitignored — it is a private scratchpad for exploratory research, prior-art studies, and redesign drafts. Never reference paths underdocs/analysis/from committed files (Markdown, code comments, commit messages, PR descriptions). See Documentation Standards § Local-Only Directories.
- English is the documentation language (ADR-0007). The Turkish-facing UI of any tenant is separate.
- Mermaid for diagrams in fenced
```mermaidblocks. Diagrams must remain readable in text form (titles + bullet fallbacks) for renderers that don't support Mermaid. - Single source of truth. Each piece of knowledge lives in exactly one place. The glossary holds terms. ADRs hold decisions. Standards hold ongoing rules. Architecture docs hold conceptual descriptions. Roadmap holds phases. Do not duplicate.
- ADR numbers are sequential and never reused. Superseded ADRs become redirect stubs under
decisions/_redirects/. Adding a new ADR uses the next free number. - Standards changes cite an ADR. A new standard rule or a change to an existing one is paired with an ADR when the rule is non-trivial.
- Modular monolith with four cross-module mechanisms (ADR-0010): application contract, intra-module domain event, integration event via outbox (dispatched through
IEventBus—InProcessEventBustoday, the Dapr/Kafka adapter on its trigger), read-model projection. No fifth. - Tenant + organization isolation is defense-in-depth from day one (ADR-0003 Amendment 1, ADR-0017): tenant + organization context + EF query filters + PostgreSQL RLS + architecture tests.
- One canonical RLS template, in one file. The corrected policy shape — one
AND-ed policy per table,ENABLEandFORCE ROW LEVEL SECURITY, an explicitWITH CHECK, and the four-role model (learnstack_migrationowns,learnstack_appconnects withNOBYPASSRLS,learnstack_platformandlearnstack_outbox_adminhold audited bypasses) — is decided in ADR-0003 Amendment 3 and written as SQL in exactly one document: Database Standards. Every other document links there. The superseded template lived in four documents and was wrong in all four — two permissive policies, which PostgreSQL combines withOR, so every tenant-wide row was visible across tenants. - Self-hosted infrastructure preferred for Keycloak (auth, with two realms —
learnstack+learnstack-hub), LiveKit OSS (live classroom), SeaweedFS (object storage), Meilisearch (search), Kafka (pub/sub backend), Vault (secrets). See ADRs 0004, 0005 and 0038 (which superseded 0014). What LearnStack uses is settled; when each arrives is ADR-0035's trigger table. - The core platform stays domain-generic. Domain-specific shapes (CEFR levels, English placement-test scoring, kyu/dan ranks, yoga asana catalogs, …) live as tenant customization data (ADR-0018), never as code in any module. There is no
Verticals/folder. ADR-0011 is superseded. The boundary of that claim is in Platform Vision § Genericity boundary. - Irreversible now, additive on demand — the one-way-door test (ADR-0035): if I add this six months from now, will I have to touch code that is already written?
- Yes → ship it now. Tenant + organization isolation, the corrected RLS policies, the
outbox_messagestable and its ownership, strongly-typed identifiers, the localization schema, MUST-class audit durability, module boundaries and their architecture tests. These touch every query, every migration, and every job payload. - No → ship the port now, the adapter on a named trigger. Dapr pub/sub, Kafka, Valkey-backed cache, Vault, APISIX, the Hub entitlement source, signed licence keys, custom-domain TLS automation,
audit_logpartitioning. Each has a port inLearnStack.SharedKernelwherever ADR-0035 § The gated set names one, a working default implementation (InProcessEventBus,InMemoryCacheService,ConfigurationSecretProvider,NullEntitlementProvider), an owning phase, and a written trigger condition. A building block missing any of those, other than a port that table records as absent, is not demand-gated — it is missing.
- Yes → ship it now. Tenant + organization isolation, the corrected RLS policies, the
- Provider adapters everywhere. Payments, auth, storage, search, live classroom, notifications, event bus, cache, secrets, Hub contract, entitlement source, host resolver — all sit behind interfaces. No SaaS lock-in in
DomainorApplication. See 20-infrastructure-stack.md. - The Hub contract is governed by two invariants, not by a count (ADR-0034): (1) the Hub stores no tenant content — courses, lessons, learners, enrollments, sessions and media live only in LearnStack, and the Hub holds tenant metadata only; (2) every LearnStack↔Hub crossing goes through a named adapter —
IEntitlementProvider,IUsageReporter,IHubTenantSync, and nothing else may hold a Hub client. Adding an endpoint still requires an ADR, because the surface is a cross-repository contract both repositories have to agree on. - One binary, five
DeploymentModevalues. Selection happens at the composition root; module code never branches on the mode (ADR-0020, enforced byModules_Do_Not_Reference_DeploymentMode). Deployment Models § Supported today versus prepared seam owns the current foundation wiring, remaining adapters and production-readiness boundary; a selectable enum value is not a supported deployment.
- Short and declarative — heading + bullets over essay paragraphs.
- Present tense decisions ("LearnStack uses ..."), not future tense ("LearnStack will use ...").
- Cross-link liberally — to glossary, related architecture docs, standards, ADRs. Use relative paths.
- TODO comments include a date and an owner:
// TODO(YYYY-MM-DD, @owner): refactor when X lands. - Don't redefine glossary terms in other docs; link to them.
Once application code lands, the engineering standards under
docs/standards/ are the authority for every PR. The most load-bearing
rules:
- C# / .NET 10, strongly-typed ids, records, MediatR pipeline, EF Core
with per-module
DbContext(02, 05). - TypeScript strict + Next.js App Router; one frontend app under
frontend/apps/webwith route segments (03, 07). The operator portal is a separate app,frontend/apps/operator-portal, in theLearnStack-Hubrepository. - REST + RFC 7807 Problem Details + cursor pagination + idempotency keys + ETag concurrency (04).
- OpenTelemetry + correlation id end to end (10).
- WCAG 2.2 AA across all surfaces (16).
- Audit-coverage matrix required per module (18).
- Global User identity consumes the existing typed
UserId; global and tenant transaction owners never join or retarget each other (ADR-0072). - Permission keys
{module}.{resource}.{action}with closed action set + scope (Platform / Tenant / Organization) (19). - Infrastructure-stack rules (foundation ports and their default implementations, the Hub contract surface, outbox + inbox, entitlement projection) in 20.
- The architecture-test catalogue in 21 — canonical rule names live there; do not invent a second spelling.
- Zero-tolerance review blockers enumerated in 17.
- Conventional Commits style:
type(scope): subject. - Subject in imperative mood; ≤ 72 chars.
- For doc-only commits:
docs(scope): ...where scope is one ofarchitecture,decisions,standards,roadmap, or omitted for cross-cutting changes.
- Edit an Accepted ADR's body, except by the two bounded mechanisms ADR-0041 defines: an inline erratum beside the false text, which is the default, or in-place replacement where the text is a canonical artifact for reuse — a template others are told to copy, a DDL or command meant to be applied. Both are for a statement that was false when it entered the record, both leave § Status / § Date / § Deciders and all rationale untouched, and both owe a dated Amendment in every Accepted ADR the diff changes. A statement that was true then and is stale now is history: amend it, or write a new ADR that supersedes the old one.
- Introduce a fifth cross-module communication mechanism.
- Add domain-specific code (CEFR, exam, English placement, kyu/dan,
asana, code-challenge runner, …) to any module. Such shapes live
as tenant customization data per
ADR-0018.
There is no
Verticals/folder; the architecture testNo_Source_Folder_Named_Verticalsenforces it. - Add an endpoint to the Hub contract surface without an ADR. The count is not the rule — ADR-0034's two invariants are — but the surface is a cross-repository contract, so it changes by decision record, in both repositories, or not at all.
- Call Hub endpoints from anywhere except the dedicated
IEntitlementProvider/IUsageReporter/IHubTenantSyncadapters. - Resolve a host by calling the Hub.
IHostToTenantResolverreadsplatform_host_to_tenantand nothing else (ADR-0034); an anonymous page load must never depend on a control plane being reachable. - Carry TLS certificates or private keys in the entitlement payload. Cert
material moves by secret-store replication and is referenced by path
from
PUT /api/internal/tenants/{id}/host-mappings, never by value through a payload LearnStack caches, logs, audits and mirrors. - Append a dated packet record to a phase document, or narrate packet status
anywhere but its Status block. Decision packages, step records, reviews,
corrections and closeouts are entries in the phase's delivery log. This file and
the repository README point at the phase document and link no delivery log, and
the roadmap index's § Phases links none either
(ADR-0069).
scripts/roadmap-structure.pyfails the build otherwise, andscripts/markdown-fragment-audit.pyfails it on any anchor a move leaves broken. - Copy the RLS template into a second document. It lives only in Database Standards; everywhere else links to it. The last duplication shipped a broken policy into four files at once.
- Run a tenant- or organization-isolation test as the table owner or as a
BYPASSRLSrole. Isolation tests connect aslearnstack_app— a test that runs aslearnstack_migration,learnstack_platformorlearnstack_outbox_adminpasses even when every policy is inert, and therefore proves nothing. - Write a MUST-class audit row outside the business transaction. MUST-class
audit is written on the same transaction as the state change it describes
(ADR-0033) —
AuditLogBehaviorclassifies and parks the intents,TransactionBehaviorwrites them immediately beforeCOMMIT— so they commit with that change or not at all, and so they execute whileapp.tenant_idis set and RLS accepts it. "The sameSaveChangesas the business write" was the earlier formulation and ADR-0033 withdraws it: the guarantee is the transaction, which is what a reader ofaudit_logobserves and which needs no cross-DbContextmachinery. A tenantAuditConfigmay narrow SHOULD/MAY coverage but never removes baseline MUST coverage. Exactly two failures reject the operation: an operation the catalogue does not classify at all, and a MUST-class row that cannot be written durably. A tenant-override read failure does not — it falls back to the in-process catalogue, which carries the same MUST floor, so nothing proceeds unaudited and a cache outage does not deny every request platform-wide. The second of those two is narrowed for the standalone class by ADR-0033 Amendment 1: a standalone MUST-class write failure changes the response only when the operation would otherwise have succeeded. A row recording an operation already being refused — adeniedauthorisation outcome, a rejected tenant assertion — keeps its own 403 / 404 and logs atCritical; downgrading a refusal to a503an anonymous caller can provoke tells them more, not less. The in-transaction class is untouched. - Write one audit row per request when the request audits two resources.
Intents are plural (ADR-0044, and
ADR-0033 Amendment 2): one per
audited
(resource, operation), held as an ordered list, and only the owning unit-of-work frame writes them or reports the commit boundary — a joiner that reportsCommittedclaims durability for a row nothing committed.ProvisionTenantCommandis the shipped case: two aggregates, one transaction, two MUST rows. - Write two instances of an operation's declared aggregate without naming which one
the row is about. A row describes one instance. A handler that writes two — a
publication retires the incumbent and activates the successor — calls
IAuditSubject.Designate(aggregate), and the other instance travels inchangesunder its own instance-qualified pointer; undesignated, the composer refuses the pair and the request fails closed. An entity the aggregate contains through a navigation needs nothing: it is captured inside the aggregate's row (ADR-0044 Amendment 6). - Declare an audit value type in the Audit module's
Domain.LearnStack.SharedKernel.Auditholds the value types beside the ports —OperationType,OperationClass,AuditOutcome,AuditClassification,AuditIntentStateandCapturedEntityChange(ADR-0044 Amendment 3) — becauseAuditIntentandAuditEntryDraftare SharedKernel records that name them and every module'sIAuditCatalogSourcenames the first two. Declaring them in the module is a project cycle.AuditEntryconsumes them; it does not declare them. - Announce
TenantId.PlatformSentinelas a request's tenant. Exactly two named classes of audit row may carry it: platform-scope standalone operations and ADR-0072 globalidentity.user.createattempts under its confined common owner. Neither class grants tenant authority or permits a tenant setter to announce the sentinel. Packet 9 puts the guard where the value enters:SetProvisioningTenantContextAsyncrefuses the sentinel exactly as it already refusesGuid.Empty, andTenant.Createrefuses it in the factory (ADR-0044 Amendment 3). ThetenantsCHECK is the backstop, not the control — a constraint cannot stop a GUC from being announced. - Store a killswitch in
tenant_feature_flags. That table has a foreign key totenantsand the platform sentinel deliberately has notenantsrow, so the write is refused — and a foreign key is a constraint no role and noBYPASSRLSmoves. Killswitches live in the platform-scopedplatform_killswitches(ADR-0045). Packet 9 shipped that table, its policies, the overlay and its cache family; the single writer isKillswitchToggle, which enters the platform scope only with aPlatformAdmissionthe operator gate minted for an authenticated operator holdingplatform.killswitch.write(ADR-0101, runbook), and the architecture rules pin that no other file writes the table. - Read
platform_entitlement_cachefrom a module,IFeatureFlagsincluded. The only sanctioned reader and writer is anIEntitlementProviderimplementation;IFeatureFlagscomposes over the port, which is what makes swapping the registered provider change the answer. - Spell a limit key in LearnStack's own vocabulary. The limit-key set is the
Hub's, under the
limits.prefix, because the Hub has merged code and two plan validators built on it and this side has a declaration and no implementing line (ADR-0045 Amendment 1, ADR-0021). The earliertenancy.max_learners/classroom.minutes_per_month/media.storage_gbspellings are withdrawn: a key the Hub never sends misses on every real projection and falls through to the catalog default, so a paid tenant reads as unentitled and the read reports success. The feature-key set is not changed with it. - Inject
IConnectionMultiplexer/IDistributedCache/KafkaProducer/VaultClientdirectly — useIEventBus/ICacheService/ISecretProvider. - Read
DeploymentModefrom inside a module — the composition root branches once, modules never. - Write
audit_log,platform_entitlement_cache, or produceroutbox_messagesrows directly — useIAuditStore,IEntitlementProvider.RefreshAsync,IOutbox. Only ADR-0046's confined dispatcher and ADR-0103's confined operator recovery owner write outbox status through fenced parameterized SQL; each terminal or recovery UPDATE and its narrow witness-bound audit INSERT share one transaction. - Write
inbox_messagesorevent_deliveriesfrom a module or Seeder. ADR-0046's transport-owned acceptance, inbox/business owner and confined scheduler alone write their granted columns. - Write rows through EF Core's set-based APIs —
ExecuteUpdate,ExecuteDelete,ExecuteSql*. The audit capture sees only what theChangeTrackerholds (ADR-0044 § 7), so such a write commits with no before, after or changes and nothing fails;No_Set_Based_Write_Bypasses_The_Audit_Captureenforces it. - Accept
learnstack-hubrealm tokens on tenant-facing endpoints, orlearnstackrealm tokens on/api/internal/*. - Reuse an ADR number.
- Add an architecture or standard document whose existence makes one of the existing documents ambiguous about ownership; if a topic needs more space, expand the existing doc rather than splintering.
- Mention a feature as "deferred to a later phase" without naming the phase that owns it. For an infrastructure building block the bar is higher: name the port, the default implementation, the owning phase, and the trigger condition (ADR-0035). Three out of four is not demand-gating.
- Throw
DomainExceptionfor expected business-rule violations — useResult.Fail(business_rule_violation, ...).DomainExceptionis reserved for programmer errors / aggregate invariant bugs (ADR-0032 § Sub-decision 4). The Roslyn analyzerLearnStackException-DomainExceptionThrowflags violations; full catalogue entry in docs/standards/21-architecture-tests-catalogue.md. - Silence the production
LS0002sensitive-exception-message guard project-wide. Its automatic wiring and bounded scope are in the same catalogue. A clean report is not data-flow secrecy or a redaction guarantee. - Throw
FluentValidation.ValidationExceptionfromValidationBehavior— the behavior returnsResult.Fail(validation_failed)and never throws. - Reference
Sentry.SentrySdkdirectly from any module assembly — error capture goes throughIErrorTrackingProvider; the L1IExceptionHandleris the only sanctioned caller in application code. - Add an
ExceptionHandlingBehaviorto the MediatR pipeline —AuditLogBehavior(catches handler exceptions, audits, rethrows viaExceptionDispatchInfo) plus the L1IExceptionHandlercover every exception path. - Register the OpenTelemetry
LoggerProvider(AddOpenTelemetry().WithLogging()) alongside Serilog. Logs flow through Serilog → OTLP sink only; double-export would duplicate every line. - Import
Serilog.ILoggerfrom a module assembly — modules useMicrosoft.Extensions.Logging.ILogger<T>; Serilog is the implementation wired once at the composition root. - Import a provider SDK exception type outside the adapter's
LearnStack.Infrastructure.<Adapter>namespace — adapters translate SDK exceptions intoProviderExceptionsubclasses at the boundary. - Tag a span with
tenant.id/organization.id/user.id/correlation.idfrom module code — theTenantContextSpanProcessorenriches every span centrally.
- Term means what? — docs/glossary.md.
- Why was this decided? —
docs/decisions/. Each ADR carries context. - What rule applies to my change? —
docs/standards/. The index is in docs/standards/README.md. - What's next? — docs/roadmap/README.md.
- What's the shape of the live classroom / auth / search / etc.? —
the corresponding
docs/architecture/NN-topic.md.