# ecuidev/obsidian-quiz-generator architecture

> Architecture diagram of the GitHub repository ecuidev/obsidian-quiz-generator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ecuidev/obsidian-quiz-generator
- Repository: https://github.com/ecuidev/obsidian-quiz-generator

## Overview

##### Main Components
- UI Layer:
- Located in the src/ui directory (with subdirectories for components, quiz, and selectors).
- Contains interactive components (e.g., AnswerInput.tsx, QuizModal.tsx, ModalButton.tsx) that enable users to interact with the quiz generator (e.g., generating questions, reviewing quizzes, and selecting folders/notes).
- Generator Modules (Business Logic):
- Found under src/generators, where each subdirectory (openai, google, anthropic, etc.) implements a provider-specific generator along with its corresponding models.
- A generator factory (generatorFactory.ts) encapsulates the logic to choose the appropriate generator for the configured provider.
- Settings and Configuration:
- Organized in src/settings with subdivisions for general settings, generation settings, saving settings, and model-specific settings.
- These modules define configuration parameters such as API keys, generation rules, file paths for saving quizzes, and provider-specific configurations.
- Services:
- In src/services, with modules like quizReviewer.ts and quizSaver.ts, which are responsible for processing quiz data, handling reviews, and persistence.
- Utilities:
- Helper functions and type guards in src/utils (e.g., helpers.ts, markdownCleaner.ts) that provide support across various parts of the system.
- External API Integrations:

##### Relationships and Interactions
- The UI components trigger quiz generation (via button interactions or command palette triggers).
- The UI layer calls into the generator modules (using a factory pattern from generatorFactory.ts) to create the quiz data.
- Generator modules use settings (built out from the src/settings directory) to determine how to interact with the specific provider’s API.
- Once a request is processed, the generators return question data that flows back to the UI for rendering and may also be handled by the quizSaver service to persist the quizzes locally in Markdown format.
- Helper utilities and type-check functions support these modules by ensuring data integrity and proper formatting.

##### Architectural Patterns and Design Principles
- Modular Design: Each provider’s generator is implemented in its own subdirectory, allowing easy extension for new providers.
- Factory Pattern: The generatorFactory.ts centralizes the creation logic for different quiz generators.
- Separation of Concerns: Clear division between UI, business logic (generators), settings/configuration, and persistence (services).
- External Service Integration: Well-defined interfaces between the internal application and external provider APIs.
- Configurability: The settings module ensures that end-users can adjust the behavior of the plugin without changing core logic.

##### Final Detailing
- That every major file or directory in the file tree that plays a role in the architecture is conceptually represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI Layer"
        UI_Components["UI Components"]:::ui
        UI_Quiz["Quiz Components"]:::ui
        UI_Selectors["Selector Components"]:::ui
    end

    subgraph "Business Logic"
        subgraph "Generator Modules"
            GF["Generator Factory"]:::logic
            OpenAI["OpenAI Generator"]:::logic
            Google["Google Generator"]:::logic
            Anthropic["Anthropic Generator"]:::logic
            Cohere["Cohere Generator"]:::logic
            Mistral["Mistral Generator"]:::logic
            Ollama["Ollama Generator"]:::logic
            Perplexity["Perplexity Generator"]:::logic
        end
        subgraph "Settings & Configurations"
            General["General Settings"]:::settings
            Generation["Generation Settings"]:::settings
            Model["Model Settings"]:::settings
            Saving["Saving Settings"]:::settings
            MainConfig["Main Config"]:::settings
        end
        subgraph "Services"
            Reviewer["Quiz Reviewer Service"]:::services
            Saver["Quiz Saver Service"]:::services
        end
        subgraph "Utilities"
            Utilities["Helper Utilities"]:::utilities
        end
    end

    subgraph "External API Integrations"
        External["External AI Providers"]:::external
    end

    %% UI triggers quiz generation
    UI_Components -->|"triggers_generation"| GF
    UI_Quiz -->|"triggers_generation"| GF
    UI_Selectors -->|"triggers_generation"| GF

    %% Generator Factory creates provider-specific generators
    GF -->|"creates"| OpenAI
    GF -->|"creates"| Google
    GF -->|"creates"| Anthropic
    GF -->|"creates"| Cohere
    GF -->|"creates"| Mistral
    GF -->|"creates"| Ollama
    GF -->|"creates"| Perplexity

    %% Generator modules depend on settings
    GF -->|"uses_settings"| General
    GF -->|"uses_settings"| Generation
    GF -->|"uses_settings"| Model
    GF -->|"uses_settings"| Saving
    GF -->|"uses_settings"| MainConfig

    %% Generator modules are supported by utilities
    GF -->|"supports"| Utilities

    %% Each provider calls external APIs
    OpenAI -->|"api_call"| External
    Google -->|"api_call"| External
    Anthropic -->|"api_call"| External
    Cohere -->|"api_call"| External
    Mistral -->|"api_call"| External
    Ollama -->|"api_call"| External
    Perplexity -->|"api_call"| External

    %% External API responses flow back to generator
    External -->|"api_response"| GF

    %% Generator returns quiz data to UI and routes for saving and review
    GF -->|"returns_quiz"| UI_Quiz
    GF -->|"saves_quiz"| Saver
    GF -->|"reviews_quiz"| Reviewer

    %% Review service updates the UI
    Reviewer -->|"update_UI"| UI_Components

    %% Click Events
    click UI_Components "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/ui/components"
    click UI_Quiz "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/ui/quiz"
    click UI_Selectors "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/ui/selector"
    click GF "https://github.com/ecuidev/obsidian-quiz-generator/blob/master/src/generators/generatorFactory.ts"
    click OpenAI "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/openai"
    click Google "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/google"
    click Anthropic "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/anthropic"
    click Cohere "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/cohere"
    click Mistral "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/mistral"
    click Ollama "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/ollama"
    click Perplexity "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/generators/perplexity"
    click General "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/settings/general"
    click Generation "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/settings/generation"
    click Model "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/settings/model"
    click Saving "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/settings/saving"
    click MainConfig "https://github.com/ecuidev/obsidian-quiz-generator/blob/master/src/settings/config.ts"
    click Reviewer "https://github.com/ecuidev/obsidian-quiz-generator/blob/master/src/services/quizReviewer.ts"
    click Saver "https://github.com/ecuidev/obsidian-quiz-generator/blob/master/src/services/quizSaver.ts"
    click Utilities "https://github.com/ecuidev/obsidian-quiz-generator/tree/master/src/utils"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef logic fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef settings fill:#D5F5E3,stroke:#239B56,stroke-width:2px;
    classDef services fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef utilities fill:#FDEBD0,stroke:#CA6F1E,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
