# abdnh/anki-copycat-importer architecture

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

- Interactive diagram: https://gitdiagram.com/abdnh/anki-copycat-importer
- Repository: https://github.com/abdnh/anki-copycat-importer

## Overview

1. **What this repo is**
   - This is an **Anki add-on** called “Copycat Importer.” Its purpose is to import content from other study apps into Anki, with documentation and release metadata for AnkiWeb (`addon.json`, `ankiweb_page.html`, `README.md`, `CHANGELOG.md`).

2. **Top-level runtime boundary**
   - The repo is split into a **Python add-on core** under `src/` and a **TypeScript/Svelte UI** under `ts/`.
   - Python runs inside Anki’s add-on environment and owns import logic, backend services, config, and integration with Anki.
   - The TS app provides the interactive UI shown to the user, likely embedded in a webview/dialog rather than as a standalone website.

3. **Entry points and Anki integration**
   - `src/main.py` is the main add-on entry.
   - `src/menu.py` wires the add-on into Anki’s menus/actions.
   - `src/gui/dialog.py`, `src/gui/web.py`, and `src/gui/sveltekit_web.py` suggest the add-on opens a custom dialog/web container to host the frontend.

4. **Frontend architecture**
   - `ts/` is a SvelteKit app built with Vite.
   - `ts/src/routes/help/+page.svelte` and `ts/src/lib/` indicate the frontend includes at least a help/support UI and shared client logic.
   - `ts/src/lib/backend.ts` is the frontend’s bridge to the Python side, so the UI is not self-contained; it depends on backend-provided data/actions.

5. **Backend service layer**
   - `src/backend/server.py` and `src/backend/services.py` form the Python service boundary exposed to the UI.
   - `proto/backend.proto` and `proto/generic.proto` define the contract between frontend and backend, which implies typed request/response messaging rather than ad hoc coupling.
   - This is the main seam to draw in an architecture diagram: **UI → backend API/service layer → importer logic / Anki integration**.

6. **Importer pipeline**
   - `src/importers/` contains the domain-specific import logic.
   - There are dedicated importers for at least two source families: `algoapp.py` and `noji.py`.
   - Shared modules like `importer.py`, `utils.py`, `httpclient.py`, and `errors.py` indicate a common normalization pipeline: fetch or read source data, transform it into a canonical internal model, then hand it off to Anki-facing services.

7. **Source-specific UI and workflows**
   - `src/gui/widgets/algoapp.py` and `src/gui/widgets/noji.py` mirror the importer split on the UI side.
   - This suggests the user can choose between different source workflows, each with its own form/state, while sharing a common widget base in `src/gui/widgets/widget.py`.
   - `src/gui/importer.py` likely coordinates the UI selection and importer execution flow.

8. **Configuration and user data**
   - `src/config.py`, `src/config.json`, `src/config.schema.json`, and `src/config.md` show a structured configuration system with validation/schema documentation.
   - `src/user_files/README.txt` indicates the add-on stores user-specific persistent files separately from code.
   - `src/consts.py`, `src/errors.py`, and `src/log.py` provide cross-cutting constants, error handling, and diagnostics.

9. **Documentation and external-facing assets**
   - `docs/` is a separate documentation site built with mdBook (`docs/book.toml`, `docs/src/`).
   - `technical.md` and the docs pages (`intro.md`, `algoapp.md`, `noji.md`, `support.md`) explain usage and source-specific behavior.
   - `design` files (`designer/*.ui`) suggest some GUI is also authored in Qt Designer format, even if the shipped UI is web-based.

10. **Build, release, and quality tooling**
   - Python packaging and dependency management are driven by `pyproject.toml` and `uv.lock`.
   - The frontend has its own package boundary in `ts/package.json`, with lint/build/test tooling under `ts/`.
   - GitHub Actions in `.github/workflows/` cover CI, docs builds, and release creation.
   - `tests/` contains Python tests, while `ts/src/demo.spec.ts` indicates frontend tests as well.

11. **Likely end-to-end data flow**
   - User opens the add-on from Anki.
   - Python creates/hosts the UI and loads the Svelte frontend.
   - The user selects a source type and provides input or credentials.
   - The frontend calls the Python backend via the proto-defined bridge.
   - The backend invokes the appropriate importer, which may fetch remote data through `httpclient.py`, normalize it, and pass the result into Anki through the add-on’s services layer.

12. **Useful diagram boundaries**
   - Draw three main boxes: **Anki host / add-on shell**, **Python backend + importers**, and **TS/Svelte frontend**.
   - Show a service/API boundary between frontend and Python using the proto contract.
   - Show external dependencies only where they matter: Anki runtime, source-app endpoints reached by importers, and docs/release distribution via AnkiWeb/GitHub.

