Chapter 1: Obsidian Plugin Architecture

April 13, 2026 ยท View on GitHub

Welcome to Chapter 1: Obsidian Plugin Architecture. In this part of Obsidian Outliner Plugin: Deep Dive Tutorial, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.

Understanding Obsidian's plugin system and API boundaries

๐ŸŽฏ Learning Objectives

By the end of this chapter, you'll understand:

  • Obsidian's plugin architecture and lifecycle
  • The plugin API and safe interaction patterns
  • Plugin manifest and configuration
  • Development environment setup

๐Ÿ—๏ธ Obsidian Plugin System Overview

Obsidian plugins extend the core functionality through a well-defined API that maintains security and stability. The plugin system is designed to be:

  • Secure: Plugins run in sandboxed environments with controlled access
  • Extensible: Clean APIs for adding features without modifying core code
  • Compatible: Version-aware APIs that maintain backward compatibility
  • Discoverable: Centralized plugin marketplace with quality controls

Plugin Types

TypeDescriptionUse Case
Editor PluginExtends editing capabilitiesCustom editors, syntax highlighting
View PluginAdds new view typesCalendar, kanban boards, mind maps
Command PluginAdds commands to command paletteFile operations, transformations
Settings PluginAdds settings UIConfiguration management
Theme PluginModifies appearanceCustom styling, layouts

๐Ÿ“‹ Plugin Manifest

Every Obsidian plugin requires a manifest.json file that defines its identity and capabilities:

{
  "id": "obsidian-outliner",
  "name": "Outliner",
  "version": "4.8.0",
  "minAppVersion": "1.0.0",
  "description": "Work with your lists like in Workflowy or Roam Research.",
  "author": "Viacheslav Slinko",
  "authorUrl": "https://github.com/vslinko",
  "isDesktopOnly": false,
  "fundingUrl": "https://github.com/sponsors/vslinko"
}

Manifest Fields

FieldRequiredDescription
idโœ…Unique plugin identifier (lowercase, hyphens)
nameโœ…Human-readable plugin name
versionโœ…Semantic version string
minAppVersionโœ…Minimum Obsidian version required
descriptionโœ…Plugin description for marketplace
authorโœ…Plugin author name
authorUrlโŒLink to author website/GitHub
isDesktopOnlyโŒWhether plugin requires desktop features
fundingUrlโŒLink for donations/sponsorship

๐Ÿ”ง Plugin Class Structure

All Obsidian plugins extend the base Plugin class:

import { Plugin, PluginManifest } from 'obsidian';

export default class OutlinerPlugin extends Plugin {
  // Plugin manifest passed to constructor
  constructor(app: App, manifest: PluginManifest) {
    super(app, manifest);
  }

  // Called when plugin is enabled
  async onload() {
    // Plugin initialization code
    console.log('Outliner plugin loaded');

    // Register commands, views, etc.
    this.registerCommands();
    this.registerViews();
    this.registerEvents();
  }

  // Called when plugin is disabled
  async onunload() {
    // Cleanup code
    console.log('Outliner plugin unloaded');

    // Clean up resources
    this.cleanup();
  }

  private registerCommands() {
    // Command registration
  }

  private registerViews() {
    // View registration
  }

  private registerEvents() {
    // Event listener registration
  }

  private cleanup() {
    // Resource cleanup
  }
}

Plugin Lifecycle

stateDiagram-v2
    [*] --> PluginDisabled
    PluginDisabled --> Loading: User enables plugin
    Loading --> onload(): Plugin code loads
    onload() --> Active: Initialization complete
    Active --> onunload(): User disables plugin
    onunload() --> PluginDisabled: Cleanup complete
    Active --> Error: Runtime error
    Error --> onunload(): Error recovery
    Error --> [*]: Fatal error

๐Ÿ”Œ Core API Components

App Interface

The main entry point for accessing Obsidian functionality:

interface App {
  // Vault management
  vault: Vault;

  // Workspace management
  workspace: Workspace;

  // Metadata management
  metadataCache: MetadataCache;

