Architecture overview¶
Spongram is one service in front of a knowledge-graph engine and two stores. This page describes the logical architecture, which is the same in every deployment; the Portainer / Docker Swarm and AWS pages show how it is laid out on each platform.
Open the diagram in its own tab. Click a component to read what it does; the toolbar switches theme, pauses the animation and exports the drawing.
Components¶
| Component | Role | Reachable by |
|---|---|---|
spongram |
The only entry point. One FastAPI process on port 8091 that serves MCP (/mcp), the brain-key API (/v1/*), the admin API and web UI (/admin/*), health and metrics endpoints, and this documentation (/documentation/). |
Clients, through your TLS proxy |
graphiti-mcp |
The Graphiti MCP server, rebuilt with Spongram's configuration. Extracts entities and facts from episodes and answers hybrid searches. Port 8000. | spongram only |
| Neo4j | The knowledge graph: episodes, entities, facts, summaries and the code map, partitioned by group_id. |
spongram and graphiti-mcp |
| PostgreSQL | Spongram's own database: brains, key hashes, the ingestion queue, runtime settings, personas, skills, aliases and the migration journal. | spongram only |
| Inference endpoint | An OpenAI-compatible API for chat completions and embeddings. External to the stack, chosen by the operator. | spongram only |
Inside the spongram process, five responsibilities matter for understanding the flows:
- the MCP router authenticates the brain key, injects the
group_id, guards the tools that address objects by uuid and runs the search pipeline; - the ingestion queue stores each accepted episode in PostgreSQL and delivers it to Graphiti, with retries and reconciliation;
- the background workers, Sleeper and Dream, summarise and consolidate the graph;
- the inference proxy is the single path to the model endpoint;
- the admin API and web UI provision brains and serve the explorers.
Write path¶
- The client calls
add_memoryon/mcpwithAuthorization: Bearer spt_brain_…. - The router resolves the key to a brain, completes the tags in
source_descriptionand stores the episode in the queue. The client gets its acknowledgement at this point. - The queue worker forwards the episode to Graphiti with the brain's
group_id. - Graphiti extracts entities and facts. Each model call it makes goes to
spongram's internal inference proxy, which forwards it to the inference endpoint. - Graphiti writes the result to Neo4j.
- If delivery fails or the episode is later found missing from the graph, the row is retried on a growing schedule. An accepted episode is never abandoned.
Details: ingestion.
Read path¶
- The client calls
search_nodesorsearch_memory_facts. - The router checks the result cache, then forwards an oversampled search to Graphiti, restricted to the brain's
group_id. - The search pipeline filters by scope, reranks, hides invalidated facts and truncates to the requested size. It reads tags and graph structure directly from Neo4j for this.
- The result is returned in both
content[0].textandstructuredContent, with a_spongramblock of counters.
Details: search.
Design rules¶
These rules hold in every deployment. Each is enforced in code or in the deployment files.
- All graph traffic goes through
spongram - Clients never reach Graphiti. Its port is internal to the stack, because Graphiti resolves several tools by uuid without looking at the
group_id, and onlyspongramchecks that a uuid belongs to the caller's brain. - The server chooses the
group_id - It comes from the authenticated key. A call that carries another
group_idis rejected. - One path to the model
- Graphiti's extraction, the Sleeper's summaries and session distillation all go through the internal inference proxy. That is where the model is selected per role, usage is attributed to the brain, transient upstream errors are retried and the circuit breaker lives. No memory operation calls a third-party LLM API, and Graphiti's usage telemetry is disabled.
- Readiness is not health
/readyzjudges only the three hard dependencies (Graphiti, PostgreSQL, Neo4j) and is what a container healthcheck must call./healthzalso reports the background workers and answers 503 when one of them is unhealthy; wiring it to a healthcheck would restart a container that can still serve.- One process, one replica
- The search activity bus, the alias cache and the per-episode delete lock are held in memory. The supplied deployments run a single
spongramreplica; running several needs these to move to a shared mechanism first. - The embedding dimension is fixed
- It is 1024 by default and immutable for a brain. Changing the embedding model requires a purge and a re-ingestion.
Fixed ports¶
| Port | Service | Exposure |
|---|---|---|
| 8091 | spongram |
The only port clients use. Put a TLS proxy in front of it. |
| 8000 | graphiti-mcp |
Internal to the stack. Never published. |
| 5432 | PostgreSQL | Internal to the stack. |
| 7474, 7687 | Neo4j HTTP and Bolt | Internal. For administration and debugging only, the Swarm stack publishes them on the node as 7475 and 7688, and Compose publishes them on the ports set by NEO4J_HTTP_PORT and NEO4J_BOLT_PORT. Client bundles never reference them. |
Related pages¶
- Data model: what is stored in PostgreSQL and in Neo4j.
- Security model: keys, isolation, permissions.
- MCP overview: the protocol surface.