# matthias-stemmler/annimate architecture

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

- Interactive diagram: https://gitdiagram.com/matthias-stemmler/annimate
- Repository: https://github.com/matthias-stemmler/annimate

## Overview

##### Project type and purpose
- Annimate is a cross-platform desktop application (Windows, macOS, Linux) built with Tauri.
- It provides a friendly GUI to export query results (matches) from an external ANNIS corpus-query system into CSV or Excel formats.
- The core functionality (corpus import, query execution, result formatting) lives in a Rust library crate (`annimate_core`), while the desktop UI and native integrations live in the `annimate_desktop` Tauri app (Rust + React/TypeScript).

##### High-level file-structure analysis
- Top-level crates/configs:
- `annimate_core/` (Rust library, Cargo.toml, `src/` modules: import, query, cache, format, export)
- `annimate_desktop/` (Tauri app)
– `src-tauri/` (Rust Tauri backend: `api.rs`, `state.rs`, `main.rs`, build.rs)
– `src/` (React app in TypeScript: UI components, store, API wrappers)
- CI/workflows (`.github/workflows/` for cargo + pnpm lint/build/test/release)
- Docs (`docs/`, `pages/`) and user-guide

##### Key insights from the README
- Annimate sits alongside the ANNIS web interface, focusing solely on exporting results.
- Relies on the graphANNIS library under the hood (Rust dependency) to query ANNIS.
- Exports one row per match, with KWIC context and metadata.
- Packaged via Tauri for native installers and auto-updates.

##### Main components and their interactions
a. Presentation layer (React UI)
- Components under `annimate_desktop/src/components`
- Dispatches user actions (select corpora, run query, export)
- Uses `src/lib/api.ts` for invoking backend commands via Tauri’s JavaScript‐to-Rust bridge
b. Application layer (Tauri backend)
- `src-tauri/src/main.rs` registers commands
- `api.rs` defines functions exposed to JS (e.g., `run_query`, `export_matches`)
- `delayed_queue.rs` manages long-running tasks without blocking UI
- Maintains in-memory `state.rs` for current project config
c. Domain/core layer (`annimate_core` crate)
- Modules: `import` (reads GraphML/RELANNIS archives), `query` (builds/executes AQL queries via graphANNIS), `cache` (caches query results), `format` (CSV/XLSX writers), `metadata`, `project` (project config & serialization)
- Exposes a Rust API consumed by Tauri backend
d. Infrastructure/external services
- External ANNIS server (over HTTP via graphANNIS client)
- Local filesystem (read project archives, write CSV/XLSX exports)
- Auto-update service (Tauri updater)
- CI/CD pipeline (GitHub Actions invoking Cargo and pnpm)

##### Architectural patterns & design principles
- Layered architecture: Presentation (React) → Application (Tauri commands) → Domain (Rust core library) → Infrastructure (external ANNIS, filesystem).
- Separation of concerns: UI purely handles state/UX; core library is UI-agnostic.
- Asynchronous command queue to keep UI responsive.
- Use of Rust’s module system and strong typing for reliability.
- Tauri’s invoke pattern for secure, sandboxed JS↔Rust communication.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Presentation Layer
  subgraph "Presentation" 
    ReactMain["React UI\n(main.tsx)"]:::frontend
    ReactComponents["Components\n(directory)"]:::frontend
  end

  %% Application Layer
  subgraph "Application"
    APIWrapperTS["API Wrapper\n(api.ts / api-types.ts)"]:::frontend
    Preload["JS Preload & Invoke Bridge\n(preload.rs)"]:::backend
    BackendMain["Tauri Rust Backend\n(main.rs)"]:::rust
    BackendAPI["api.rs"]:::rust
    BackendState["state.rs"]:::rust
    BackendQueue["delayed_queue.rs"]:::rust
  end

  %% Domain Layer
  subgraph "Domain"
    CoreLib["annimate_core\n(lib.rs)"]:::rust
    Import["import.rs"]:::rust
    Query["query.rs"]:::rust
    Cache["cache.rs"]:::rust
    FormatMod["format/mod.rs"]:::rust
    FormatCSV["format/csv.rs"]:::rust
    FormatXLSX["format/xlsx.rs"]:::rust
    FormatTable["format/table.rs"]:::rust
    Metadata["metadata.rs"]:::rust
    Project["project.rs"]:::rust
  end

  %% Infrastructure Layer
  subgraph "Infrastructure"
    ANNICLOUD["ANNIS Server"]:::infra
    Filesystem["Local Filesystem"]:::infra
  end

  %% DevOps
  CI["GitHub Actions"]:::devops

  %% Connections
  ReactMain -->|"calls API"| APIWrapperTS
  APIWrapperTS -->|"invoke run_query()"| Preload
  Preload -->|"invoke command"| BackendMain
  BackendMain --> BackendAPI
  BackendMain --> BackendState
  BackendMain --> BackendQueue

  BackendAPI -->|"run_query()/export_matches()"| CoreLib
  CoreLib -->|"HTTP via graphANNIS"| ANNICLOUD
  ANNICLOUD --> CoreLib
  CoreLib --> BackendAPI
  CoreLib -->|"write CSV/XLSX"| Filesystem

  BackendAPI -->|"return data"| Preload
  Preload -->|"emit event"| ReactMain

  CI -.-> ReactMain
  CI -.-> APIWrapperTS
  CI -.-> BackendMain

  %% Click Events
  click ReactMain "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src/main.tsx"
  click ReactComponents "https://github.com/matthias-stemmler/annimate/tree/main/annimate_desktop/src/components/"
  click Preload "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src-tauri/src/preload.rs"
  click APIWrapperTS "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src/lib/api.ts"
  click BackendMain "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src-tauri/src/main.rs"
  click BackendAPI "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src-tauri/src/api.rs"
  click BackendState "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src-tauri/src/state.rs"
  click BackendQueue "https://github.com/matthias-stemmler/annimate/blob/main/annimate_desktop/src-tauri/src/delayed_queue.rs"
  click CoreLib "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/lib.rs"
  click Import "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/import.rs"
  click Query "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/query.rs"
  click Cache "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/cache.rs"
  click FormatMod "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/format/mod.rs"
  click FormatCSV "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/format/csv.rs"
  click FormatXLSX "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/format/xlsx.rs"
  click FormatTable "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/format/table.rs"
  click Metadata "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/metadata.rs"
  click Project "https://github.com/matthias-stemmler/annimate/blob/main/annimate_core/src/project.rs"
  click CI "https://github.com/matthias-stemmler/annimate/tree/main/.github/workflows/"

  %% Styles
  classDef frontend fill:#D6EAF8,stroke:#1B4F72,color:#1B2631
  classDef backend fill:#F9E79F,stroke:#7D6608,color:#1B2631
  classDef rust fill:#F5B7B1,stroke:#78281F,color:#1B2631
  classDef infra fill:#D5D8DC,stroke:#424949,color:#1B2631
  classDef devops fill:#D2B4DE,stroke:#512E5F,color:#1B2631
```