Main entry points: [`src/importers/importer.py`](https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/importer.py) (Importer core), [`src/backend/services.py`](https://github.com/abdnh/anki-copycat-importer/blob/main/src/backend/services.py) (Services), [`ts/src/lib/backend.ts`](https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/lib/backend.ts) (Backend bridge), [`src/main.py`](https://github.com/abdnh/anki-copycat-importer/blob/main/src/main.py) (Main entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_anki_host["Anki host"]
  node_src_main["Main entry<br/>addon entry<br/>[main.py]"]
  node_src_menu["Menu wiring<br/>anki integration<br/>[menu.py]"]
  node_src_dialog["Dialog<br/>ui shell<br/>[dialog.py]"]
  node_src_web["Web host<br/>ui container<br/>[web.py]"]
  node_src_sveltekit_web["Svelte host<br/>frontend bridge<br/>[sveltekit_web.py]"]
end

subgraph group_python_core["Python core"]
  node_src_server["Backend server<br/>api boundary<br/>[server.py]"]
  node_src_services["Services<br/>domain service<br/>[services.py]"]
  node_src_importer_core["Importer core<br/>pipeline core<br/>[importer.py]"]
  node_src_algo_importer["Algo importer<br/>source importer<br/>[algoapp.py]"]
  node_src_noji_importer["Noji importer<br/>source importer<br/>[noji.py]"]
  node_src_httpclient(("HTTP client<br/>integration<br/>[httpclient.py]"))
  node_src_config["Config<br/>settings<br/>[config.py]"]
  node_src_errors["Errors<br/>shared types<br/>[errors.py]"]
end

subgraph group_ts_frontend["TS frontend"]
  node_ts_backend["Backend bridge<br/>ui client<br/>[backend.ts]"]
  node_ts_help["Help page<br/>ui page<br/>[+page.svelte]"]
  node_ts_lib["Shared UI<br/>ui library<br/>[index.ts]"]
end

subgraph group_docs_tooling["Docs & tooling"]
  node_docs_intro["Docs<br/>documentation<br/>[intro.md]"]
  node_addon_json["Addon manifest<br/>release metadata<br/>[addon.json]"]
  node_github_actions["CI & release<br/>automation<br/>[ci.yml]"]
end

node_src_main -->|"registers"| node_src_menu
node_src_main -->|"opens"| node_src_dialog
node_src_dialog -->|"hosts"| node_src_web
node_src_web -->|"embeds"| node_src_sveltekit_web
node_src_sveltekit_web -->|"calls"| node_ts_backend
node_ts_backend -->|"protocol"| node_src_server
node_src_server -->|"delegates"| node_src_services
node_src_services -->|"orchestrates"| node_src_importer_core
node_src_importer_core -->|"dispatches"| node_src_algo_importer
node_src_importer_core -->|"dispatches"| node_src_noji_importer
node_src_algo_importer -->|"fetches"| node_src_httpclient
node_src_noji_importer -->|"fetches"| node_src_httpclient
node_src_importer_core -->|"raises"| node_src_errors
node_src_services -->|"reads"| node_src_config
node_ts_backend -->|"exports"| node_ts_lib
node_ts_lib -->|"renders"| node_ts_help
node_docs_intro -.->|"documents"| node_addon_json
node_github_actions -.->|"builds"| node_docs_intro

click node_src_main "https://github.com/abdnh/anki-copycat-importer/blob/main/src/main.py"
click node_src_menu "https://github.com/abdnh/anki-copycat-importer/blob/main/src/menu.py"
click node_src_dialog "https://github.com/abdnh/anki-copycat-importer/blob/main/src/gui/dialog.py"
click node_src_web "https://github.com/abdnh/anki-copycat-importer/blob/main/src/gui/web.py"
click node_src_sveltekit_web "https://github.com/abdnh/anki-copycat-importer/blob/main/src/gui/sveltekit_web.py"
click node_src_server "https://github.com/abdnh/anki-copycat-importer/blob/main/src/backend/server.py"
click node_src_services "https://github.com/abdnh/anki-copycat-importer/blob/main/src/backend/services.py"
click node_src_importer_core "https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/importer.py"
click node_src_algo_importer "https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/algoapp.py"
click node_src_noji_importer "https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/noji.py"
click node_src_httpclient "https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/httpclient.py"
click node_src_config "https://github.com/abdnh/anki-copycat-importer/blob/main/src/config.py"
click node_src_errors "https://github.com/abdnh/anki-copycat-importer/blob/main/src/errors.py"
click node_ts_backend "https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/lib/backend.ts"
click node_ts_help "https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/routes/help/+page.svelte"
click node_ts_lib "https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/lib/index.ts"
click node_docs_intro "https://github.com/abdnh/anki-copycat-importer/blob/main/docs/src/intro.md"
click node_addon_json "https://github.com/abdnh/anki-copycat-importer/blob/main/addon.json"
click node_github_actions "https://github.com/abdnh/anki-copycat-importer/blob/main/.github/workflows/ci.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_src_main,node_src_menu,node_src_dialog,node_src_web,node_src_sveltekit_web toneBlue
class node_src_server,node_src_services,node_src_importer_core,node_src_algo_importer,node_src_noji_importer,node_src_httpclient,node_src_config,node_src_errors toneAmber
class node_ts_backend,node_ts_help,node_ts_lib toneMint
class node_docs_intro,node_addon_json,node_github_actions toneRose
```

## Components

### Anki host

Anki runtime and add-on entry surface

- [Main entry](https://github.com/abdnh/anki-copycat-importer/blob/main/src/main.py): addon entry · Loads the add-on inside Anki and starts runtime wiring · `src/main.py`
- [Menu wiring](https://github.com/abdnh/anki-copycat-importer/blob/main/src/menu.py): anki integration · Registers add-on actions into Anki menus · `src/menu.py`
- [Dialog](https://github.com/abdnh/anki-copycat-importer/blob/main/src/gui/dialog.py): ui shell · Top-level dialog used to open the importer experience · `src/gui/dialog.py`
- [Web host](https://github.com/abdnh/anki-copycat-importer/blob/main/src/gui/web.py): ui container · Webview/container abstraction for the embedded frontend · `src/gui/web.py`
- [Svelte host](https://github.com/abdnh/anki-copycat-importer/blob/main/src/gui/sveltekit_web.py): frontend bridge · Hosts the SvelteKit app inside the Python UI shell · `src/gui/sveltekit_web.py`

### Python core

Add-on backend, importer pipeline, and Anki integration

- [Backend server](https://github.com/abdnh/anki-copycat-importer/blob/main/src/backend/server.py): api boundary · Exposes backend actions and requests to the UI · `src/backend/server.py`
- [Services](https://github.com/abdnh/anki-copycat-importer/blob/main/src/backend/services.py): domain service · Coordinates import workflows and backend operations · `src/backend/services.py`
- [Importer core](https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/importer.py): pipeline core · Shared importer abstractions and orchestration · `src/importers/importer.py`
- [Algo importer](https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/algoapp.py): source importer · Importer for Algo-style source data · `src/importers/algoapp.py`
- [Noji importer](https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/noji.py): source importer · Importer for Noji-style source data · `src/importers/noji.py`
- [HTTP client](https://github.com/abdnh/anki-copycat-importer/blob/main/src/importers/httpclient.py): integration · Remote fetching for source-app data · `src/importers/httpclient.py`
- [Config](https://github.com/abdnh/anki-copycat-importer/blob/main/src/config.py): settings · Structured configuration and schema validation · `src/config.py`
- [Errors](https://github.com/abdnh/anki-copycat-importer/blob/main/src/errors.py): shared types · Shared exception and error definitions · `src/errors.py`

### TS frontend

SvelteKit UI hosted inside the add-on

- [Backend bridge](https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/lib/backend.ts): ui client · Frontend-side API wrapper for Python backend calls · `ts/src/lib/backend.ts`
- [Help page](https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/routes/help/+page.svelte): ui page · User-facing help and support view · `ts/src/routes/help/+page.svelte`
- [Shared UI](https://github.com/abdnh/anki-copycat-importer/blob/main/ts/src/lib/index.ts): ui library · Shared frontend logic and exports · `ts/src/lib/index.ts`

### Docs & tooling

Documentation, packaging, tests, and release automation

- [Docs](https://github.com/abdnh/anki-copycat-importer/blob/main/docs/src/intro.md): documentation · mdBook documentation for usage and source-specific behavior · `docs/src/intro.md`
- [Addon manifest](https://github.com/abdnh/anki-copycat-importer/blob/main/addon.json): release metadata · AnkiWeb/add-on metadata and packaging identity · `addon.json`
- [CI & release](https://github.com/abdnh/anki-copycat-importer/blob/main/.github/workflows/ci.yml): automation · Build, test, docs, and release workflows · `.github/workflows/ci.yml`

## Connections

- Main entry → Menu wiring: registers · Main add-on entry installs menu actions
- Main entry → Dialog: opens · Main entry launches the importer UI shell
- Dialog → Web host: hosts · Dialog contains the web container
- Web host → Svelte host: embeds · Web container loads the SvelteKit frontend
- Svelte host → Backend bridge: calls · Frontend shell uses the TS backend bridge
- Backend bridge → Backend server: protocol · UI talks to Python over the proto-defined backend contract
- Backend server → Services: delegates · API layer routes requests into backend services
- Services → Importer core: orchestrates · Services coordinate importer execution
- Importer core → Algo importer: dispatches · Core selects the Algo-specific importer
- Importer core → Noji importer: dispatches · Core selects the Noji-specific importer
- Algo importer → HTTP client: fetches · Algo importer may retrieve remote source data
- Noji importer → HTTP client: fetches · Noji importer may retrieve remote source data
- Importer core → Errors: raises · Shared importer errors propagate through the pipeline
- Services → Config: reads · Backend services use structured configuration
- Backend bridge → Shared UI: exports · Backend bridge is consumed by shared UI code
- Shared UI → Help page: renders · Shared UI supports the help page
- Docs → Addon manifest: documents · Documentation explains add-on metadata and usage
- CI & release → Docs: builds · CI covers docs generation and validation
