# aritra741/memoryatlas architecture

> Architecture diagram of the GitHub repository aritra741/memoryatlas, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aritra741/memoryatlas
- Repository: https://github.com/aritra741/memoryatlas

## Overview

#### Purpose and Entry Points
MemoryAtlas is a local-first journaling system that detects sustained negative emotional trajectories and retrieves evidence of prior recovery. The React client starts at `frontend/src/main.jsx` and `frontend/src/App.jsx`; the FastAPI service starts at `backend/main.py`. Primary ingress is entry ingestion, with REST routers and a user WebSocket under `backend/routers/entries.py`, `backend/routers/search.py`, and `backend/routers/websocket.py`.

#### Frontend Experience and State
The frontend renders an emotional 3D “ocean” rather than a conventional dashboard. `frontend/src/components/OceanView.jsx` maps entry coordinates and emotional state into the scene; `frontend/src/components/InterventionCinematic.jsx` and `frontend/src/components/InterventionOverlays.jsx` present the staged recovery journey. API/WebSocket integration is centralized in `frontend/src/services/api.js`; client-side memory and intervention timing state live in `frontend/src/store/memoryStore.js` and `frontend/src/store/interventionTimings.js`.

#### Entry Ingestion and Feature Extraction
`POST /api/entries` accepts text and optional audio through `backend/routers/entries.py`. The pipeline generates semantic embeddings, emotion distributions/Russell valence-arousal features, and linguistic features via `backend/ml/embeddings.py`, `backend/ml/emotion.py`, and `backend/ml/linguistic.py`. Audio processing adds transcription/prosodic signals and text-audio dissonance through `backend/ml/voice_emotion.py`. The resulting entry is a multimodal point, with suppression/dissonance flags retained as searchable payload.

#### Vector Storage Boundary
Qdrant is the durable retrieval engine, accessed through `backend/db/qdrant_client.py` and higher-level persistence/search operations in `backend/db/storage.py`. Each entry shares one point ID across six named vectors; trajectory points have four named vectors. This co-location enables filtered searches and dissonance queries without cross-collection joins. Qdrant runs locally via `docker-compose.yml`; collection lifecycle support is in `backend/reset_collections.py`.

#### Trajectory Construction and Matching
After upsert, a recent 14-day entry window is converted into sequence and aggregate representations by `backend/ml/trajectory_build.py`, `backend/ml/trajectory_encoder.py`, and `backend/ml/trajectory_features.py`. Historical trajectory retrieval performs weighted multi-vector fusion in `backend/ml/trajectory_context.py`; confidence evaluation is isolated in `backend/ml/match_confidence.py`. This is the core boundary between per-entry understanding and longitudinal spiral detection.

#### Intervention and Recovery Retrieval
`backend/ml/observation_engine.py` implements the graduated intervention gates: ambient negative-state signaling, sustained-pattern observation, and evidence-backed cinematic intervention. Once a trajectory match passes confidence and safety gates, Qdrant Recommend uses the current spiral as negative examples and a post-historical-spiral datetime window to identify contrasting recovery entries. `backend/ml/recovery_scoring.py` ranks those candidates before they are returned in the ingest response.

#### Projection, Realtime Updates, and Infrastructure
`backend/ml/umap_projector.py` projects combined embedding features into 3D coordinates; periodic refits publish updated coordinates through the WebSocket router. The frontend uses these coordinates to position journal orbs and derives camera behavior from rolling emotional state. Deployment consists of a FastAPI container (`backend/Dockerfile`), static React/Nginx container (`frontend/Dockerfile`, `frontend/nginx.conf`), and local Qdrant. External dependency is TwelveLabs Marengo for audio embeddings; text, emotion, NLP, Whisper, UMAP, and trajectory models run locally.

