# rprtr258/pm architecture

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

- Interactive diagram: https://gitdiagram.com/rprtr258/pm
- Repository: https://github.com/rprtr258/pm

## Overview

##### Main Components

a. CLI Client Component:
- Located in `/internal/cli`
- Handles user commands (run, start, stop, delete, etc.)
- Interacts with the server component

b. Shim Component:
- Core process management functionality
- Handles process monitoring, restarts, watches
- Manages signals and shutdowns

c. Storage Components:
- Database system (in `/internal/db`)
- Log rotation system (in `/internal/logrotation`)
- File system watcher (in `/internal/fsnotify`)

d. Configuration Management:
- Jsonnet configuration parser
- Process configuration handling

- User Layer   |

- Process Mgmt  |

- Storage Layer  |

##### Key Relationships

- CLI → Shim communication
- Shim → Managed Processes interaction
- Storage interactions (logs, DB, config)
- File system monitoring

##### Specific Elements

a. User Interface:
- CLI commands interface
- Configuration input (Jsonnet/JSON)

b. Process Management:
- Process lifecycle management
- Auto-restart mechanism
- Watch functionality
- Signal handling

c. Storage:
- Database tables
- Log files management
- Configuration storage

##### Important Architectural Details

- $HOME/.pm directory structure
- Systemd integration point
- Process state transitions
- Linux-specific components

##### Implementation Details to Highlight

- Core process types and configurations
- Error handling paths
- Log rotation mechanisms
- File system watch patterns

##### System integration points

This system design should help developers understand both the high-level architecture and the specific implementation details that make PM an effective process management tool.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef cli fill:#3498db,stroke:#2980b9,color:white
    classDef storage fill:#f1c40f,stroke:#f39c12,color:black
    classDef process fill:#2ecc71,stroke:#27ae60,color:white
    classDef config fill:#e74c3c,stroke:#c0392b,color:white
    classDef error fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef docs fill:#9b59b6,stroke:#8e44ad,color:white
    classDef test fill:#34495e,stroke:#2c3e50,color:white

    subgraph User_Layer
        CLI["CLI Interface"]:::cli
        Commands["Command Operations"]:::cli
    end

    subgraph Process_Management_Layer
        ProcHandler["Linux Process Handler"]:::process
        ProcTypes["Process Types"]:::process
        ProcFilter["Process Filter"]:::process
        StateManager["State Manager"]:::process
    end

    subgraph Storage_Layer
        DB["Database"]:::storage
        LogRotation["Log Rotation"]:::storage
        FSWatcher["FS Watcher"]:::storage
    end

    subgraph Configuration
        ConfigParser["Config Parser"]:::config
        CoreConfig["Core Config"]:::config
        RunConfig["Run Configuration"]:::config
    end

    subgraph Error_Handling
        ErrorSystem["Error Handler"]:::error
    end

    subgraph Documentation
        StateDoc["Process State Docs"]:::docs
        ConfigExamples["Config Examples"]:::docs
    end

    subgraph Testing
        E2ETests["E2E Tests"]:::test
        TestExamples["Test Examples"]:::test
    end

    %% Relationships
    CLI --> Commands
    Commands --> ProcHandler
    ProcHandler --> ProcTypes
    ProcHandler --> ProcFilter
    ProcHandler --> StateManager
    ProcHandler --> DB
    StateManager --> LogRotation
    StateManager --> FSWatcher
    ConfigParser --> CoreConfig
    CoreConfig --> RunConfig
    RunConfig --> ProcHandler
    ProcHandler --> ErrorSystem

    %% Click Events
    click CLI "https://github.com/rprtr258/pm/blob/master/internal/cli/cli.go"
    click Commands "https://github.com/rprtr258/pm/tree/master/internal/cli"
    click ProcHandler "https://github.com/rprtr258/pm/tree/master/internal/linuxprocess"
    click ProcTypes "https://github.com/rprtr258/pm/blob/master/internal/core/proctypes.go"
    click ProcFilter "https://github.com/rprtr258/pm/blob/master/internal/core/filter.go"
    click DB "https://github.com/rprtr258/pm/blob/master/internal/db/db.go"
    click LogRotation "https://github.com/rprtr258/pm/blob/master/internal/logrotation/logrotation.go"
    click FSWatcher "https://github.com/rprtr258/pm/blob/master/internal/fsnotify/watcher.go"
    click ConfigParser "https://github.com/rprtr258/pm/blob/master/internal/config/config.go"
    click CoreConfig "https://github.com/rprtr258/pm/blob/master/internal/core/config.go"
    click RunConfig "https://github.com/rprtr258/pm/blob/master/internal/core/runconfig.go"
    click ErrorSystem "https://github.com/rprtr258/pm/blob/master/internal/errors/errors.go"
    click StateDoc "https://github.com/rprtr258/pm/blob/master/docs/process-state-diagram.jsonnet"
    click ConfigExamples "https://github.com/rprtr258/pm/blob/master/docs/docs.jsonnet"
    click E2ETests "https://github.com/rprtr258/pm/blob/master/e2e/e2e_test.go"
    click TestExamples "https://github.com/rprtr258/pm/tree/master/e2e/tests"
```
