Spec: Legal journey platform — the matter spine¶
- ID: 036-legal-journey-platform
- Status: planned
- Owner: @bamr87
- Created: 2026-08-17
- Roadmap Epic: whole-legal-journey platform (user directive 2026-08-17; PRD §5 Phase 2 "user workspaces, project folders", §8.1 Dashboard/Library)
- Constitution Compliance: confirmed against docs/constitution.md — no amendment required; §1 (local-first reachable, no third vendor), §4 (provenance, soft-delete), §5 (HITL on new agent output paths), §13 (power-aware outputs) each addressed below
1. Problem & Motivation¶
The platform's stage-local capabilities are real: ingestion feeds a knowledge graph, GraphRAG-backed agents produce IRAC analyses, the graph explorer renders precedent networks, and the LSAT Lab teaches. What does not exist is the connective tissue that would make these a journey:
- Nothing persists.
POST /api/analysisbuilds a fullAnalysisResponse— IRAC, precedents, agent trace — returns it, and forgets it (backend/law_ai/analysis/urls.py; the gap is BL-20260429-25). LSAT progress lives in browserlocalStorage. A user who did an hour of research yesterday starts from zero today. - Nobody exists. The API authenticates scope-keys, not people (
law_ai.core.models.ApiTokenhas no user link). There is no way to say "my matters", no reviewer identity on HITL decisions (BL-20260811-04), no per-user anything (BL-20260503-05, BL-20260811-06 are all blocked on this). - Nothing represents the matter. A legal journey — a dispute, a filing, a research question, a course of study — has a beginning, accumulating artifacts, and stages. The platform has no noun for it, so it cannot answer the only question a journeying user actually has: where am I, and what should I do next?
The goal set for this epic — a platform that facilitates the whole legal journey — therefore reduces to building the spine: user accounts + a durable Matter workspace that threads every existing stage capability + a navigator over that state, and then attaching each stage (intake → issues → research → analysis → drafting → action → resolution, plus the parallel learning journey) to it.
2. Origin & Background¶
Origin. User directive (2026-08-17): "build a platform that can facilitate the whole legal journey." Roadmap anchors: PRD §5 Phase 2 (workspaces, project folders, export), §8.1 (Dashboard, Library, persistent tabs per matter); Law AI proposal collaboration layer.
Backlog items claimed by this spec (moved to ## Claimed in BACKLOG.md):
- BL-20260429-25 — persist analyses (request + response + trace ids) in Postgres so users can revisit a run — becomes matter-scoped artifact persistence (FR-6).
- BL-20260429-26 — "save & share": bookmark an analysis with a slug and produce a shareable URL (FR-9).
- BL-20260503-05 — persist per-user LSAT attempt history once auth lands (FR-14).
- BL-20260503-13 — auth on top of
core.ApiToken— delivered as first-class Django user accounts with session auth for the frontend plus per-user API tokens; the JWT/OAuth mechanism named in the item is deliberately deferred (see §12 RQ-1). - BL-20260811-04 — reviewer identity as a real user FK on HITL decisions instead of free text (FR-2).
Related, deliberately left open: BL-20260811-06 (per-user quotas — unblocked by FR-2, but quota policy is guardrails work), BL-20260803-01 (disposition metadata — feeds the resolution stage later), BL-20260503-12 (per-token rate limiting), BL-20260811-05 (counsel review of UPL wording — this spec adds surfaces that inherit that open review).
Constitution §13 review question — who is the stronger here, and what does this feature do for them? The journey platform's beneficiary is the party without institutional process memory: the pro se litigant, the legal-aid or solo lawyer without a docketing system, associates, or a matter file that survives the week. Repeat players already have all of this; a matter spine hands the one-shot player the repeat player's memory. Two §13 hazards follow and are bound here: (a) the navigator (FR-11) recommends process steps grounded in the matter's own state, never outcome predictions — "similar parties usually lose" framing is prohibited by schema (AC-6), because that would launder the corpus's victor bias into advice; (b) every authority surfaced inside a matter keeps the platform's existing attribution and coverage-envelope labelling (philosophy P1–P5) — the journey layer adds navigation, never a new authority score.
3. Goals¶
- G1: One durable, user-owned Matter threads intake → issues → research → analysis → drafting → action → resolution; every existing stage capability can attach its output to it.
- G2: Nothing a user produces vanishes: analyses, research runs, notes, drafts, and intake facts persist as matter artifacts with full provenance.
- G3: A journey navigator tells the user where they are and what grounded next steps exist — process guidance, never legal advice, never outcome prediction.
- G4: Confidentiality is a per-matter property: a matter marked confidential pins every LLM call in its context to the local tier (constitution §1's
ollamapin), enforced in code, visible in provenance. - G5: The learning journey persists per user (LSAT attempt history server-side), so the student track rides the same spine as the practice track.
- G6: Everything anonymous keeps working — accounts add capability, they never become a wall in front of existing flows.
4. Non-Goals¶
- NG1: E-filing, court/PACER integration, or deadline-rule computation. The action stage records what the user logs; it does not talk to courts (follow-up BL-20260817-02).
- NG2: Practice-management accounting (time capture, billing, invoicing, trust ledgers).
- NG3: Organizations, teams, roles, SSO. Ownership is single-user + revocable read-only share links; workspace RBAC stays future work.
- NG4: Outcome prediction or party-success scoring, in any stage. Prohibited framing per constitution §13 — see AC-6.
- NG5: New runtime LLM vendors, new top-level frameworks, or Neo4j schema changes. The journey spine is workspace state and lives in Postgres; the knowledge graph is referenced by id, never mutated by this spec.
- NG6: Client-to-lawyer matching or referral. The platform facilitates the journey; it does not broker representation.
- NG7: Document upload/ingestion of user files into the corpus. Matter artifacts hold user-authored and agent-produced content; corpus ingestion keeps its own quarantined pipeline.
5. User Stories¶
- As a pro se litigant, I want to describe my situation in plain language and get a structured matter with spotted issues and a map of what comes next, so that I can navigate a process built for professionals.
- As a solo practitioner, I want yesterday's research and analyses attached to the matter I ran them for, so that the file builds itself as I work instead of living in my browser history.
- As a lawyer under a confidentiality obligation, I want to mark a matter confidential and know that no prompt text from it reaches a third party, so that I can use the platform on privileged facts (constitution §1).
- As a law student, I want my practice history and accuracy to survive devices and browsers, so that my learning journey is cumulative.
- As an auditor or reviewer, I want every matter mutation and HITL decision attributed to a real user with a timestamp, so that the file is reconstructible after the fact.
6. Functional Requirements¶
Journey spine (phase A — the concrete build of this spec)¶
- FR-1: A canonical journey-stage model —
intake,issues,research,analysis,drafting,action,resolution— codified once (enum in the newmattersapp) and documented in docs/data-model.md. Stages label matters and artifacts; transitions are non-linear (see §12 RQ-2). - FR-2: User accounts as first-class API principals: Django's existing
django.contrib.authuser model exposed through session login/logout/whoami endpoints for the frontend;core.ApiTokengains a nullableuserFK so a token can act as a user;ingestionapp.PendingReviewreviewer attribution and LSAT proposal approve/reject gain the same user FK (closes BL-20260811-04). - FR-3: A
Mattermodel: title, description, jurisdiction, current stage,confidentialflag, owner FK,created_at,archived_at(soft-archive only; no hard delete anywhere — constitution §4). - FR-4: A
MatterArtifactmodel: kind (analysis|research|note|draft|intake), stage tag, JSON payload, originating trace ids, creating user,created_at,archived_at. Append-only: artifacts are archived, never edited in place or deleted. - FR-5: A
JourneyEventtimeline per matter: stage transitions, artifact attachments, share-link grants/revocations, and HITL decisions, each carrying actor + timestamp. The timeline is the matter-level audit surface. - FR-6:
POST /api/analysisaccepts an optionalmatter_id; when present and the caller may write that matter, the fullAnalysisResponseis persisted as ananalysisartifact plus a journey event (closes BL-20260429-25 in matter scope). Withoutmatter_id, behaviour is byte-for-byte today's. - FR-7: A matter API under
/api/matters/*: list (owner-scoped, archived excluded by default), create, detail, update (stage, metadata), archive, artifact list/attach, timeline. Pydantic-validated at every boundary. - FR-8: Confidential matters pin the provider chain: every
law_ai.core.llmcall made in the context of a matter withconfidential=Trueis issued with the chain restricted to the local tier, using the existing per-call provider-restriction parameter shipped by spec 034 — no ambient global state. Provenance records the pin on each call. - FR-9: Read-only share links: an owner can mint an unguessable slug for a matter artifact, anyone with the slug can view that artifact (with disclaimers), and the owner can revoke it (closes BL-20260429-26).
Journey navigation (phase B)¶
- FR-10: A matter workspace frontend at
frontend/app/matters/: matter list, matter detail with stage indicator, artifact list, journey timeline, and "attach this analysis to a matter" flow in Analysis Studio. - FR-11: A
JourneyGuideagent (LangGraph workflow overChatProviderChain): given a matter's state (stage, artifacts, issue list, coverage gaps), it emits a structured set of process recommendations — each typed against a closed recommendation-kind enum (e.g.run_research,run_analysis,review_pending,record_outcome,consult_professional), each grounded in named matter artifacts or named coverage gaps. Output declareshuman_approval_required(constitution §5: new output path with no existing gate inherits the requirement) and carries the UPL disclaimer. No free-text "you will win/lose" channel exists in the schema. - FR-12: Guided intake: plain-language narrative in → structured matter profile out (parties, jurisdiction, timeline, goals, candidate issue tags) via an
IntakeExtractoragent. Extractions below the existing confidence threshold (0.7, mirroringIngestionScout) land as apendingintake artifact requiring explicit user confirmation before the matter profile updates — the HITL gate for this path.
Deliverables & learning journey (phases C–D, seams built here, bodies graduate to sub-specs)¶
- FR-13: The
draftartifact kind and a memo-composition seam: an endpoint that assembles a matter's analysis artifacts into a draft memo artifact, every legal proposition carrying its authority attribution (court, jurisdiction, date, binding/persuasive — constitution §13). DOCX/PDF export with Bluebook citations and a provenance footer is explicitly a follow-up sub-spec (BL-20260817-03), not this spec. - FR-14: Per-user LSAT attempt history: an
LsatAttemptPostgres model; authenticated attempts persist server-side and/api/lsat/statsreturns per-user accuracy over time; anonymous behaviour (localStorage) unchanged (closes BL-20260503-05).
7. Non-Functional Requirements¶
- NFR-AUDIT-1: Every matter mutation (create, stage transition, artifact attach, share grant/revoke, archive) and every navigator/intake agent call logs through
law_ai.core.provenancewith the acting user — JSONL-first dual-write preserved (constitution §4). Model calls go only throughlaw_ai.core.llm. - NFR-PRIV-1: For a confidential matter, the local-tier pin is sufficient on its own to guarantee no prompt text leaves the host: no code path in matter context may construct a chain call without the restriction. Asserted by test (complements the still-open BL-20260811-24 end-to-end check).
- NFR-SEC-1: Matter access is owner-only by default; share slugs are ≥ 32 bytes of
secretsentropy, single-artifact scoped, revocable; session auth uses Django's hardened defaults (CSRF on unsafe methods); credentials and slugs never logged. - NFR-DATA-1: No hard delete of matters, artifacts, events, or attempts —
archived_atsoft-delete only, mirroring the graph rule (constitution §4). - NFR-HITL-1: Both new agent output paths (FR-11, FR-12) declare
human_approval_requiredsemantics from day one; the navigator ships behindENABLE_JOURNEY_NAVIGATOR(defaultFalse) until the production-deployment gate for a new agent role (constitution §5) is explicitly passed. - NFR-SAFE-1: Every navigator and intake output surface renders the existing UPL disclaimer (spec 030
LegalDisclaimer) plus process-guidance framing; wording inherits the open counsel-review item BL-20260811-05 rather than inventing new legal language. - NFR-PERF-1: Matter list and detail p95 < 500 ms with 1k artifacts per matter (paginated artifact/timeline queries; indexed FKs).
- NFR-COMPAT-1: Every existing anonymous flow (scope-key
POST /api/analysis, graph, LSAT endpoints, static site) works unchanged with no account — verified by regression tests, not by intention.
8. Data Model Impact¶
Postgres (new law_ai.matters Django app): Matter, MatterArtifact, JourneyEvent, ShareLink, plus LsatAttempt (lsat app) — all with created_at/archived_at, FK indexes, and no cascade hard-deletes (on_delete=PROTECT/SET_NULL per relation). Changed: core.ApiToken + ingestionapp.PendingReview gain nullable user FKs (additive migrations; existing rows untouched). Neo4j: no schema change — matters reference graph nodes by id in artifact payloads only. Django migrations are schema migrations and therefore carry the constitution §5 HITL flag: human_approval_required: true at the PR gate.
9. API Surface¶
| Method & path | Request / response (Pydantic) | Notes |
|---|---|---|
POST /api/auth/login, POST /api/auth/logout, GET /api/auth/me |
LoginRequest → SessionInfo |
Django session; CSRF-protected |
GET/POST /api/matters |
MatterCreate → MatterSummary[] / MatterDetail |
owner-scoped; ?include_archived= |
GET/PATCH /api/matters/{id} |
MatterUpdate → MatterDetail |
stage transition = PATCH, evented |
POST /api/matters/{id}/archive |
— → MatterDetail |
soft-archive |
GET/POST /api/matters/{id}/artifacts |
ArtifactAttach → ArtifactSummary[] |
paginated |
GET /api/matters/{id}/timeline |
→ JourneyEventList |
paginated |
POST/DELETE /api/matters/{id}/share |
ShareRequest → ShareLinkInfo |
mint/revoke slug |
GET /api/shared/{slug} |
→ SharedArtifactView |
unauthenticated, read-only, disclaimed |
POST /api/matters/{id}/navigate |
→ JourneyGuideOutput |
flag-gated (NFR-HITL-1) |
POST /api/matters/{id}/intake |
IntakeRequest → IntakeResult |
HITL below threshold |
POST /api/analysis |
AnalysisRequest gains optional matter_id |
back-compat (NFR-COMPAT-1) |
GET /api/lsat/stats |
per-user series when authenticated | anonymous unchanged |
10. Agent / Crew Impact¶
Two new agents, both under the AGENTS.md contract (run(input: dict) -> dict, Pydantic output, versioned prompts in agents_runtime/prompts/, tests in backend/tests/agents/, all model calls via law_ai.core.llm):
- JourneyGuide (
agents_runtime/graphs/journey_guide.py) — FR-11. Reads matter state; emits typed process recommendations. Never retrieves fresh authority itself; it points at gaps for the existing tools to fill. - IntakeExtractor (
agents_runtime/crews/intake_extractor.py) — FR-12. Narrative → structured matter profile with per-field confidence.
Existing LegalAnalyst / PrecedentHunter / LegalWorkflow are unchanged; their outputs become persistable via FR-6. docs/agent-roles.md gains both roles at implement time (constitution §9).
11. Acceptance Criteria¶
- AC-1: Given an authenticated owner and a matter, when
POST /api/analysisruns withmatter_id, then ananalysisartifact and a journey event exist for that matter and the artifact's payload round-trips the fullAnalysisResponse(integration, real Postgres). - AC-2: Given a matter with
confidential=True, when any agent runs in its context, then the chain call carries the local-tier restriction and thellm_callprovenance event records it; a test asserts no non-local provider attempt is recorded (unit + integration). - AC-3: Given no session and today's scope keys, when every pre-existing endpoint is exercised without
matter_id, then responses are unchanged (regression suite passes untouched). - AC-4: Given an archived matter, then it is absent from default lists, present with
?include_archived=true, and no code path performs a hard delete (model-level test provesdelete()is not reachable via the API). - AC-5: Given a minted share slug, an unauthenticated GET renders the read-only artifact with disclaimer; after revocation the same slug returns 404 (integration).
- AC-6: Given any matter state,
JourneyGuideoutput contains only recommendations whosekindis in the closed enum, each referencing at least one matter artifact or named gap; the Pydantic schema rejects free-text outcome-prediction fields by construction, andhuman_approval_requiredis present (agent test). - AC-7: Given an intake narrative extracted below 0.7 confidence, the matter profile is NOT updated and a
pendingintake artifact awaits explicit confirmation; upon confirmation the profile updates and both steps appear as journey events (agent + integration test). - AC-8: Given an authenticated user completing an LSAT question, the attempt persists and
/api/lsat/statsreflects it across sessions; given no session, stats behave exactly as today (unit). - AC-9: Given any matter mutation, an
AuditEvent/JSONL provenance event exists naming the acting user, the matter, and the mutation kind (unit). - AC-10:
docs/data-model.md,docs/architecture.md, anddocs/agent-roles.mddocument the journey-stage model, the matters app, and both new agent roles in the same PR that implements them (constitution §9).
12. Risks & Resolved Questions¶
Resolved via /clarify (2026-08-17); each answer is derived from the constitution, existing code, or a shipped spec — none required inventing policy:
- RQ-1 (was OQ-1: JWT/OAuth vs session auth?) — Django session auth + CSRF for the frontend; per-user
ApiTokenfor programmatic access.django.contrib.authand session middleware are already installed and constitution §2 locks the stack while §8 makes every new dependency justify itself — python-jose/passlib add a key-rotation surface with no current cross-origin need. BL-20260503-13's JWT mechanism is deferred, recorded in its claim annotation; revisit when a third-party client exists. - RQ-2 (was OQ-2: gated vs free stage transitions?) — Free (any stage → any stage), every transition evented. Real matters loop research ↔ analysis ↔ drafting; a turnstile would misrepresent the domain and philosophy P6 keeps decision power with the human. Rigor lives where stakes are: HITL on agent outputs (NFR-HITL-1), not on navigation.
- RQ-3 (was OQ-3: contextvar vs explicit provider restriction?) — Explicit per-call provider restriction, derived in one matters-service helper. Spec 034 already ships the per-call
providers=parameter; constitution §4 auditability favors a visible argument over ambient state that hides the decision from call sites and tests. - RQ-4 (was OQ-4: reuse
PendingReviewfor intake HITL?) — No — matter-scopedpendingintake artifact confirmed by the matter owner.PendingReviewis corpus quarantine with operator reviewers and graph-commit blast radius; intake is the owner confirming their own facts before their own matter profile updates. Different reviewer, different blast radius, same 0.7 threshold constant. The §5 gate is preserved either way; this places it with the right human.
| Risk | Likelihood | Impact | Mitigation |
|---|---|---|---|
| Scope creep — "whole journey" swallows quarters | high | high | Phases: A concrete here; C–D bodies graduate to sub-specs via /specify (BL-20260817-03 et al.); tasks in this spec stay single-PR sized |
| UPL exposure as guidance surfaces multiply | med | high | NFR-SAFE-1 reuses spec 030 disclaimers; navigator flag-gated off (NFR-HITL-1); counsel review already tracked (BL-20260811-05) |
| Client facts now stored server-side | med | high | Confidential pin (FR-8, NFR-PRIV-1); owner-only access (NFR-SEC-1); soft-delete audit trail (NFR-DATA-1); data-portability/deletion follow-up (BL-20260817-01) |
| Auth work regresses anonymous flows | med | med | NFR-COMPAT-1 regression suite; accounts additive, never required for existing endpoints |
| Navigator becomes de-facto legal advice | med | high | Closed recommendation-kind enum (AC-6); grounded-in-artifacts requirement; consult_professional is a first-class recommendation kind |
13. Out of Scope / Follow-ups¶
Mirrored to BACKLOG.md as BL-20260817-01 … BL-20260817-05 (see tasks.md § Follow-ups Discovered): matter data portability & account deletion; action-stage deadline/task tracking; drafting & export sub-spec (DOCX/PDF, Bluebook); doctrine-gap → study-plan linkage; matter-scoped retrieval memory. Also explicitly out: everything in §4 Non-Goals.