# vivaswt/notion2anki architecture

> Architecture diagram of the GitHub repository vivaswt/notion2anki, 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/vivaswt/notion2anki
- Repository: https://github.com/vivaswt/notion2anki

## Overview

##### Main Components
- Entry Point (Main) – Represented by src/Main.hs. This module orchestrates the flow of the application.
- Notion Integration Module – Represented by src/NotionFlashCard.hs. It contains logic to interface with the Notion database and extract flashcard properties.
- Anki Integration Module – Represented by src/Anki.hs. It handles the addition of flashcards (with images and audio) to the Anki application.
- Google Text-to-Speech Integration – Represented by src/GoogleAPI.hs. It is used for generating audio from text using the Google TTS API.
- External Systems – Notion API (for fetching flashcard data) and Anki (for flashcard import).

##### Relationships and Interactions
- Main Module acts as the central controller: it retrieves environment variables (PRIVATE_NOTION_TOKEN and GOOGLE_TTS_API_KEY), initiates the data fetching from the Notion Integration Module, optionally invokes GoogleAPI for audio generation, and finally calls the Anki module to post the flashcards.
- Data Flow: NotionFlashCard.hs fetches and structures flashcard entries → Main.hs processes or augments flashcard content (invoking GoogleAPI.hs where needed) → Passes finalized flashcards to Anki.hs for integration.

##### Architectural Patterns and Design Choices
- Modular Separation: The project clearly separates concerns by isolating the logic for each external integration into its own module.
- Configuration via Environment Variables: The use of environment variables to manage API tokens indicates that the application is designed for secure and flexible configuration.

##### Relevant Technologies and Frameworks
- Haskell as the programming language with its build and dependency management handled by Stack (stack.yaml, stack.yaml.lock) and Cabal (notion2anki.cabal).
- External APIs such as Notion’s API and Google Text-to-Speech API.
- Anki (for flashcard management) as the target system.

## Diagram (Mermaid)

```mermaid
graph TD
    main["Main (Controller)"]:::internal
    notion["Notion Flashcard Fetcher"]:::internal
    google["Google Text-to-Speech"]:::internal
    user["User Confirmation"]:::internal
    anki["Anki Flashcard Integrator"]:::internal
    notionAPI["Notion API"]:::external
    googleAPI["Google TTS API"]:::external
    ankiApp["Anki Application"]:::external

    main -->|"fetchesData"| notion
    notion -->|"calls"| notionAPI
    main -->|"requestsAudio"| google
    google -->|"calls"| googleAPI
    main -->|"awaitsConfirmation"| user
    user -->|"confirms"| anki
    anki -->|"insertsCards"| ankiApp

    click main "https://github.com/vivaswt/notion2anki/blob/master/src/Main.hs"
    click notion "https://github.com/vivaswt/notion2anki/blob/master/src/NotionFlashCard.hs"
    click google "https://github.com/vivaswt/notion2anki/blob/master/src/GoogleAPI.hs"
    click anki "https://github.com/vivaswt/notion2anki/blob/master/src/Anki.hs"

    classDef internal fill:#AED6F1,stroke:#1A5276,stroke-width:2px;
    classDef external fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
```
