# 1m-n00b/atcoder-to-obsidian architecture

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

- Interactive diagram: https://gitdiagram.com/1m-n00b/atcoder-to-obsidian
- Repository: https://github.com/1m-n00b/atcoder-to-obsidian

## Overview

##### Project Type and Purpose
- This project is a browser extension for both Firefox and Chrome.
- Its purpose is to enable users to save AtCoder problem pages and related memo contents directly into an Obsidian vault. It does so by interfacing with the Obsidian Local REST API.
- The extension features a popup UI for user interaction, background scripts to manage extension-wide behavior, and content scripts to interact with the problem pages.

##### File Structure
- Key Directories:
- entrypoints/background: Contains the background script (index.ts) which likely handles events, messaging, or long-running tasks required by the extension.
- entrypoints/content: Contains the content script (index.ts) which interacts with the AtCoder problem pages.
- entrypoints/popup: Contains the React-based popup front-end (App.tsx, main.tsx, and index.html) that users interact with. This is the UI for entering settings (like Local REST API key and save path) and triggering actions (e.g., “Obsidianに保存”).
- components directory: Contains reusable UI components such as the SettingsModal.
- utils directory: Provides utility functions for markdown conversion, parsing, storage management, and custom types used by the project.
- Configuration and build files: package.json, tsconfig.json, tailwind.config.ts, and postcss.config.cjs are included to manage dependencies, TypeScript settings, and styling (Tailwind CSS). The presence of wxt.config.ts hints at some extension-specific configuration.
- The overall file structure suggests a modular, multi-entry point architecture typical of browser extension development.

##### README for Additional Insights
- The README clearly explains how to set up and use the extension across Firefox and Chrome.
- It details the user workflow: configuring the local REST API key and target vault path, and then using the popup to send data from AtCoder pages to Obsidian.
- The emphasis on the configuration and toggle settings indicates the critical role of both UI interactions (via popup) and background/configuration logic.

a. Main Components to Include:
- Browser Extension Shell: A high-level container representing the extension running in the browser.
- Background Script: Manages the extension’s lifecycle, messaging, and event handling.
- Popup UI: The front-end interface (built with React) that lets users input configurations (e.g., API key, vault path) and trigger actions.
- Content Script: Injected into AtCoder problem pages to capture or interact with page-specific elements.
- Utility Modules: Modules for markdown conversion, parsing, storage, and type definitions.
- External Service: Obsidian Local REST API that receives the saved data from the extension.
b. Relationships and Interactions:
- The Popup UI sends user commands and configuration settings to the Background Script.
- The Background Script communicates with the Content Script as needed (for example, to extract problem details from AtCoder pages).
- Utility modules are called throughout the extension by various components to handle data formatting, parsing the AtCoder content, and managing local storage of user configurations.
- Data flow from the extension (via popup or background) to the external Obsidian Local REST API is a critical path.
c. Architectural Patterns and Design Principles:
- Modular separation of concerns: Clearly dividing UI (popup), background processing (background scripts), and content interaction (content scripts).
- Separation between presentation (React components, e.g., in components/ and entrypoints/popup) and business logic (utility functions in utils/).
- Asynchronous communication: Likely implemented via message passing between content scripts, popup, and background scripts.
d. Technologies, Frameworks, and Libraries:
- React: For building the popup UI (evidence from *.tsx files).
- Tailwind CSS: For styling (inferred from tailwind.config.ts and postcss.config.cjs).
- TypeScript: Based on typescript configuration (tsconfig.json).
- Browser extension APIs: Specific to Firefox/Chrome, used in background and content scripts.
- Obsidian Local REST API: External dependency the extension communicates with.

## Diagram (Mermaid)

```mermaid
graph TD
    BE["Browser Extension Shell"]:::container
    PUI["Popup UI"]:::popup
    BS["Background Script"]:::background
    CS["Content Script"]:::content

    BE -->|"contains"| PUI
    BE -->|"contains"| BS
    BE -->|"contains"| CS

    subgraph "Popup UI Components"
        App["Popup UI: App Component"]:::popup
        Main["Popup UI: Main Script"]:::popup
        HTML["Popup UI: Index Page"]:::popup
    end

    PUI -->|"composedOf"| App
    PUI -->|"composedOf"| Main
    PUI -->|"composedOf"| HTML

    %% Communication Flow
    PUI -->|"sendsConfig"| BS
    BS -->|"communicatesWith"| CS
    BS -->|"calls"| ES["Obsidian Local REST API"]:::external
    PUI -->|"calls"| ES

    %% Usage of Reusable UI Component
    PUI -->|"uses"| RUI["SettingsModal"]:::component
    BS -->|"uses"| RUI

    %% Utility Modules usage from Popup UI
    PUI -->|"calls"| MD["Markdown Converter"]:::utility
    PUI -->|"calls"| PAR["Parser"]:::utility
    PUI -->|"calls"| STOR["Storage Manager"]:::utility
    PUI -->|"calls"| TYPES["Type Definitions"]:::utility

    %% Utility Modules usage from Background Script
    BS -->|"calls"| MD
    BS -->|"calls"| PAR
    BS -->|"calls"| STOR
    BS -->|"calls"| TYPES

    %% Click Events
    click BE "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/."
    click BS "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/entrypoints/background/index.ts"
    click CS "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/entrypoints/content/index.ts"
    click App "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/entrypoints/popup/App.tsx"
    click Main "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/entrypoints/popup/main.tsx"
    click HTML "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/entrypoints/popup/index.html"
    click RUI "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/components/SettingsModal.tsx"
    click MD "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/utils/mdConverter.ts"
    click PAR "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/utils/parser.ts"
    click STOR "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/utils/storage.ts"
    click TYPES "https://github.com/1m-n00b/atcoder-to-obsidian/blob/develop/utils/types.ts"

    %% Styles
    classDef container fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef popup fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef background fill:#ffcdd2,stroke:#b71c1c,stroke-width:2px;
    classDef content fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
    classDef utility fill:#ffecb3,stroke:#f57f17,stroke-width:2px;
    classDef component fill:#d7ccc8,stroke:#3e2723,stroke-width:2px;
    classDef external fill:#f0f4c3,stroke:#827717,stroke-width:2px;
```
