Architecture
Dense-Mem is a standalone MCP Streamable HTTP memory service. PostgreSQL with pgvector owns durable memory, provenance, workflow, security, search, and audit. Model providers propose assessments; deterministic server policy decides what can commit.
Runtime Boundaries
%%{init: {"flowchart": {"curve": "linear"}}}%%
flowchart TB
Client["AI client"] --> MCP["Authenticated /mcp"]
User["User browser"] --> UI["First-party /ui"]
Operator["Private operator"] --> Control["Separate control listener"]
MCP --> App["Capability application services"]
UI --> App
Control --> App
App --> PG[("PostgreSQL + pgvector<br/>Durable authority")]
App --> Providers["Assessment, extraction, embeddings<br/>Optional typed decisions"]
App --> Coordination["Redis or single-process coordination"]
Workers["Topic maintenance<br/>Search reconciliation<br/>Privacy maintenance"] --> AppMCP is the supported external memory integration contract. Browser handlers are first-party interfaces. The control listener stays private or behind dedicated administrative ingress.
Dependency Direction
%%{init: {"flowchart": {"curve": "linear"}}}%%
flowchart LR
Transport["Transport<br/>Bind and translate"] --> Application["Application<br/>Orchestrate use cases"]
Application --> Domain["Domain policy and ports"]
Storage["PostgreSQL / Redis adapters"] -. "Implement ports" .-> Domain
Provider["Provider adapters"] -. "Implement ports" .-> Domain
Composition["Composition root"] -. "Construct and connect" .-> Application
Composition -.-> Storage
Composition -.-> Provider| Capability | Owns |
|---|---|
| Access | Identity, memberships, credentials, sessions, grants, and access policy. |
| Remember / Session | Strict intake, exact session staging, bounded provider orchestration, and terminal outcomes. |
| Knowledge | Evidence, occurrences, source revisions, lifecycle, Evidence conflicts, and authoritative search writes. |
| Recall / Trace | Authorized retrieval and bounded provenance reads. |
| Topics | Shared-Evidence Topic assignment, direct memberships, Community placement, and Evidence equivalence. |
| Search | Search contracts, query orchestration, index mechanics, and reconciliation. |
| Privacy / Settings / Operations / Audit | Erasure and retention, configuration, diagnostics, and audit use cases. |
Package-level detail lives with the source. Capability contracts
Runtime Composition
| Runtime | Boundary |
|---|---|
| Production | /app/server, migrations, user/control browser bundles. |
| Demo | /app/demo-server, bounded temporary-team behavior and user bundle. |
| Evaluation | The public QA runner uses a pinned production image and the supported MCP Recall and Trace tools on restored dataset seeds. |
| One server process | Process-local coordination is supported. |
| Multiple server processes | Redis or an equivalent distributed implementation is required. |
Startup validates configuration, connects to a writable PostgreSQL primary, serializes migrations under a session lock, verifies search contracts, and composes providers, listeners, and workers. Readiness remains false until required dependencies are ready. Shutdown cancels request/worker contexts and closes dependencies.
Read And Write Responsibilities
| Question | Canonical explanation |
|---|---|
| What is stored, and what changes eligibility? | Evidence Model And Lifecycle |
| When is input staged, assessed, embedded, and committed? | Memory Write Pipeline |
| How are shared sources organized? | Topics And Organization |
| How are candidates selected and hydrated? | Recall Ranking |
| How are identity and spaces enforced? | Request Lifecycle And Security |
| How do startup, backup, and recovery work? | Operations Runbook |
Built-In MCP OAuth
ADR 0024 adds an OAuth 2.1 authorization server to the Access capability. Release v2.9.2 introduces it; see implementation status.
| Decision | Consequence |
|---|---|
| One authority resolver | A customer IdP with protected-resource validation takes precedence. Invalid configuration fails closed and never falls back to built-in mode. |
| Opaque hashed tokens | Access and refresh tokens are random values. PostgreSQL stores only their SHA-256 hashes under system-only forced RLS. There are no signed JWTs or signing keys. |
| Grant families | One grant represents one connection: one client, resource, team, and sign-in source. Its access and refresh tokens are revoked together, including on code or refresh replay. |
| Live revalidation | Each MCP request and refresh rechecks the backing key or SSO membership, so lifecycle changes take effect without waiting for token expiry. |
Policy details are in Request Lifecycle And Security, and the authority table is in Configuration.
Code Ownership And Design Review
Handlers validate request shape and translate results. Application services orchestrate use cases and domain policy through ports. Adapters implement those ports and own infrastructure details such as SQL and driver-error translation. Capabilities expose narrow public contracts, and composition wires private implementations.
During pull request review, trace changed code through its callers, decision owner, and adapters. Check whether existing code or a maintained dependency can meet the requirement more simply. Build and behavioral checks exercise the production boundaries. Development And Testing