  // File manager
  fileManager: FileManager;

  // Plugin system
  plugins: PluginSystem;

  // Commands
  commands: Commands;

  // Settings
  setting: Setting;
}

Vault API

Manages files and folders in the vault:

interface Vault {
  // File operations
  create(path: string, data: string): Promise<TFile>;
  read(file: TFile): Promise<string>;
  modify(file: TFile, data: string): Promise<void>;
  delete(file: TFile, force?: boolean): Promise<void>;

  // Folder operations
  createFolder(path: string): Promise<TFolder>;
  delete(folder: TFolder, force?: boolean): Promise<void>;

  // Utility methods
  getAbstractFileByPath(path: string): TAbstractFile | null;
  getAllLoadedFiles(): TFile[];
  getMarkdownFiles(): TFile[];

  // Events
  on(name: 'create', callback: (file: TAbstractFile) => any): EventRef;
  on(name: 'delete', callback: (file: TAbstractFile) => any): EventRef;
  on(name: 'modify', callback: (file: TFile) => any): EventRef;
  on(name: 'rename', callback: (file: TAbstractFile, oldPath: string) => any): EventRef;
}

Workspace API

Manages the user interface and views:

interface Workspace {
  // Active file/view
  getActiveFile(): TFile | null;
  getActiveViewOfType<T extends View>(type: Constructor<T>): T | null;

  // View management
  getLeavesOfType(viewType: string): WorkspaceLeaf[];
  createLeafInTabGroup(): WorkspaceLeaf;
  createLeafBySplit(leaf: WorkspaceLeaf, direction: 'vertical' | 'horizontal'): WorkspaceLeaf;

  // Layout management
  changeLayout(workspace: any): Promise<void>;
  saveLayout(): Promise<void>;

  // Events
  on(name: 'active-leaf-change', callback: (leaf: WorkspaceLeaf | null) => any): EventRef;
  on(name: 'file-open', callback: (file: TFile) => any): EventRef;
  on(name: 'layout-change', callback: () => any): EventRef;
}

๐Ÿ› ๏ธ Development Environment Setup

Project Structure

obsidian-outliner-tutorial/
โ”œโ”€โ”€ manifest.json          # Plugin manifest
โ”œโ”€โ”€ package.json           # Node.js dependencies
โ”œโ”€โ”€ tsconfig.json          # TypeScript configuration
โ”œโ”€โ”€ main.ts               # Main plugin file
โ”œโ”€โ”€ src/                  # Source code
โ”‚   โ”œโ”€โ”€ plugin.ts         # Plugin class
โ”‚   โ”œโ”€โ”€ commands.ts       # Command implementations
โ”‚   โ”œโ”€โ”€ views.ts          # Custom view components
โ”‚   โ””โ”€โ”€ utils.ts          # Utility functions
โ”œโ”€โ”€ styles.css            # Plugin styles
โ””โ”€โ”€ dist/                 # Built plugin (generated)
    โ”œโ”€โ”€ main.js
    โ””โ”€โ”€ manifest.json

Package.json Configuration

{
  "name": "obsidian-outliner",
  "version": "4.8.0",
  "description": "Work with your lists like in Workflowy or Roam Research",
  "main": "main.ts",
  "scripts": {
    "dev": "node esbuild.config.mjs",
    "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
    "version": "node version-bump.mjs && git add manifest.json package.json"
  },
  "keywords": ["obsidian", "plugin", "outliner"],
  "author": "Viacheslav Slinko",
  "license": "MIT",
  "devDependencies": {
    "@types/node": "^16.11.6",
    "@typescript-eslint/eslint-plugin": "5.29.0",
    "@typescript-eslint/parser": "5.29.0",
    "builtin-modules": "3.3.0",
    "esbuild": "0.17.3",
    "obsidian": "latest",
    "tslib": "2.4.0",
    "typescript": "4.7.4"
  }
}

TypeScript Configuration

