# ernieatlyd/retrospect-ai architecture

> Architecture diagram of the GitHub repository ernieatlyd/retrospect-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ernieatlyd/retrospect-ai
- Repository: https://github.com/ernieatlyd/retrospect-ai

## Overview

##### Project Type and Purpose
- This is an Obsidian plugin focused on processing users’ journal entries and weekly reviews using AI analysis.
- It integrates multiple AI provider modules (such as OpenAI, Anthropic Claude, and self-hosted models like Ollama) and offers privacy controls plus customizable analysis outputs.
- The plugin is triggered from within Obsidian (via ribbon commands/command palette), analyzes note content, and outputs structured insights.

##### Key Components Based on the File Structure
a. Core Plugin Functionality:
- In the src/core folder you have key managers:
- CommandManager.ts – handles user commands.
- ServiceManager.ts – orchestrates the different service modules.
- UIManager.ts – controls the UI components within Obsidian.
b. Service Integration Modules:
- Located in the src/services folder, these files implement integration with various AI providers and support services:
- AIService.ts: Likely handles generic AI service interactions.
- OpenAIService.ts: Manages integration with OpenAI’s API.
- AnthropicService.ts: Handles connections with Anthropic’s AI (Claude models).
- OllamaService.ts: Supports self-hosted AI models.
- Additional modules for caching (CacheManager), logging (LoggingService), streaming (StreamingManager), weekly analysis (WeeklyAnalysisService), etc.
c. Prompts and Settings:
- The src/prompts directory contains the prompt templates for daily and weekly analysis.
- The src/settings directory provides the settings UI and tests for configuring AI provider API keys and analysis preferences.
d. Utilities and Configurations:
- The src/utils folder holds helper functions (e.g., debounce, retry logic, error handling).
- Configuration files such as tsconfig.json, eslint.config.js, and the build scripts like esbuild.config.mjs indicate a modern JavaScript/TypeScript setup.

##### Relationships and Interactions
- User Interaction: A user interacts with Obsidian’s UI, triggering the plugin (e.g., clicking the AI Reflection button or invoking commands via the command palette).
- CommandManager then passes the action to ServiceManager.
- The ServiceManager orchestrates different processes:
- It calls the corresponding prompt generator (from the src/prompts modules).
- It invokes the appropriate AI Service Integration module based on the configuration – selected from OpenAI, Anthropic, or Ollama.
- These AI services communicate with external APIs or local servers.
- UIManager then takes the processed results and renders the insights (daily reflections or weekly analysis) on the Obsidian interface.

##### Architectural Patterns or Design Principles
- Modularity: Clear separation between core management (core folder) and service-specific integrations (services folder).
- Extensibility: The Providers.ts file and the distinct service modules show an architecture designed to allow plug-and-play support for additional AI providers.
- Testability: The presence of __mocks__ directories and test files (e.g., main.test.ts, service tests) indicate an emphasis on unit testing.
- Clean separation of concerns between UI handling, command processing, service integrations, and utility functions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Environment
    OBI["Obsidian Environment"]:::external

    %% Core Plugin Components
    subgraph "Core Plugin"
        CM["CommandManager"]:::core
        SM["ServiceManager"]:::core
        UM["UIManager"]:::core
    end

    %% Prompts and Configuration
    subgraph "Prompts & Configuration"
        DRP["Daily Reflection Prompt"]:::prompt
        WRP["Weekly Reflection Prompt"]:::prompt
        SET["Settings"]:::settings
    end

    %% AI Integration Modules - Top Row
    subgraph "AI Integration (Primary)"
        AIS["AIService"]:::service
        OAIS["OpenAIService"]:::service
        ATS["AnthropicService"]:::service
    end

    %% AI Integration Modules - Bottom Row
    subgraph "AI Integration (Secondary)"
        OS["OllamaService"]:::service
        CMgr["CacheManager"]:::service
        LS["LoggingService"]:::service
        PS["PrivacyManager"]:::service
        SS["StreamingManager"]:::service
        WAS["WeeklyAnalysisService"]:::service
    end

    %% Utility Functions
    subgraph "Utilities"
        DU["Debounce Utility"]:::util
        EH["Error Handling Utility"]:::util
        FE["FetchWithError Utility"]:::util
        RL["Retry Utility"]:::util
    end

    %% Relationships and Data Flow
    OBI -->|"triggers"| CM
    CM -->|"forwards command"| SM

    %% ServiceManager interacts with Prompts for generating analysis
    SM -->|"generates"| DRP
    SM -->|"generates"| WRP
    DRP -->|"outputs insights to"| UM
    WRP -->|"outputs insights to"| UM

    %% ServiceManager calls AI Integration Modules (Primary Row)
    SM -->|"calls"| AIS
    SM -->|"calls"| OAIS
    SM -->|"calls"| ATS

    %% ServiceManager calls AI Integration Modules (Secondary Row)
    SM -->|"calls"| OS
    SM -->|"calls"| CMgr
    SM -->|"calls"| LS
    SM -->|"calls"| PS
    SM -->|"calls"| SS
    SM -->|"calls"| WAS

    %% AI Modules return results to UIManager
    AIS -->|"results"| UM
    OAIS -->|"results"| UM
    ATS -->|"results"| UM
    OS -->|"results"| UM
    CMgr -->|"results"| UM
    LS -->|"results"| UM
    PS -->|"results"| UM
    SS -->|"results"| UM
    WAS -->|"results"| UM

    %% Click Events for Core Plugin Components
    click CM "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/core/CommandManager.ts"
    click SM "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/core/ServiceManager.ts"
    click UM "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/core/UIManager.ts"

    %% Click Events for AI Service Integration Modules (Primary)
    click AIS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/AIService.ts"
    click OAIS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/OpenAIService.ts"
    click ATS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/AnthropicService.ts"

    %% Click Events for AI Service Integration Modules (Secondary)
    click OS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/OllamaService.ts"
    click CMgr "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/CacheManager.ts"
    click LS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/LoggingService.ts"
    click PS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/PrivacyManager.ts"
    click SS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/StreamingManager.ts"
    click WAS "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/services/WeeklyAnalysisService.ts"

    %% Click Events for Prompts and Configuration
    click DRP "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/prompts/reflectionPrompt.ts"
    click WRP "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/prompts/weeklyReflectionPrompt.ts"
    click SET "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/settings/settingsTab.ts"

    %% Click Events for Utility Functions
    click DU "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/utils/debounce.ts"
    click EH "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/utils/error.ts"
    click FE "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/utils/fetchWithError.ts"
    click RL "https://github.com/ernieatlyd/retrospect-ai/blob/master/src/utils/retry.ts"

    %% Styling Classes
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:2px;
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef service fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef prompt fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef settings fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef util fill:#f8d7da,stroke:#721c24,stroke-width:2px;
```
