# obsidiantoanki/obsidian_to_anki architecture

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

- Interactive diagram: https://gitdiagram.com/obsidiantoanki/obsidian_to_anki
- Repository: https://github.com/obsidiantoanki/obsidian_to_anki

## Overview

##### Main components
- Python Script: The standalone command-line utility (obsidian_to_anki.py and obstoanki_setup.py) that can be run outside Obsidian to scan files, generate configuration (obsidian_to_anki_config.ini), and interact with the file system.
- Communication with Anki: Both the plugin and the script use the AnkiConnect RESTful API. Show this as an external Anki component (with details like API key setup and port 8765 as specified in the README).
- Configuration & Settings: Include the default configuration files, defaults in “root/defaults”, and the extensive support for custom syntax defined via configuration (using matcher files, regex, and settings interfaces in “src/interfaces”). This represents the customization layer.
- Testing/CI Components: The “tests” directory and GitHub workflows indicate automated testing (including integration tests for various flashcard styles and folder scanning) that ensure functionality.
- Build & Deployment Artifacts: Build scripts like rollup.config.js and Dockerfile illustrate that the code is bundled and containerized; these should be represented as the build/deployment support layer.

##### Relationships and interactions
- The scanned files are parsed by the front-end module or processing scripts (using the logic in “src” and helper modules) that convert markdown to Anki-ready notes.
- Additionally, configuration management is done via local config files (ini, JSON, or via defaults) and is read/written by both the plugin and the script.
- The testing suite simulates both file input scenarios and API interactions to verify correct processing.

##### Important architectural patterns & design principles
- Separation of Concerns: There are clearly separated modules for parsing/formatting (e.g., format.ts, file.ts), configuration (settings.ts and interfaces), and integration with external systems (AnkiConnect).
- Dual Usage Path: The architecture supports two modes (GUI integration as an Obsidian plugin, and CLI usage as a Python script) while sharing common processing logic (custom syntax for flashcards) and configuration mechanisms.
- Extensibility: The extensive use of custom syntax configuration (regular expressions, support for many markdown styles) underlines a plugin/extensible design.

##### Relevant technologies, frameworks, or libraries
- TypeScript/JavaScript: For the Obsidian plugin code (located in “src”), which transforms markdown input.
- Python: For the command-line version of the tool.
- AnkiConnect: For communication with Anki.
- Docker & CI/CD: Dockerfile for containerization and GitHub workflows for continuous integration.
- Testing Frameworks: The “tests” directory indicates a combination of e2e tests and unit tests (some written in Python, some in TypeScript as indicated by .ts files).

- Labels: Name each component clearly – e.g., “Obsidian Plugin (UI & Processing)”, “Python CLI Utility”, “Anki (with AnkiConnect API)”, “Configuration Manager”, “Test Suite / CI”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input
    Vault["Obsidian Vault (Markdown Files)"]:::file

    %% External Service
    Anki["Anki (AnkiConnect API)"]:::external

    %% Subgraph: Obsidian Plugin (UI & Processing)
    subgraph "Obsidian Plugin (UI & Processing)"
        direction TB
        Plugin_Anki["src/anki.ts"]:::plugin
        Plugin_Note["src/note.ts"]:::plugin
        Plugin_Settings["src/settings.ts"]:::plugin
        Plugin_Main["main.ts & manifest.json"]:::plugin
        Plugin_Styles["styles.css"]:::plugin
    end

    %% Subgraph: Python CLI Utility
    subgraph "Python CLI Utility"
        direction TB
        CLI_Main["obsidian_to_anki.py"]:::cli
        CLI_Setup["obstoanki_setup.py"]:::cli
        CLI_Config["obsidian_to_anki_config.ini"]:::cli
        CLI_Data["obsidian_to_anki_data.json"]:::cli
    end

    %% Subgraph: Configuration Manager
    subgraph "Configuration Manager"
        direction TB
        Config_Root["root/defaults"]:::config
        Config_Interfaces["src/interfaces"]:::config
        Config_SettingData["src/setting-to-data.ts"]:::config
    end

    %% Subgraph: Test Suite / CI
    subgraph "Test Suite / CI"
        direction TB
        Test_Dir["tests"]:::testing
        CI_Dir[".github/workflows"]:::testing
    end

    %% Subgraph: Build & Deployment Support
    subgraph "Build & Deployment Support"
        direction TB
        Build_Rollup["rollup.config.js"]:::deployment
        Build_Docker["Dockerfile"]:::deployment
    end

    %% Data Flow Arrows
    Vault -->|"scan files"| Plugin_Anki
    Vault -->|"scan files"| CLI_Main

    Config_Root -->|"loads config"| Plugin_Anki
    Config_Root -->|"loads config"| CLI_Main

    Plugin_Settings -->|"formats flashcards"| Anki
    CLI_Main -->|"sends flashcards"| Anki

    Test_Dir ---|"simulate tests"| Plugin_Anki
    Test_Dir ---|"simulate tests"| CLI_Main

    Build_Rollup ---|"builds"| Plugin_Main
    Build_Rollup ---|"builds"| Plugin_Anki

    %% Click Events for Obsidian Plugin
    click Plugin_Anki "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/src/anki.ts"
    click Plugin_Note "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/src/note.ts"
    click Plugin_Settings "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/src/settings.ts"
    click Plugin_Main "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/main.ts"
    click Plugin_Styles "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/styles.css"

    %% Click Events for Python CLI Utility
    click CLI_Main "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/obsidian_to_anki.py"
    click CLI_Setup "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/obstoanki_setup.py"
    click CLI_Config "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/obsidian_to_anki_config.ini"
    click CLI_Data "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/obsidian_to_anki_data.json"

    %% Click Events for Configuration Manager
    click Config_Root "https://github.com/obsidiantoanki/obsidian_to_anki/tree/master/root/defaults"
    click Config_Interfaces "https://github.com/obsidiantoanki/obsidian_to_anki/tree/master/src/interfaces"
    click Config_SettingData "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/src/setting-to-data.ts"

    %% Click Events for Test Suite / CI
    click Test_Dir "https://github.com/obsidiantoanki/obsidian_to_anki/tree/master/tests"
    click CI_Dir "https://github.com/obsidiantoanki/obsidian_to_anki/tree/master/.github/workflows"

    %% Click Events for Build & Deployment Support
    click Build_Rollup "https://github.com/obsidiantoanki/obsidian_to_anki/blob/master/rollup.config.js"
    click Build_Docker "https://github.com/obsidiantoanki/obsidian_to_anki/tree/master/Dockerfile"

    %% Class Definitions for Colors
    classDef plugin fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef cli fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef config fill:#FFFFE0,stroke:#000,stroke-width:1px;
    classDef external fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef testing fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef deployment fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef file fill:#E6E6FA,stroke:#000,stroke-width:1px;
```