{
  "compilerOptions": {
    "baseUrl": ".",
    "inlineSourceMap": true,
    "inlineSources": true,
    "module": "ESNext",
    "target": "ES6",
    "allowJs": true,
    "noImplicitAny": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "strictNullChecks": false,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "strictFunctionTypes": false,
    "strictPropertyInitialization": false,
    "lib": [
      "DOM",
      "ES5",
      "ES6",
      "ES7"
    ]
  },
  "include": [
    "**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Build Configuration

// esbuild.config.mjs
import esbuild from "esbuild";
import process from "process";

const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === 'production');

esbuild.build({
  banner: {
    js: banner,
  },
  entryPoints: ['main.ts'],
  bundle: true,
  external: [
    'obsidian',
    'electron',
    '@codemirror/view',
    '@codemirror/state',
    '@codemirror/lang-markdown'
  ],
  format: 'cjs',
  target: 'es2018',
  logLevel: "info",
  sourcemap: prod ? false : 'inline',
  treeShaking: true,
  outfile: 'dist/main.js',
}).catch(() => process.exit(1));

๐Ÿ”’ API Boundaries and Best Practices

Safe Plugin Development

// โœ… Good: Using official APIs
export default class SafePlugin extends Plugin {
  async onload() {
    // Safe: Using documented API
    this.registerEvent(
      this.app.vault.on('modify', (file) => {
        console.log(`${file.name} was modified`);
      })
    );

    // Safe: Using command API
    this.addCommand({
      id: 'my-command',
      name: 'My Command',
      callback: () => {
        // Command implementation
      }
    });
  }
}

// โŒ Bad: Accessing private APIs
export default class UnsafePlugin extends Plugin {
  async onload() {
    // Unsafe: Accessing private properties
    const privateProperty = (this.app as any)._privateProperty;

    // Unsafe: Modifying DOM directly
    document.querySelector('.some-internal-class').style.display = 'none';
  }
}

Plugin Security Guidelines

  1. API Compliance: Only use documented APIs and methods
  2. Resource Management: Clean up event listeners and resources on unload
  3. Error Handling: Implement proper error handling and recovery
  4. Performance: Avoid blocking operations and memory leaks
  5. Compatibility: Test across different Obsidian versions

๐Ÿงช Development Workflow

Local Development Setup

  1. Clone sample plugin:

    git clone https://github.com/obsidianmd/obsidian-sample-plugin.git
    cd obsidian-sample-plugin
    npm install
    
  2. Copy plugin to vault:

    # Create plugins folder in your vault
    mkdir -p /path/to/vault/.obsidian/plugins/your-plugin-id/
    
    # Copy built plugin
    cp dist/main.js /path/to/vault/.obsidian/plugins/your-plugin-id/
    cp manifest.json /path/to/vault/.obsidian/plugins/your-plugin-id/
    
  3. Enable plugin in Obsidian:

    • Open Settings โ†’ Community plugins
    • Turn on "Safe mode" off
    • Find your plugin in the list and enable it

Hot Reload Development

// For development with auto-reload
export default class DevPlugin extends Plugin {
  async onload() {
    // Development helpers
    if (process.env.NODE_ENV === 'development') {
      this.registerDomEvent(window, 'keydown', (evt) => {
        if (evt.key === 'F5' && evt.ctrlKey) {
          // Trigger reload
          window.location.reload();
        }
      });
    }

    // Your plugin logic here
  }
}

๐ŸŽฏ Key Takeaways

  1. Plugin Architecture: Clean separation between plugin and core functionality
  2. API Boundaries: Respect documented APIs to ensure compatibility and security
  3. Lifecycle Management: Proper initialization and cleanup of resources
  4. Type Safety: TypeScript provides compile-time safety for plugin development
  5. Development Workflow: Streamlined setup for efficient plugin development

๐Ÿงช Hands-On Exercise

Estimated Time: 30 minutes

  1. Set up development environment:

    • Clone the Obsidian sample plugin
    • Configure TypeScript and build system
    • Create a basic plugin structure
  2. Create a simple plugin:

    • Add a command that shows a notice
    • Register an event listener for file changes
    • Test plugin loading and unloading
  3. Explore the API:

    • Access vault files and metadata
    • Register commands and shortcuts
    • Add settings to the plugin

Ready to build text editing features? Continue to Chapter 2: Text Editing Implementation

What Problem Does This Solve?

Most teams struggle here because the hard part is not writing more code, but deciding clear boundaries for plugin, file, obsidian so behavior stays predictable as complexity grows.

In practical terms, this chapter helps you avoid three common failures:

  • coupling core logic too tightly to one implementation path
  • missing the handoff boundaries between setup, execution, and validation
  • shipping changes without clear rollback or observability strategy

After working through this chapter, you should be able to reason about Chapter 1: Obsidian Plugin Architecture as an operating subsystem inside Obsidian Outliner Plugin: Deep Dive Tutorial, with explicit contracts for inputs, state transitions, and outputs.

Use the implementation notes around Plugin, name, TFile as your checklist when adapting these patterns to your own repository.

How it Works Under the Hood

Under the hood, Chapter 1: Obsidian Plugin Architecture usually follows a repeatable control path:

  1. Context bootstrap: initialize runtime config and prerequisites for plugin.
  2. Input normalization: shape incoming data so file receives stable contracts.
  3. Core execution: run the main logic branch and propagate intermediate state through obsidian.
  4. Policy and safety checks: enforce limits, auth scopes, and failure boundaries.
  5. Output composition: return canonical result payloads for downstream consumers.
  6. Operational telemetry: emit logs/metrics needed for debugging and performance tuning.

When debugging, walk this sequence in order and confirm each stage has explicit success/failure conditions.

Source Walkthrough

Use the following upstream sources to verify implementation details while reading this chapter:

  • Obsidian Outliner Why it matters: authoritative reference on Obsidian Outliner (github.com).

Suggested trace strategy:

  • search upstream code for plugin and file to map concrete implementation paths
  • compare docs claims against actual runtime/config code before reusing patterns in production

Chapter Connections

Depth Expansion Playbook

Source Code Walkthrough

jest/global-setup.js

The wait function in jest/global-setup.js handles a key part of this chapter's functionality:

global.KILL_CMD = KILL_CMD;

function wait(t) {
  return new Promise((resolve) => setTimeout(resolve, t));
}

function runForAWhile({ timeout, fileToCheck }) {
  return new Promise(async (resolve, reject) => {
    const start = Date.now();
    const obsidian = cp.spawn(OBSIDIAN_APP_CMD[0], OBSIDIAN_APP_CMD.slice(1));
    obsidian.on("error", reject);
    const i = setInterval(() => {
      if (fs.existsSync(fileToCheck)) {
        clearInterval(i);
        setTimeout(() => {
          cp.spawnSync(KILL_CMD[0], KILL_CMD.slice(1));
          resolve();
        }, 1000);
        return;
      }
      const diff = Date.now() - start;
      if (diff > timeout) {
        clearInterval(i);
        cp.spawnSync(KILL_CMD[0], KILL_CMD.slice(1));
        reject();
      }
    }, 1000);
  });
}

async function prepareObsidian() {
  debug(`Preparing Obsidian`);

This function is important because it defines how Obsidian Outliner Plugin: Deep Dive Tutorial implements the patterns covered in this chapter.

jest/global-setup.js

The runForAWhile function in jest/global-setup.js handles a key part of this chapter's functionality:

}

function runForAWhile({ timeout, fileToCheck }) {
  return new Promise(async (resolve, reject) => {
    const start = Date.now();
    const obsidian = cp.spawn(OBSIDIAN_APP_CMD[0], OBSIDIAN_APP_CMD.slice(1));
    obsidian.on("error", reject);
    const i = setInterval(() => {
      if (fs.existsSync(fileToCheck)) {
        clearInterval(i);
        setTimeout(() => {
          cp.spawnSync(KILL_CMD[0], KILL_CMD.slice(1));
          resolve();
        }, 1000);
        return;
      }
      const diff = Date.now() - start;
      if (diff > timeout) {
        clearInterval(i);
        cp.spawnSync(KILL_CMD[0], KILL_CMD.slice(1));
        reject();
      }
    }, 1000);
  });
}

async function prepareObsidian() {
  debug(`Preparing Obsidian`);

  if (!fs.existsSync(OBSIDIAN_CONFIG_PATH)) {
    debug(`  Creating ${OBSIDIAN_CONFIG_PATH}`);
    mkdirp.sync(OBSIDIAN_CONFIG_DIR);

This function is important because it defines how Obsidian Outliner Plugin: Deep Dive Tutorial implements the patterns covered in this chapter.

jest/global-setup.js

The prepareObsidian function in jest/global-setup.js handles a key part of this chapter's functionality:

}

async function prepareObsidian() {
  debug(`Preparing Obsidian`);

  if (!fs.existsSync(OBSIDIAN_CONFIG_PATH)) {
    debug(`  Creating ${OBSIDIAN_CONFIG_PATH}`);
    mkdirp.sync(OBSIDIAN_CONFIG_DIR);
    fs.writeFileSync(
      OBSIDIAN_CONFIG_PATH,
      '{"vaults":{},"updateDisabled":true}',
    );

    debug("  Running Obsidian for 90 seconds to setup");
    await runForAWhile({
      timeout: 90000,
      fileToCheck: OBSIDIAN_LOCAL_STORAGE_PATH,
    });
    await wait(2000);
  }

  originalObsidianConfig = fs.readFileSync(OBSIDIAN_CONFIG_PATH, "utf-8");

  const obsidianConfig = JSON.parse(originalObsidianConfig);
  for (const key of Object.keys(obsidianConfig.vaults)) {
    debug(`  Closing vault ${obsidianConfig.vaults[key].path}`);
    obsidianConfig.vaults[key].open = false;
  }
  debug(`  Opening vault ${VAULT_DIR}`);
  obsidianConfig.vaults[OBISDIAN_TEST_VAULT_ID] = {
    path: VAULT_DIR,
    ts: Date.now(),

This function is important because it defines how Obsidian Outliner Plugin: Deep Dive Tutorial implements the patterns covered in this chapter.

jest/global-setup.js

The prepareVault function in jest/global-setup.js handles a key part of this chapter's functionality:

}

async function prepareVault() {
  debug(`Prepare vault`);

  mkdirp.sync(VAULT_DIR);
  fs.writeFileSync(VAULT_DIR + "/test.md", "");

  const vaultConfigFilePath = `${VAULT_DIR}/.obsidian/app.json`;
  const vaultCommunityPluginsConfigFilePath = `${VAULT_DIR}/.obsidian/community-plugins.json`;
  const vaultPluginDir = `${VAULT_DIR}/.obsidian/plugins/obsidian-outliner`;

  if (!fs.existsSync(vaultConfigFilePath)) {
    debug("  Running Obsidian for 90 seconds to setup vault");
    await runForAWhile({ timeout: 90000, fileToCheck: vaultConfigFilePath });
    await wait(2000);
  }

  const vaultConfig = JSON.parse(fs.readFileSync(vaultConfigFilePath));
  const newVaultConfig = {
    ...vaultConfig,
    foldHeading: true,
    foldIndent: true,
    useTab: false,
    tabSize: 2,
    legacyEditor: false,
  };
  if (JSON.stringify(vaultConfig) !== JSON.stringify(newVaultConfig)) {
    debug(`  Saving ${vaultConfigFilePath}`);
    fs.writeFileSync(vaultConfigFilePath, JSON.stringify(newVaultConfig));
  }

This function is important because it defines how Obsidian Outliner Plugin: Deep Dive Tutorial implements the patterns covered in this chapter.

How These Components Connect

flowchart TD
    A[wait]
    B[runForAWhile]
    C[prepareObsidian]
    D[prepareVault]
    E[stateToString]
    A --> B
    B --> C
    C --> D
    D --> E