# gmphto/tera architecture

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

- Interactive diagram: https://gitdiagram.com/gmphto/tera
- Repository: https://github.com/gmphto/tera

## Overview

TERA is a local-first instrument-palette desktop application: users import local samples, build a library, configure a kick-to-bass context, request ranked recommendations, and audition selections. The map includes the documented Tauri/local-service shell and the analysis, library, and recommendation modules indicated by the source index. Evaluation and outcome-related modules are represented as product subsystems, but their runtime connections are omitted where the excerpts do not establish them. Several backend capabilities are unsampled, so their nodes use supported directory paths and only documented or indexed relationships are shown.

Main entry points: [`frontend/src/App.tsx`](https://github.com/gmphto/tera/blob/master/frontend/src/App.tsx) (Desktop UI), [`backend/api`](https://github.com/gmphto/tera/tree/master/backend/api) (API handlers), [`backend/library/repository.py`](https://github.com/gmphto/tera/blob/master/backend/library/repository.py) (Library repository), [`backend/api/imports.py`](https://github.com/gmphto/tera/blob/master/backend/api/imports.py) (Library import)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_app["Desktop UI<br/>[App.tsx]"]
  node_status["Service status"]
  node_service_bridge["Service bridge<br/>[bridge.ts]"]
  node_palette_ui["Palette controls<br/>[PalettePanel.tsx]"]
  node_library_ui["Library browser<br/>[LibraryBrowser.tsx]"]
  node_recommendation_ui["Recommendations UI"]
  node_audition_ui["Audition controls"]
  node_tauri["Tauri host<br/>[main.rs]"]
end

subgraph group_service["Local API"]
  node_service_process["Loopback service<br/>[service.py]"]
  node_api_routes["API handlers"]
end

subgraph group_library["Sample library"]
  node_library_import["Library import<br/>[imports.py]"]
  node_scanner["Folder scanning<br/>[scanner.py]"]
  node_worker["Analysis worker<br/>[worker.py]"]
  node_queue["Analysis queue<br/>[queue.py]"]
  node_indexer["Pending index<br/>[indexer.py]"]
  node_schema[("SQLite schema<br/>[schema.py]")]
  node_repository["Library repository<br/>[repository.py]"]
  node_outcomes["Audition outcomes<br/>[outcomes.py]"]
end

subgraph group_analysis["Audio analysis"]
  node_contracts["Domain contracts<br/>[contracts.py]"]
  node_wav["WAV reader<br/>[audio.py]"]
  node_batch["Batch analysis<br/>[batch.py]"]
end

subgraph group_intelligence["Palette intelligence"]
  node_retrieval["Candidate retrieval<br/>[retrieval.py]"]
  node_palette_retrieval["Feature retrieval<br/>[retrieval.py]"]
  node_compatibility["Compatibility rules<br/>[compatibility.py]"]
  node_ranking["Candidate ranking<br/>[ranking.py]"]
  node_jev["Jev judgments<br/>[jev.py]"]
  node_questions["Decision questions<br/>[questions.py]"]
  node_palette_model["Palette model<br/>[model.py]"]
  node_evaluation["Evaluation tools"]
end

node_user(("Musician"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_status
node_app -->|"renders"| node_palette_ui
node_app -->|"renders"| node_library_ui
node_app -->|"renders"| node_recommendation_ui
node_app -->|"starts"| node_service_bridge
node_palette_ui -.->|"offers"| node_audition_ui
node_tauri -->|"hosts"| node_service_process
node_service_bridge -->|"discovers service"| node_tauri
node_status -.->|"polls health"| node_service_process
node_service_process -->|"dispatches"| node_api_routes
node_api_routes -->|"routes imports"| node_library_import
node_api_routes -->|"routes library access"| node_repository
node_api_routes -->|"requests recommendations"| node_retrieval
node_api_routes -->|"requests ranking"| node_ranking
node_api_routes -->|"requests judgments"| node_jev
node_library_import -->|"uses"| node_scanner
node_library_import -->|"enqueues"| node_queue
node_library_import -->|"records samples"| node_repository
node_worker -->|"finds pending work"| node_indexer
node_worker -->|"claims work"| node_queue
node_worker -->|"analyzes samples"| node_batch
node_batch -->|"loads audio"| node_wav
node_batch -->|"produces samples"| node_contracts
node_repository -->|"uses connection"| node_schema
node_retrieval -->|"reads library"| node_repository
node_retrieval -->|"orders candidates"| node_palette_retrieval
node_retrieval -->|"filters candidates"| node_compatibility
node_ranking -->|"applies rules"| node_compatibility
node_jev -->|"uses questions"| node_questions
node_questions -->|"uses rules"| node_compatibility
node_palette_model -->|"uses sample analysis"| node_contracts
node_outcomes -.->|"records outcomes"| node_repository

click node_app "https://github.com/gmphto/tera/blob/master/frontend/src/App.tsx"
click node_status "https://github.com/gmphto/tera/blob/master/frontend/src/features/service/ServiceStatusPanel.tsx"
click node_service_bridge "https://github.com/gmphto/tera/blob/master/frontend/src/features/service/bridge.ts"
click node_palette_ui "https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/PalettePanel.tsx"
click node_library_ui "https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/browser/LibraryBrowser.tsx"
click node_recommendation_ui "https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/recommendations/RecommendationPanel.tsx"
click node_audition_ui "https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/audition/AuditionControls.tsx"
click node_tauri "https://github.com/gmphto/tera/blob/master/frontend/src-tauri/src/main.rs"
click node_service_process "https://github.com/gmphto/tera/blob/master/backend/api/service.py"
click node_api_routes "https://github.com/gmphto/tera/tree/master/backend/api"
click node_contracts "https://github.com/gmphto/tera/blob/master/backend/contracts.py"
click node_wav "https://github.com/gmphto/tera/blob/master/backend/audio.py"
click node_batch "https://github.com/gmphto/tera/blob/master/backend/analysis/batch.py"
click node_library_import "https://github.com/gmphto/tera/blob/master/backend/api/imports.py"
click node_scanner "https://github.com/gmphto/tera/blob/master/backend/library/scanner.py"
click node_worker "https://github.com/gmphto/tera/blob/master/backend/library/worker.py"
click node_queue "https://github.com/gmphto/tera/blob/master/backend/library/queue.py"
click node_indexer "https://github.com/gmphto/tera/blob/master/backend/library/indexer.py"
click node_schema "https://github.com/gmphto/tera/blob/master/backend/library/schema.py"
click node_repository "https://github.com/gmphto/tera/blob/master/backend/library/repository.py"
click node_retrieval "https://github.com/gmphto/tera/blob/master/backend/library/retrieval.py"
click node_palette_retrieval "https://github.com/gmphto/tera/blob/master/backend/palette/retrieval.py"
click node_compatibility "https://github.com/gmphto/tera/blob/master/backend/palette/compatibility.py"
click node_ranking "https://github.com/gmphto/tera/blob/master/backend/palette/ranking.py"
click node_jev "https://github.com/gmphto/tera/blob/master/backend/intelligence/jev.py"
click node_questions "https://github.com/gmphto/tera/blob/master/backend/intelligence/questions.py"
click node_palette_model "https://github.com/gmphto/tera/blob/master/backend/palette/model.py"
click node_evaluation "https://github.com/gmphto/tera/tree/master/backend/evaluation"
click node_outcomes "https://github.com/gmphto/tera/blob/master/backend/api/outcomes.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_status,node_service_bridge,node_palette_ui,node_library_ui,node_recommendation_ui,node_audition_ui,node_tauri toneBlue
class node_service_process,node_api_routes toneAmber
class node_library_import,node_scanner,node_worker,node_queue,node_indexer,node_schema,node_repository,node_outcomes toneMint
class node_contracts,node_wav,node_batch toneRose
class node_retrieval,node_palette_retrieval,node_compatibility,node_ranking,node_jev,node_questions,node_palette_model,node_evaluation,node_user toneIndigo
```

## Components

### Desktop experience

- [Desktop UI](https://github.com/gmphto/tera/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Service status](https://github.com/gmphto/tera/blob/master/frontend/src/features/service/ServiceStatusPanel.tsx): `frontend/src/features/service/ServiceStatusPanel.tsx`
- [Service bridge](https://github.com/gmphto/tera/blob/master/frontend/src/features/service/bridge.ts): `frontend/src/features/service/bridge.ts`
- [Palette controls](https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/PalettePanel.tsx): `frontend/src/features/palette/PalettePanel.tsx`
- [Library browser](https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/browser/LibraryBrowser.tsx): `frontend/src/features/palette/browser/LibraryBrowser.tsx`
- [Recommendations UI](https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/recommendations/RecommendationPanel.tsx): `frontend/src/features/palette/recommendations/RecommendationPanel.tsx`
- [Audition controls](https://github.com/gmphto/tera/blob/master/frontend/src/features/palette/audition/AuditionControls.tsx): `frontend/src/features/palette/audition/AuditionControls.tsx`
- [Tauri host](https://github.com/gmphto/tera/blob/master/frontend/src-tauri/src/main.rs): `frontend/src-tauri/src/main.rs`

### Local API

- [Loopback service](https://github.com/gmphto/tera/blob/master/backend/api/service.py): `backend/api/service.py`
- [API handlers](https://github.com/gmphto/tera/tree/master/backend/api): `backend/api`

### Sample library

- [Library import](https://github.com/gmphto/tera/blob/master/backend/api/imports.py): `backend/api/imports.py`
- [Folder scanning](https://github.com/gmphto/tera/blob/master/backend/library/scanner.py): `backend/library/scanner.py`
- [Analysis worker](https://github.com/gmphto/tera/blob/master/backend/library/worker.py): `backend/library/worker.py`
- [Analysis queue](https://github.com/gmphto/tera/blob/master/backend/library/queue.py): `backend/library/queue.py`
- [Pending index](https://github.com/gmphto/tera/blob/master/backend/library/indexer.py): `backend/library/indexer.py`
- [SQLite schema](https://github.com/gmphto/tera/blob/master/backend/library/schema.py): `backend/library/schema.py`
- [Library repository](https://github.com/gmphto/tera/blob/master/backend/library/repository.py): `backend/library/repository.py`
- [Audition outcomes](https://github.com/gmphto/tera/blob/master/backend/api/outcomes.py): `backend/api/outcomes.py`

### Audio analysis

- [Domain contracts](https://github.com/gmphto/tera/blob/master/backend/contracts.py): `backend/contracts.py`
- [WAV reader](https://github.com/gmphto/tera/blob/master/backend/audio.py): `backend/audio.py`
- [Batch analysis](https://github.com/gmphto/tera/blob/master/backend/analysis/batch.py): `backend/analysis/batch.py`

### Palette intelligence

- [Candidate retrieval](https://github.com/gmphto/tera/blob/master/backend/library/retrieval.py): `backend/library/retrieval.py`
- [Feature retrieval](https://github.com/gmphto/tera/blob/master/backend/palette/retrieval.py): `backend/palette/retrieval.py`
- [Compatibility rules](https://github.com/gmphto/tera/blob/master/backend/palette/compatibility.py): `backend/palette/compatibility.py`
- [Candidate ranking](https://github.com/gmphto/tera/blob/master/backend/palette/ranking.py): `backend/palette/ranking.py`
- [Jev judgments](https://github.com/gmphto/tera/blob/master/backend/intelligence/jev.py): `backend/intelligence/jev.py`
- [Decision questions](https://github.com/gmphto/tera/blob/master/backend/intelligence/questions.py): `backend/intelligence/questions.py`
- [Palette model](https://github.com/gmphto/tera/blob/master/backend/palette/model.py): `backend/palette/model.py`
- [Evaluation tools](https://github.com/gmphto/tera/tree/master/backend/evaluation): `backend/evaluation`

### Other components

- **Musician**

## Connections

- Musician → Desktop UI: uses (evidence: `frontend/src/App.tsx`)
- Desktop UI → Service status: renders (evidence: `frontend/src/App.tsx`)
- Desktop UI → Palette controls: renders (evidence: `frontend/src/App.tsx`)
- Desktop UI → Library browser: renders (evidence: `frontend/src/App.tsx`)
- Desktop UI → Recommendations UI: renders (evidence: `frontend/src/App.tsx`)
- Desktop UI → Service bridge: starts (evidence: `frontend/src/App.tsx`)
- Palette controls → Audition controls: offers
- Tauri host → Loopback service: hosts
- Service bridge → Tauri host: discovers service (evidence: `frontend/src/features/service/bridge.ts`)
- Service status → Loopback service: polls health
- Loopback service → API handlers: dispatches (evidence: `backend/api/service.py`)
- API handlers → Library import: routes imports (evidence: `backend/api/service.py`)
- API handlers → Library repository: routes library access (evidence: `backend/api/service.py`)
- API handlers → Candidate retrieval: requests recommendations (evidence: `backend/api/recommendations.py`)
- API handlers → Candidate ranking: requests ranking (evidence: `backend/api/recommendations.py`)
- API handlers → Jev judgments: requests judgments (evidence: `backend/api/recommendations.py`)
- Library import → Folder scanning: uses (evidence: `backend/api/imports.py`)
- Library import → Analysis queue: enqueues (evidence: `backend/api/imports.py`)
- Library import → Library repository: records samples (evidence: `backend/api/imports.py`)
- Analysis worker → Pending index: finds pending work (evidence: `backend/library/worker.py`)
- Analysis worker → Analysis queue: claims work (evidence: `backend/library/worker.py`)
- Analysis worker → Batch analysis: analyzes samples (evidence: `backend/library/worker.py`)
- Batch analysis → WAV reader: loads audio (evidence: `backend/analysis/batch.py`)
- Batch analysis → Domain contracts: produces samples (evidence: `backend/analysis/batch.py`)
- Library repository → SQLite schema: uses connection (evidence: `backend/library/repository.py`)
- Candidate retrieval → Library repository: reads library (evidence: `backend/library/retrieval.py`)
- Candidate retrieval → Feature retrieval: orders candidates (evidence: `backend/library/retrieval.py`)
- Candidate retrieval → Compatibility rules: filters candidates (evidence: `backend/library/retrieval.py`)
- Candidate ranking → Compatibility rules: applies rules (evidence: `backend/palette/ranking.py`)
- Jev judgments → Decision questions: uses questions (evidence: `backend/intelligence/jev.py`)
- Decision questions → Compatibility rules: uses rules (evidence: `backend/intelligence/questions.py`)
- Palette model → Domain contracts: uses sample analysis (evidence: `backend/palette/model.py`)
- Audition outcomes → Library repository: records outcomes