Main entry points: [`backend/main.py`](https://github.com/aritra741/memoryatlas/blob/main/backend/main.py) (FastAPI application), [`frontend/src/App.jsx`](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/App.jsx) (App shell), [`frontend/src/services/api.js`](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/services/api.js) (API & WebSocket client), [`backend/db/storage.py`](https://github.com/aritra741/memoryatlas/blob/main/backend/db/storage.py) (Storage operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React Client"]
  node_react_entry["React entry<br/>client bootstrap<br/>[main.jsx]"]
  node_app["App shell<br/>React app<br/>[App.jsx]"]
  node_ocean["Emotional ocean<br/>3D visualization<br/>[OceanView.jsx]"]
  node_intervention_ui["Intervention journey<br/>staged UI"]
  node_client_api["API &amp; WebSocket client<br/>integration service<br/>[api.js]"]
  node_memory_state["Memory state<br/>client store<br/>[memoryStore.js]"]
end

subgraph group_api["FastAPI Service"]
  node_fastapi["FastAPI application<br/>service entry<br/>[main.py]"]
  node_entry_router["Entry ingestion<br/>REST router<br/>[entries.py]"]
  node_search_router["Memory search<br/>REST router<br/>[search.py]"]
  node_websocket["Realtime updates<br/>WebSocket router<br/>[websocket.py]"]
end

subgraph group_ml["Understanding &amp; Intervention"]
  node_entry_features["Multimodal features<br/>feature extraction<br/>[embeddings.py]"]
  node_trajectory["Trajectory construction<br/>longitudinal encoder"]
  node_trajectory_match["Historical matching<br/>multi-vector retrieval"]
  node_observation["Observation gates<br/>intervention engine"]
  node_recovery["Recovery ranking<br/>recovery retrieval"]
  node_projection["3D projection<br/>UMAP projector<br/>[umap_projector.py]"]
end

subgraph group_storage["Vector Storage"]
  node_storage_service["Storage operations<br/>persistence/search layer<br/>[storage.py]"]
  node_qdrant[("Qdrant<br/>vector database<br/>[qdrant_client.py]")]
end

subgraph group_infra["Deployment"]
  node_compose{{"Local stack<br/>container deployment<br/>[docker-compose.yml]"}}
end

node_react_entry -->|"mounts"| node_app
node_app -->|"renders"| node_ocean
node_app -->|"renders"| node_intervention_ui
node_app -->|"uses"| node_client_api
node_client_api -->|"REST / WebSocket"| node_fastapi
node_fastapi -->|"routes"| node_entry_router
node_fastapi -->|"routes"| node_search_router
node_fastapi -->|"routes"| node_websocket
node_entry_router -->|"extracts"| node_entry_features
node_entry_features -->|"upserts entry payload and vectors"| node_storage_service
node_storage_service -->|"persists and queries"| node_qdrant
node_storage_service -->|"loads recent 14-day window"| node_trajectory
node_trajectory -->|"upserts trajectory vectors"| node_storage_service
node_trajectory -->|"current spiral"| node_trajectory_match
node_trajectory_match -->|"retrieves historical trajectories"| node_qdrant
node_trajectory_match -->|"matched confidence"| node_observation
node_observation -->|"approved intervention"| node_recovery
node_recovery -->|"recommends recovery evidence"| node_qdrant
node_observation -.->|"ingest response"| node_entry_router
node_entry_features -->|"combined features"| node_projection
node_projection -->|"coordinate updates"| node_websocket
node_websocket -->|"pushes updates"| node_client_api
node_client_api -->|"updates"| node_memory_state
node_memory_state -->|"coordinates and state"| node_ocean
node_memory_state -->|"intervention state"| node_intervention_ui
node_compose -->|"runs"| node_fastapi
node_compose -->|"runs"| node_qdrant

click node_react_entry "https://github.com/aritra741/memoryatlas/blob/main/frontend/src/main.jsx"
click node_app "https://github.com/aritra741/memoryatlas/blob/main/frontend/src/App.jsx"
click node_ocean "https://github.com/aritra741/memoryatlas/blob/main/frontend/src/components/OceanView.jsx"
click node_intervention_ui "https://github.com/aritra741/memoryatlas/blob/main/frontend/src/components/InterventionCinematic.jsx"
click node_client_api "https://github.com/aritra741/memoryatlas/blob/main/frontend/src/services/api.js"
click node_memory_state "https://github.com/aritra741/memoryatlas/blob/main/frontend/src/store/memoryStore.js"
click node_fastapi "https://github.com/aritra741/memoryatlas/blob/main/backend/main.py"
click node_entry_router "https://github.com/aritra741/memoryatlas/blob/main/backend/routers/entries.py"
click node_search_router "https://github.com/aritra741/memoryatlas/blob/main/backend/routers/search.py"
click node_websocket "https://github.com/aritra741/memoryatlas/blob/main/backend/routers/websocket.py"
click node_entry_features "https://github.com/aritra741/memoryatlas/blob/main/backend/ml/embeddings.py"
click node_trajectory "https://github.com/aritra741/memoryatlas/blob/main/backend/ml/trajectory_build.py"
click node_trajectory_match "https://github.com/aritra741/memoryatlas/blob/main/backend/ml/trajectory_context.py"
click node_observation "https://github.com/aritra741/memoryatlas/blob/main/backend/ml/observation_engine.py"
click node_recovery "https://github.com/aritra741/memoryatlas/blob/main/backend/ml/recovery_scoring.py"
click node_projection "https://github.com/aritra741/memoryatlas/blob/main/backend/ml/umap_projector.py"
click node_storage_service "https://github.com/aritra741/memoryatlas/blob/main/backend/db/storage.py"
click node_qdrant "https://github.com/aritra741/memoryatlas/blob/main/backend/db/qdrant_client.py"
click node_compose "https://github.com/aritra741/memoryatlas/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_react_entry,node_app,node_ocean,node_intervention_ui,node_client_api,node_memory_state toneBlue
class node_fastapi,node_entry_router,node_search_router,node_websocket toneAmber
class node_entry_features,node_trajectory,node_trajectory_match,node_observation,node_recovery,node_projection toneMint
class node_storage_service,node_qdrant toneRose
class node_compose toneIndigo
```

## Components

### React Client

Local emotional ocean experience.

- [React entry](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/main.jsx): client bootstrap · `frontend/src/main.jsx`
- [App shell](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/App.jsx): React app · `frontend/src/App.jsx`
- [Emotional ocean](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/components/OceanView.jsx): 3D visualization · Positions journal orbs from projected coordinates and emotional state. · `frontend/src/components/OceanView.jsx`
- [Intervention journey](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/components/InterventionCinematic.jsx): staged UI · `frontend/src/components/InterventionCinematic.jsx`
- [API & WebSocket client](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/services/api.js): integration service · `frontend/src/services/api.js`
- [Memory state](https://github.com/aritra741/memoryatlas/blob/main/frontend/src/store/memoryStore.js): client store · Stores memories and intervention timing state. · `frontend/src/store/memoryStore.js`

### FastAPI Service

Ingress, search, and realtime delivery.

- [FastAPI application](https://github.com/aritra741/memoryatlas/blob/main/backend/main.py): service entry · `backend/main.py`
- [Entry ingestion](https://github.com/aritra741/memoryatlas/blob/main/backend/routers/entries.py): REST router · Accepts text and optional audio at POST /api/entries. · `backend/routers/entries.py`
- [Memory search](https://github.com/aritra741/memoryatlas/blob/main/backend/routers/search.py): REST router · `backend/routers/search.py`
- [Realtime updates](https://github.com/aritra741/memoryatlas/blob/main/backend/routers/websocket.py): WebSocket router · Publishes coordinate refits to users. · `backend/routers/websocket.py`

### Understanding & Intervention

Entry analysis through recovery retrieval.

- [Multimodal features](https://github.com/aritra741/memoryatlas/blob/main/backend/ml/embeddings.py): feature extraction · Builds embeddings, emotion, linguistic, and audio dissonance signals. · `backend/ml/embeddings.py`
- [Trajectory construction](https://github.com/aritra741/memoryatlas/blob/main/backend/ml/trajectory_build.py): longitudinal encoder · Builds 14-day sequence and aggregate representations. · `backend/ml/trajectory_build.py`
- [Historical matching](https://github.com/aritra741/memoryatlas/blob/main/backend/ml/trajectory_context.py): multi-vector retrieval · Fuses trajectory vectors and evaluates match confidence. · `backend/ml/trajectory_context.py`
- [Observation gates](https://github.com/aritra741/memoryatlas/blob/main/backend/ml/observation_engine.py): intervention engine · Selects ambient, sustained-pattern, or cinematic intervention. · `backend/ml/observation_engine.py`
- [Recovery ranking](https://github.com/aritra741/memoryatlas/blob/main/backend/ml/recovery_scoring.py): recovery retrieval · Ranks contrasting post-spiral recovery entries. · `backend/ml/recovery_scoring.py`
- [3D projection](https://github.com/aritra741/memoryatlas/blob/main/backend/ml/umap_projector.py): UMAP projector · Refits and produces entry coordinates. · `backend/ml/umap_projector.py`

### Vector Storage

Local durable retrieval boundary.

- [Storage operations](https://github.com/aritra741/memoryatlas/blob/main/backend/db/storage.py): persistence/search layer · Co-locates entry and trajectory named vectors by point ID. · `backend/db/storage.py`
- [Qdrant](https://github.com/aritra741/memoryatlas/blob/main/backend/db/qdrant_client.py): vector database · Durable local engine for filtered, fused, and recommendation retrieval. · `backend/db/qdrant_client.py`

### Deployment

Local containerized runtime.

- [Local stack](https://github.com/aritra741/memoryatlas/blob/main/docker-compose.yml): container deployment · Runs FastAPI, React/Nginx, and Qdrant locally. · `docker-compose.yml`

## Connections

- React entry → App shell: mounts
- App shell → Emotional ocean: renders
- App shell → Intervention journey: renders
- App shell → API & WebSocket client: uses
- API & WebSocket client → FastAPI application: REST / WebSocket
- FastAPI application → Entry ingestion: routes
- FastAPI application → Memory search: routes
- FastAPI application → Realtime updates: routes
- Entry ingestion → Multimodal features: extracts
- Multimodal features → Storage operations: upserts entry payload and vectors
- Storage operations → Qdrant: persists and queries
- Storage operations → Trajectory construction: loads recent 14-day window
- Trajectory construction → Storage operations: upserts trajectory vectors
- Trajectory construction → Historical matching: current spiral
- Historical matching → Qdrant: retrieves historical trajectories
- Historical matching → Observation gates: matched confidence
- Observation gates → Recovery ranking: approved intervention
- Recovery ranking → Qdrant: recommends recovery evidence
- Observation gates → Entry ingestion: ingest response
- Multimodal features → 3D projection: combined features
- 3D projection → Realtime updates: coordinate updates
- Realtime updates → API & WebSocket client: pushes updates
- API & WebSocket client → Memory state: updates
- Memory state → Emotional ocean: coordinates and state
- Memory state → Intervention journey: intervention state
- Local stack → FastAPI application: runs
- Local stack → Qdrant: runs
