# prathamkhatwani/code_cubicle architecture

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

- Interactive diagram: https://gitdiagram.com/prathamkhatwani/code_cubicle
- Repository: https://github.com/prathamkhatwani/code_cubicle

## Overview

CORTEX is an offline-first vector-memory platform for edge devices. Observations enter through the REST API or the robot-arena demo, are embedded and stored locally, then surfaced through semantic search and the inspector. A consolidation sleep cycle clusters and merges memories, applies decay and PII safeguards, while a separate sync agent prioritizes anomalous records and reconciles edge/cloud updates. The README documents these major capabilities; source excerpts are partial, so links to the cloud store and some internal consolidation details are omitted where callers are not shown.

Main entry points: [`backend/main.py`](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/main.py) (REST API), [`backend/qdrant_store.py`](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/qdrant_store.py) (Edge Vector Store), [`backend/consolidation.py`](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/consolidation.py) (Sleep Consolidation), [`backend/sync_agent.py`](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/sync_agent.py) (Sync Agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_intake["Intake &amp; API"]
  node_rest_api["REST API<br/>[main.py]"]
  node_seed_data["Demo Seed Data<br/>[seed_data.py]"]
end

subgraph group_memory["Memory Services"]
  node_embedding["Local Embeddings<br/>[embedding.py]"]
  node_edge_store[("Edge Vector Store<br/>[qdrant_store.py]")]
  node_models["Memory Models<br/>[models.py]"]
  node_config["Platform Config<br/>[config.py]"]
  node_benchmark["Memory Benchmark<br/>[benchmark.py]"]
end

subgraph group_lifecycle["Memory Lifecycle"]
  node_consolidation["Sleep Consolidation<br/>[consolidation.py]"]
  node_sync_agent["Sync Agent<br/>[sync_agent.py]"]
  node_activity_log[("Activity Log<br/>[activity_log.py]")]
end

subgraph group_experience["Inspector Experience"]
  node_robot_arena["Robot Arena<br/>[simulation.js]"]
  node_dashboard["Inspector Dashboard<br/>[app.js]"]
end

node_operator(("Operator / Device"))
node_cloud_qdrant[("Cloud Qdrant")]

node_operator -->|"operates"| node_robot_arena
node_robot_arena -->|"posts memories"| node_rest_api
node_operator -->|"uses"| node_dashboard
node_dashboard -->|"calls API"| node_rest_api
node_rest_api -->|"serves UI"| node_dashboard
node_rest_api -->|"reads and writes"| node_edge_store
node_rest_api -->|"runs / restores"| node_consolidation
node_rest_api -->|"dispatches sync"| node_sync_agent
node_rest_api -->|"reads activity"| node_activity_log
node_rest_api -->|"loads samples"| node_seed_data
node_edge_store -->|"embeds text"| node_embedding
node_embedding -->|"reads settings"| node_config
node_edge_store -->|"reads settings"| node_config
node_consolidation -->|"logs events"| node_activity_log
node_consolidation -.->|"updates memories"| node_edge_store
node_sync_agent -.->|"syncs records"| node_cloud_qdrant
node_sync_agent -.->|"reads and updates"| node_edge_store
node_seed_data -->|"adds samples"| node_edge_store
node_rest_api -->|"runs benchmark"| node_benchmark
node_consolidation -->|"uses data models"| node_models
node_activity_log -->|"creates entries"| node_models

click node_robot_arena "https://github.com/prathamkhatwani/code_cubicle/blob/main/frontend/simulation.js"
click node_rest_api "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/main.py"
click node_dashboard "https://github.com/prathamkhatwani/code_cubicle/blob/main/frontend/app.js"
click node_embedding "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/embedding.py"
click node_edge_store "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/qdrant_store.py"
click node_models "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/models.py"
click node_config "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/config.py"
click node_seed_data "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/seed_data.py"
click node_consolidation "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/consolidation.py"
click node_sync_agent "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/sync_agent.py"
click node_activity_log "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/activity_log.py"
click node_benchmark "https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/benchmark.py"

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_rest_api,node_seed_data toneBlue
class node_embedding,node_edge_store,node_models,node_config,node_benchmark,node_cloud_qdrant toneAmber
class node_consolidation,node_sync_agent,node_activity_log toneMint
class node_robot_arena,node_dashboard toneRose
class node_operator toneIndigo
```

## Components

### Intake & API

- [REST API](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/main.py): `backend/main.py`
- [Demo Seed Data](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/seed_data.py): `backend/seed_data.py`

### Memory Services

- [Local Embeddings](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/embedding.py): `backend/embedding.py`
- [Edge Vector Store](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/qdrant_store.py): `backend/qdrant_store.py`
- [Memory Models](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/models.py): `backend/models.py`
- [Platform Config](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/config.py): `backend/config.py`
- [Memory Benchmark](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/benchmark.py): `backend/benchmark.py`

### Memory Lifecycle

- [Sleep Consolidation](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/consolidation.py): `backend/consolidation.py`
- [Sync Agent](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/sync_agent.py): `backend/sync_agent.py`
- [Activity Log](https://github.com/prathamkhatwani/code_cubicle/blob/main/backend/activity_log.py): `backend/activity_log.py`

### Inspector Experience

- [Robot Arena](https://github.com/prathamkhatwani/code_cubicle/blob/main/frontend/simulation.js): `frontend/simulation.js`
- [Inspector Dashboard](https://github.com/prathamkhatwani/code_cubicle/blob/main/frontend/app.js): `frontend/app.js`

### Other components

- **Operator / Device**
- **Cloud Qdrant**

## Connections

- Operator / Device → Robot Arena: operates (evidence: `README.md`)
- Robot Arena → REST API: posts memories (evidence: `frontend/simulation.js`)
- Operator / Device → Inspector Dashboard: uses (evidence: `README.md`)
- Inspector Dashboard → REST API: calls API (evidence: `frontend/app.js`)
- REST API → Inspector Dashboard: serves UI (evidence: `backend/main.py`)
- REST API → Edge Vector Store: reads and writes (evidence: `backend/main.py`)
- REST API → Sleep Consolidation: runs / restores (evidence: `backend/main.py`)
- REST API → Sync Agent: dispatches sync (evidence: `backend/main.py`)
- REST API → Activity Log: reads activity (evidence: `backend/main.py`)
- REST API → Demo Seed Data: loads samples (evidence: `backend/main.py`)
- Edge Vector Store → Local Embeddings: embeds text (evidence: `backend/qdrant_store.py`)
- Local Embeddings → Platform Config: reads settings (evidence: `backend/embedding.py`)
- Edge Vector Store → Platform Config: reads settings (evidence: `backend/qdrant_store.py`)
- Sleep Consolidation → Activity Log: logs events (evidence: `backend/consolidation.py`)
- Sleep Consolidation → Edge Vector Store: updates memories
- Sync Agent → Cloud Qdrant: syncs records
- Sync Agent → Edge Vector Store: reads and updates
- Demo Seed Data → Edge Vector Store: adds samples (evidence: `backend/seed_data.py`)
- REST API → Memory Benchmark: runs benchmark (evidence: `backend/main.py`)
- Sleep Consolidation → Memory Models: uses data models (evidence: `backend/consolidation.py`)
- Activity Log → Memory Models: creates entries (evidence: `backend/activity_log.py`)
