# obsidianmd/obsidian-api architecture

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

- Interactive diagram: https://gitdiagram.com/obsidianmd/obsidian-api
- Repository: https://github.com/obsidianmd/obsidian-api

## Overview

##### Main Components
- API Type Definitions: The core of the project is found in files like obsidian.d.ts, canvas.d.ts, and publish.d.ts. These files define interfaces and types, e.g., for the global App object and its subcomponents (Vault, Workspace, MetadataCache).
- Plugin Structure & Extension Points: The README explains how plugins are built – via manifest.json, main.js, and various registration methods (commands, events, DOM events, etc.). Even though these files aren’t in the file tree, the README’s “Plugin structure” section and “App Architecture” description are key.

##### Representing Relationships and Interactions
- Inside, detail the main modules (Vault, Workspace, MetadataCache).
- That plugins use the provided type definitions for interfacing with the App.
- That plugin developers define a manifest.json and main.js that leverage functions like this.addRibbonIcon, this.addCommand, etc.
- Detail event registrations (using methods like this.registerEvent, this.registerDomEvent, this.registerInterval) which link back to components of the app module.
- Optionally, include an “External Documentation/Developer Resources” block (from links mentioned in the README) to indicate how external resources and community forums fit into the ecosystem.

##### Highlighting Architectural Patterns
- Abstraction layers (interfaces provided via type definitions vs. runtime implementations in the Obsidian app).
- The plugin lifecycle (installation, activation, event registration, and unloading) which relies on a clear contract defined by the API.

##### Including Key Technologies and Languages
- JavaScript/TypeScript source: since the project includes .d.ts (TypeScript Definition) files.
- Mention bundling tools (like Rollup or Webpack) as referenced in the README for building main.js.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Type Definitions Subgraph
    subgraph "API Type Definitions"
        A["Obsidian API"]:::api
        V["Vault Interface"]:::api
        W["Workspace Interface"]:::api
        M["MetadataCache Interface"]:::api
        C["Canvas API"]:::api
        P["Publish API"]:::api
    end

    A -->|"includes"| V
    A -->|"includes"| W
    A -->|"includes"| M

    %% Plugin Integration Subgraph
    subgraph "Plugin Integration"
        PM["Plugin Manifest (manifest.json)"]:::plugin
        PC["Plugin Code (main.js)"]:::plugin
        PE["Extension Points (Ribbon,Commands,Events)"]:::plugin
    end

    PC -->|"calls"| A
    PC -->|"uses"| PE
    PE -->|"registers_to"| A

    %% External Documentation/Developer Resources
    subgraph "External Resources"
        EX["Documentation/Developer Community"]:::external
    end

    PC -->|"references"| EX

    %% Click Events for API Type Definitions
    click A "https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts"
    click C "https://github.com/obsidianmd/obsidian-api/blob/master/canvas.d.ts"
    click P "https://github.com/obsidianmd/obsidian-api/blob/master/publish.d.ts"

    %% Styles
    classDef api fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef plugin fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef external fill:#CCE5FF,stroke:#333,stroke-width:2px;
```
