Skip to content

feat(regulations): add the regulations.* contract and data model - #110

Draft
lorenzocorallo wants to merge 5 commits into
mainfrom
feat/regulations
Draft

lorenzocorallo wants to merge 5 commits into
mainfrom
feat/regulations

Conversation

@lorenzocorallo

Copy link
Copy Markdown
Member

First PR of the regulations editor backend (spec: regulations-editor-spec.md, phases 2 and 4). It publishes the
regulations.* wire contract early so the admin dashboard, the bot and the deployment can align, plus the tables
behind it. The router, services and the collab/worker entrypoints follow in stacked PRs.

Contract (src/regulations/contract.ts)

The admin keeps a copy, like people.contract.ts. Highlights:

  • regulations.me.get → { assignedDrafts, deleghe, permissions }, callable by any signed-in dashboard account
    with no permission, so people with only a draft assignment are admitted to /dashboard.
  • drafts.get returns myRole and can (edit, comment, assign, merge, transitions with blockedBy, approve,
    emanate, rectify, regenerateDiff, delete, rename, snapshot, restore), plus deadlines (3 days to emanate, 10 days
    for oppositions) computed by the backend from the document's procedure configuration.
  • collabTicket({ draftId }) → { url, documentName, ticket, role, readOnly, expiresAt }: single-use, about a
    minute. Y.Doc layout: document name = draft id, ydoc.getMap("files") path → Y.Text.
  • Files over tRPC (compile.pdf, versions.pdf, diff.pdf) are { fileName, contentType, base64 }, like
    esign; superjson has no Uint8Array support here.
  • Comments go through tRPC (anchors are base64 Y.encodeRelativePosition plus the quoted text).
  • Merge preview/apply with per-node conflicts (ours / theirs / custom text); diff with LLM categories and
    per-article word diffs; emanation steps pr|checks|merge|tag|release|email|telegram; deleghe.

Data model (src/db/schema/regulations, migration 0033_regulations)

documents (from legal.json), versions (full sources per published version), drafts (base version or draft, base
text for 3-way merges, frozen text, one in_approvazione per document via a partial unique index), assignments,
ydocs + yupdates (Yjs state with an append-only update log compacted by the collab service), collab tickets
(hash only, single use), snapshots, comments, delibere, diffs (one row per generation), blobs (content-addressed
PDFs), compile cache + per-draft compile status, merges (the source's text at the last merge is the next base),
emanations (resumable steps), notifications (proof of every send) and deleghe.

Checks

bun run typecheck, bunx biome ci ., migration applied on Postgres 18.

The wire contract of the regulations editor (shared with the admin dashboard,
which keeps a copy like people.contract.ts) and the tables behind it:
documents, published versions, drafts, per-draft assignments, Yjs state and
update log, collab tickets, snapshots, comments, delibere, LLM diffs, compile
cache, merges, emanations, notifications and deleghe.
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant