How abdnh/anki-copycat-importer works
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: importer.py Importer core · services.py Services · backend.ts Backend bridge · main.py Main entry
Components 19
Anki host
Anki runtime and add-on entry surface
- Main entry · Loads the add-on inside Anki and starts runtime wiring
src/main.py - Menu wiring · Registers add-on actions into Anki menus
src/menu.py - Dialog · Top-level dialog used to open the importer experience
src/gui/dialog.py - Web host · Webview/container abstraction for the embedded frontend
src/gui/web.py - Svelte host · 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 · Exposes backend actions and requests to the UI
src/backend/server.py - Services · Coordinates import workflows and backend operations
src/backend/services.py - Importer core · Shared importer abstractions and orchestration
src/importers/importer.py - Algo importer · Importer for Algo-style source data
src/importers/algoapp.py - Noji importer · Importer for Noji-style source data
src/importers/noji.py - HTTP client · Remote fetching for source-app data
src/importers/httpclient.py - Config · Structured configuration and schema validation
src/config.py - Errors · Shared exception and error definitions
src/errors.py
TS frontend
SvelteKit UI hosted inside the add-on
- Backend bridge · Frontend-side API wrapper for Python backend calls
ts/src/lib/backend.ts - Help page · User-facing help and support view
ts/src/routes/help/+page.svelte - Shared UI · Shared frontend logic and exports
ts/src/lib/index.ts
Docs & tooling
Documentation, packaging, tests, and release automation
- Docs · mdBook documentation for usage and source-specific behavior
docs/src/intro.md - Addon manifest · AnkiWeb/add-on metadata and packaging identity
addon.json - CI & release · Build, test, docs, and release workflows
.github/workflows/ci.yml
Connections 18
- 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