# saifmht19/mind-mirror-1 architecture

> Architecture diagram of the GitHub repository saifmht19/mind-mirror-1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saifmht19/mind-mirror-1
- Repository: https://github.com/saifmht19/mind-mirror-1

## Overview

MindMirror is a research prototype for explaining manipulation signals in AI conversations. Its main workflow is a user submitting or editing a conversation in the React workspace, the FastAPI service sending visible turns to Gemini for per-turn predictions, and the service returning evidence-backed tactics and escalation risk for display. The product also includes local live simulation, comparison and context experiments, batch dataset analysis, and presentation views. Research-data generation and annotation are distinct supporting workflows. Some backend and UI wiring is unsampled; those relationships are included only where the README or excerpts support them.

Main entry points: [`frontend/src/App.tsx`](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/App.tsx) (Workspace shell), [`backend/main.py`](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/main.py) (HTTP API), [`backend/service.py`](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/service.py) (Detection orchestration), [`data/schema.py`](https://github.com/saifmht19/mind-mirror-1/blob/main/data/schema.py) (Dialogue data schema)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Research workspace"]
  node_app["Workspace shell<br/>[App.tsx]"]
  node_live["Live simulator view<br/>[LiveSimulator.tsx]"]
  node_compare["Side-by-side view"]
  node_context["Context experiment view"]
  node_multiturn["Multi-turn experiment view"]
  node_tour["Presentation tour"]
  node_why["Safety evidence view<br/>[WhyItMatters.tsx]"]
end

subgraph group_runtime["Analysis service"]
  node_api["HTTP API<br/>[main.py]"]
  node_service["Detection orchestration<br/>[service.py]"]
  node_provider["Gemini detector<br/>[gemini.py]"]
  node_risk["Escalation scoring<br/>[escalation.py]"]
  node_schemas["Conversation validation<br/>[schemas.py]"]
  node_dataset_api["Dataset analysis<br/>[datasets.py]"]
end

subgraph group_simulation["Conversation simulation"]
  node_simulator["Scenario simulator<br/>[simulator.py]"]
end

subgraph group_research["Research workflows"]
  node_evaluation["Experiment runners"]
  node_generator["Synthetic dialogue generation<br/>[generator.py]"]
  node_labeler["Human annotation<br/>[labeler.py]"]
  node_model_pipeline["Context model pipeline"]
  node_inference["Legacy model inference<br/>[inference.py]"]
end

subgraph group_data["Research data"]
  node_data_schema["Dialogue data schema<br/>[schema.py]"]
  node_importer["Dataset importer"]
end

node_researcher(("Researcher"))
node_ollama["Local Ollama model"]

node_researcher -->|"uses"| node_app
node_app -->|"shows"| node_live
node_app -->|"shows"| node_compare
node_app -->|"shows"| node_context
node_app -->|"shows"| node_multiturn
node_app -->|"shows"| node_tour
node_app -->|"shows"| node_why
node_app -->|"calls"| node_api
node_api -->|"routes analysis"| node_service
node_service -->|"validates with"| node_schemas
node_service -->|"requests predictions"| node_provider
node_service -->|"scores prediction"| node_risk
node_api -.->|"supports batch analysis"| node_dataset_api
node_api -->|"registers routes"| node_simulator
node_live -.->|"gets scenarios"| node_simulator
node_simulator -.->|"generates replies"| node_ollama
node_live -.->|"submits visible turns"| node_api
node_compare -.->|"requests analysis"| node_api
node_context -.->|"shows saved results"| node_evaluation
node_multiturn -.->|"shows saved results"| node_evaluation
node_evaluation -->|"runs detector"| node_service
node_generator -->|"creates records"| node_data_schema
node_labeler -->|"labels samples"| node_data_schema
node_importer -->|"builds records"| node_data_schema
node_model_pipeline -.->|"loads data"| node_data_schema
node_inference -->|"uses features"| node_model_pipeline

click node_app "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/App.tsx"
click node_live "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/LiveSimulator.tsx"
click node_compare "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/CompareSimulator.tsx"
click node_context "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/ContextExperiment.tsx"
click node_multiturn "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/MultiTurnExperiment.tsx"
click node_tour "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/PresentationTour.tsx"
click node_why "https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/WhyItMatters.tsx"
click node_api "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/main.py"
click node_service "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/service.py"
click node_provider "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/gemini.py"
click node_risk "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/escalation.py"
click node_schemas "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/schemas.py"
click node_dataset_api "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/datasets.py"
click node_simulator "https://github.com/saifmht19/mind-mirror-1/blob/main/backend/simulator.py"
click node_evaluation "https://github.com/saifmht19/mind-mirror-1/blob/main/evaluation/context_experiment.py"
click node_generator "https://github.com/saifmht19/mind-mirror-1/blob/main/generation/generator.py"
click node_labeler "https://github.com/saifmht19/mind-mirror-1/blob/main/annotation/labeler.py"
click node_data_schema "https://github.com/saifmht19/mind-mirror-1/blob/main/data/schema.py"
click node_importer "https://github.com/saifmht19/mind-mirror-1/blob/main/data/import_chatbotmanip.py"
click node_model_pipeline "https://github.com/saifmht19/mind-mirror-1/blob/main/models/train_context_model.py"
click node_inference "https://github.com/saifmht19/mind-mirror-1/blob/main/models/inference.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_app,node_live,node_compare,node_context,node_multiturn,node_tour,node_why toneBlue
class node_api,node_service,node_provider,node_risk,node_schemas,node_dataset_api toneAmber
class node_simulator toneMint
class node_evaluation,node_generator,node_labeler,node_model_pipeline,node_inference toneRose
class node_data_schema,node_importer,node_researcher,node_ollama toneIndigo
```

## Components

### Research workspace

- [Workspace shell](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Live simulator view](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/LiveSimulator.tsx): `frontend/src/LiveSimulator.tsx`
- [Side-by-side view](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/CompareSimulator.tsx): `frontend/src/CompareSimulator.tsx`
- [Context experiment view](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/ContextExperiment.tsx): `frontend/src/ContextExperiment.tsx`
- [Multi-turn experiment view](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/MultiTurnExperiment.tsx): `frontend/src/MultiTurnExperiment.tsx`
- [Presentation tour](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/PresentationTour.tsx): `frontend/src/PresentationTour.tsx`
- [Safety evidence view](https://github.com/saifmht19/mind-mirror-1/blob/main/frontend/src/WhyItMatters.tsx): `frontend/src/WhyItMatters.tsx`

### Analysis service

- [HTTP API](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/main.py): `backend/main.py`
- [Detection orchestration](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/service.py): `backend/service.py`
- [Gemini detector](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/gemini.py): `backend/gemini.py`
- [Escalation scoring](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/escalation.py): `backend/escalation.py`
- [Conversation validation](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/schemas.py): `backend/schemas.py`
- [Dataset analysis](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/datasets.py): `backend/datasets.py`

### Conversation simulation

- [Scenario simulator](https://github.com/saifmht19/mind-mirror-1/blob/main/backend/simulator.py): `backend/simulator.py`

### Research workflows

- [Experiment runners](https://github.com/saifmht19/mind-mirror-1/blob/main/evaluation/context_experiment.py): `evaluation/context_experiment.py`
- [Synthetic dialogue generation](https://github.com/saifmht19/mind-mirror-1/blob/main/generation/generator.py): `generation/generator.py`
- [Human annotation](https://github.com/saifmht19/mind-mirror-1/blob/main/annotation/labeler.py): `annotation/labeler.py`
- [Context model pipeline](https://github.com/saifmht19/mind-mirror-1/blob/main/models/train_context_model.py): `models/train_context_model.py`
- [Legacy model inference](https://github.com/saifmht19/mind-mirror-1/blob/main/models/inference.py): `models/inference.py`

### Research data

- [Dialogue data schema](https://github.com/saifmht19/mind-mirror-1/blob/main/data/schema.py): `data/schema.py`
- [Dataset importer](https://github.com/saifmht19/mind-mirror-1/blob/main/data/import_chatbotmanip.py): `data/import_chatbotmanip.py`

### Other components

- **Researcher**
- **Local Ollama model**

## Connections

- Researcher → Workspace shell: uses (evidence: `README.md`)
- Workspace shell → Live simulator view: shows (evidence: `frontend/src/App.tsx`)
- Workspace shell → Side-by-side view: shows (evidence: `frontend/src/App.tsx`)
- Workspace shell → Context experiment view: shows (evidence: `frontend/src/App.tsx`)
- Workspace shell → Multi-turn experiment view: shows (evidence: `README.md`)
- Workspace shell → Presentation tour: shows (evidence: `frontend/src/App.tsx`)
- Workspace shell → Safety evidence view: shows (evidence: `frontend/src/App.tsx`)
- Workspace shell → HTTP API: calls (evidence: `README.md`)
- HTTP API → Detection orchestration: routes analysis (evidence: `backend/main.py`)
- Detection orchestration → Conversation validation: validates with (evidence: `backend/service.py`)
- Detection orchestration → Gemini detector: requests predictions (evidence: `backend/service.py`)
- Detection orchestration → Escalation scoring: scores prediction (evidence: `backend/service.py`)
- HTTP API → Dataset analysis: supports batch analysis (evidence: `README.md`)
- HTTP API → Scenario simulator: registers routes (evidence: `backend/main.py`)
- Live simulator view → Scenario simulator: gets scenarios (evidence: `README.md`)
- Scenario simulator → Local Ollama model: generates replies (evidence: `README.md`)
- Live simulator view → HTTP API: submits visible turns (evidence: `README.md`)
- Side-by-side view → HTTP API: requests analysis (evidence: `README.md`)
- Context experiment view → Experiment runners: shows saved results (evidence: `README.md`)
- Multi-turn experiment view → Experiment runners: shows saved results (evidence: `README.md`)
- Experiment runners → Detection orchestration: runs detector (evidence: `evaluation/context_experiment.py`)
- Synthetic dialogue generation → Dialogue data schema: creates records (evidence: `generation/generator.py`)
- Human annotation → Dialogue data schema: labels samples (evidence: `annotation/labeler.py`)
- Dataset importer → Dialogue data schema: builds records (evidence: `data/import_chatbotmanip.py`)
- Context model pipeline → Dialogue data schema: loads data (evidence: `models/train_context_model.py`)
- Legacy model inference → Context model pipeline: uses features (evidence: `models/inference.py`)
