Architecture

The API

The oRPC API surface: how it is exposed, the access-control tiers, and the routers.

The API is defined in @repo/api using oRPC and served through Hono, mounted in the saas app at the catch-all route app/api/[[...rest]]. Clients call it through a typed oRPC client, so inputs and outputs are end-to-end type-checked. The root router composes one sub-router per domain.

Exposure

The handler exposes both an OpenAPI/REST surface (base path /api) and an RPC surface (/api/rpc). A shared middleware stack runs ahead of procedures: request identification, CORS, authentication, a plan-tier backstop, the AI usage-cap check, organization-suspension gating, and locale resolution.

Access-control tiers

Procedures are built from a small set of base procedures that layer in access control:

TierGuaranteesUsed for
publicNo auth.Slug generation, health.
protectedAuthenticated user + session.Profile, notifications, home summary.
adminGlobal admin role.All operator and admin routers.
org-scopedMembership in the target organization (and not suspended).Advisor, policy, usage, org ingestion.
plan-gatedOrg-scoped and the plan includes the feature.Advisor (requireAdvisorPlan), Policy Hub (requirePolicyHubPlan), LP Reporting (requireReportingPlan).

Routers

RouterPurposeTypical access
adminList users and organizations for the admin governance screens.admin
organizationsSlug generation, logo upload, profile updates.mixed
usersAvatar upload.protected
homeCross-organization home summary.protected
notificationsList, counts, read state, preferences.protected
paymentsCheckout links, customer portal, purchases.protected / org owner
advisorAsk the advisor; list and read conversations.org-scoped, advisor plan
aiStreaming responses and policy gap-review generation.mixed
usagePer-organization run totals and recent usage.org-scoped
ingestionJob listing, health, enqueue, retry.mixed (admin for cross-tenant)
policyPolicy Hub documents and gap reviews.org-scoped, policy-hub plan
reportingThe whole LP Reporting cycle (see below).org-scoped, reporting plan + flag
portfolioAccessPortfolio-company access, including the messaging bridge.mixed
operatorCommand Center tenant operations.admin
operatorIntelligenceUsage, conversation oversight, knowledge gaps.admin

Selected procedures

The procedures that back the documented features:

advisor

ProcedureTypePurpose
askmutationRun a grounded advisor turn (embed → retrieve → generate).
listConversationsqueryList the organization's advisor conversations.
getConversationqueryFetch a conversation with its messages and citations.

policy

ProcedureTypePurpose
list, getqueryBrowse policy documents and their ingestion status.
createUploadUrl, register, replace, delete, updateMetamutationManage policy documents (latest-wins replacement).
downloadUrlqueryPresigned download link.
gapReviewGet, gapReviewList, gapReviewExportquery/mutationRetrieve and export policy gap analyses.

ingestion

ProcedureTypeAccessPurpose
listJobsqueryorg-scopedJobs for an organization (operators may include global).
getHealthqueryorg / adminHealth summary for an org or platform-wide.
enqueueDocmutationorg adminEnqueue ingestion for a document.
listAllFailedJobsqueryadminFailed jobs across all tenants.
retryJobmutationadminRetry a failed job.

reporting

The largest router, grouped by the screen it serves:

GroupProcedures
lplist, create, get, update, delete
templatecreateUploadUrl, register, list, get, parse, uploadNewVersion, diffVersions, delete
kpiapproveExtraction, list, get, create, update, delete, exportDictionary, libraryBrowse, importFromLibrary, linkReference
mappinglist, create, update, delete, detectDuplicates, mergeDuplicates, exportInvesteeCollectionSheet
calculationlist, create, evaluate, update, delete
investeelist, get, create, update, deactivate, sendReminders
submissioncreateUploadUrl, ingest, list, get, delete, updateStatus, correctValue, correctionHistory
dqcrun, list, get
gpDatacreateUploadUrl, ingest, ingestHistorical, list, get, aggregate, delete
reportgenerate, regenerate, list, get, delete, updateNarrative, export, approve, email
settingsgetReportingPeriod, setReportingPeriod
explorerkpiTrends, export
cockpitsummary, todos
cycleAutomationstatus
lpPortalsubmitManualKpis
tasklist, create, toggle, delete

report.approve and report.email exist but are deliberately not surfaced in the Reports screen — report delivery is by download pending a client decision. Do not treat their existence as a shipped feature.

operator

Tenant operations: getDashboard, listOrganizations, getOrganization, createOrganizationOnboarding, updateOrganizationPlan, suspendOrganization, reactivateOrganization, resendOrganizationInvite, the globalLibrary* document procedures, the *SupportSession procedures, and listAuditLogs.

operatorIntelligence

Platform analytics: usage.getPlatformDashboard, usage.listByOrg, usage.listNearCap, conversations.list, conversations.get, and gaps.listRanked.

Operator procedures that change a tenant's state (onboarding, plan changes, suspensions, global library deletions, and support sessions) write to the audit log, so every cross-tenant action is attributable.

On this page