# doomemacs/doomemacs architecture

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

- Interactive diagram: https://gitdiagram.com/doomemacs/doomemacs
- Repository: https://github.com/doomemacs/doomemacs

## Overview

##### Main Components Identification
The system should be divided into these primary components:

a. Core System
- CLI Interface (bin/doom)
- Core Libraries (lisp/doom-*.el)
- Package Management System (based on straight.el)
- Module System

b. Module Categories
- UI Layer
- Editor Features
- Tools & Integration
- Language Support
- Operating System Integration

##### Architectural Patterns

a. Modular Architecture
- Module system's hierarchical structure
- Relationship between core and optional modules
- Demonstrate the plugin architecture

b. Package Management Flow
- Package declaration
- Installation process
- Dependency resolution
- Cache management

##### Component Relationships

**[User Configuration]**
- ↓
**[Doom Core System] → [Package Manager]**
- ↓                    ↓
**[Module System] ←→ [Package Repository]**
- ↓
**[Feature Categories]**
- UI
- Editor
- Tools
- Languages
- OS Integration

##### Specific Implementation Details

Crucial elements:

a. Core Components:
- doom-cli.el (Command interface)
- doom-lib.el (Core utilities)
- doom-packages.el (Package management)
- doom-ui.el (UI management)

b. Module Structure:
- config.el (Module configuration)
- packages.el (Package declarations)
- autoload.el (Lazy loading)
- doctor.el (Diagnostics)

##### Key Workflows to Highlight

Important processes:

a. Startup Sequence:
**early-init.el → init.el → doom initialization → module loading → user config**

b. Package Management:
**package declaration → dependency resolution → installation → configuration**

c. Module Loading:
**module discovery → dependency check → lazy loading → feature activation**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Legend"
        direction TB
        style1[Core Component]:::core
        style2[Module Category]:::module
        style3[External Integration]:::external
        style4[Critical System]:::critical
        style5[Configuration]:::config
    end

    subgraph "Core System"
        direction TB
        CLI["CLI Interface"]:::core
        click CLI "https://github.com/doomemacs/doomemacs/tree/master/bin/doom"
        CoreLib["Core Libraries"]:::core
        click CoreLib "https://github.com/doomemacs/doomemacs/blob/master/lisp/doom.el"
        PackageManager["Package Management"]:::core
        click PackageManager "https://github.com/doomemacs/doomemacs/blob/master/lisp/doom-packages.el"
        KeybindSystem["Keybinding System"]:::core
        click KeybindSystem "https://github.com/doomemacs/doomemacs/blob/master/lisp/doom-keybinds.el"
        ProjectMgmt["Project Management"]:::core
        click ProjectMgmt "https://github.com/doomemacs/doomemacs/blob/master/lisp/doom-projects.el"
    end

    subgraph "Startup Sequence"
        direction TB
        EarlyInit["early-init.el"]:::critical
        click EarlyInit "https://github.com/doomemacs/doomemacs/blob/master/early-init.el"
        Init["init.el"]:::critical
        click Init "https://github.com/doomemacs/doomemacs/blob/master/lisp/init.el"
        DoomStart["doom-start.el"]:::critical
        click DoomStart "https://github.com/doomemacs/doomemacs/blob/master/lisp/doom-start.el"
    end

    subgraph "CLI Tools"
        direction TB
        Install["Install"]:::core
        click Install "https://github.com/doomemacs/doomemacs/blob/master/lisp/cli/install.el"
        Doctor["Doctor"]:::core
        click Doctor "https://github.com/doomemacs/doomemacs/blob/master/lisp/cli/doctor.el"
        Sync["Sync"]:::core
        click Sync "https://github.com/doomemacs/doomemacs/blob/master/lisp/cli/sync.el"
        Upgrade["Upgrade"]:::core
        click Upgrade "https://github.com/doomemacs/doomemacs/blob/master/lisp/cli/upgrade.el"
    end

    subgraph "Module System"
        direction TB
        ModuleLib["Module Library"]:::core
        click ModuleLib "https://github.com/doomemacs/doomemacs/blob/master/lisp/lib/modules.el"
        
        subgraph "Categories"
            direction TB
            UI["UI Modules"]:::module
            click UI "https://github.com/doomemacs/doomemacs/tree/master/modules/ui/"
            Editor["Editor Modules"]:::module
            click Editor "https://github.com/doomemacs/doomemacs/tree/master/modules/editor/"
            Tools["Tools Modules"]:::module
            click Tools "https://github.com/doomemacs/doomemacs/tree/master/modules/tools/"
            Lang["Language Modules"]:::module
            click Lang "https://github.com/doomemacs/doomemacs/tree/master/modules/lang/"
            OS["OS Integration"]:::module
            click OS "https://github.com/doomemacs/doomemacs/tree/master/modules/os/"
        end
    end

    subgraph "Configuration Templates"
        direction TB
        ConfigExample["Config Example"]:::config
        click ConfigExample "https://github.com/doomemacs/doomemacs/blob/master/static/config.example.el"
        InitExample["Init Example"]:::config
        click InitExample "https://github.com/doomemacs/doomemacs/blob/master/static/init.example.el"
        PackagesExample["Packages Example"]:::config
        click PackagesExample "https://github.com/doomemacs/doomemacs/blob/master/static/packages.example.el"
    end

    %% Core System Relationships
    CLI --> CoreLib
    CLI --> PackageManager
    CoreLib --> ModuleLib
    PackageManager --> ModuleLib

    %% Startup Sequence
    EarlyInit --> Init
    Init --> DoomStart
    DoomStart --> ModuleLib

    %% CLI Tools Relationships
    CLI --> Install
    CLI --> Doctor
    CLI --> Sync
    CLI --> Upgrade

    %% Module System Relationships
    ModuleLib --> UI
    ModuleLib --> Editor
    ModuleLib --> Tools
    ModuleLib --> Lang
    ModuleLib --> OS

    %% Configuration Relationships
    ConfigExample -.-> ModuleLib
    InitExample -.-> ModuleLib
    PackagesExample -.-> PackageManager

    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef module fill:#4CAF50,stroke:#388E3C,color:white
    classDef external fill:#FFC107,stroke:#FFA000,color:black
    classDef critical fill:#F44336,stroke:#D32F2F,color:white
    classDef config fill:#9C27B0,stroke:#7B1FA2,color:white
```
