# bayasdev/envycontrol architecture

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

- Interactive diagram: https://gitdiagram.com/bayasdev/envycontrol
- Repository: https://github.com/bayasdev/envycontrol

## Overview

##### Project type and purpose
- This is a Python-based CLI tool (“envycontrol.py”) for switching GPU modes (integrated, hybrid, Nvidia) on Linux systems with hybrid graphics (Optimus). It handles configuration files (X11, modprobe, udev), calls into system utilities (nvidia-settings, xrandr), and manages a small JSON cache.

##### File structure
- Top-level files:
- envycontrol.py – main entry point containing CLI parsing and core logic
- setup.py – installer script for pip/packaging
- flake.nix – Nix packaging integration
- logos/ – project branding assets
- .github/, LICENSE, README.md, .gitignore – project metadata and CI/templates
- No frontend/backend split; it’s a single-process CLI with internal modules (all in envycontrol.py or imported from the standard library).

##### README for additional insights
- Describes supported modes, flags, cache behavior, display-manager workarounds, and deployment targets (AUR, Fedora COPR, Debian .deb, NixOS).
- Key architectural points: mode handlers for each GPU mode, a JSON cache in /var/cache/envycontrol, and per-DM hooks (GDM/SDDM/LightDM).

##### Capturing essential architectural elements
- GPU mode as a separate handler module.
- Cache Manager reading/writing the JSON file.
- How display-manager choice drives slight variations in file paths or scripts.
- Packaging artifacts (setup.py, flake.nix) as the installation/deployment component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::external

    subgraph "CLI & Control"
        CLI["CLI Parser"]:::cliControl
        Controller["ModeSwitchService"]:::cliControl
    end

    subgraph "Mode Handlers"
        Integrated["IntegratedHandler"]:::handlers
        Hybrid["HybridHandler"]:::handlers
        Nvidia["NvidiaHandler"]:::handlers
    end

    CacheMgr["Cache Manager"]:::storage

    subgraph "OS Interface"
        OSIface["OS Interface Layer"]:::osLayer
    end

    subgraph "External System Utilities"
        XRandr["xrandr"]:::external
        NvidiaSet["nvidia-settings"]:::external
        Modprobe["modprobe"]:::external
        Udev["udev rules"]:::external
        Xorg["Xorg config"]:::external
    end

    subgraph "Display Managers"
        GDM["GDM"]:::external
        SDDM["SDDM"]:::external
        LightDM["LightDM"]:::external
    end

    Disk["/var/cache/envycontrol/cache.json"]:::storage

    subgraph "Packaging/Installer"
        Setup["setup.py"]:::packaging
        Nix["flake.nix"]:::packaging
    end

    Logos["logos/"]:::assets

    User --> CLI
    CLI --> Controller
    Controller --> Integrated
    Controller --> Hybrid
    Controller --> Nvidia
    Hybrid --> CacheMgr
    CacheMgr --> Disk
    Integrated --> OSIface
    Hybrid --> OSIface
    Nvidia --> OSIface
    OSIface --> XRandr
    OSIface --> NvidiaSet
    OSIface --> Modprobe
    OSIface --> Udev
    OSIface --> Xorg
    OSIface --> GDM
    OSIface --> SDDM
    OSIface --> LightDM
    Controller <--> Setup
    Controller <--> Nix

    click CLI "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click Controller "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click Integrated "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click Hybrid "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click Nvidia "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click OSIface "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click CacheMgr "https://github.com/bayasdev/envycontrol/blob/main/envycontrol.py"
    click Setup "https://github.com/bayasdev/envycontrol/blob/main/setup.py"
    click Nix "https://github.com/bayasdev/envycontrol/blob/main/flake.nix"
    click Logos "https://github.com/bayasdev/envycontrol/tree/main/logos/"

    classDef cliControl fill:#cce5ff,stroke:#004085,color:#004085;
    classDef handlers fill:#d4edda,stroke:#155724,color:#155724;
    classDef osLayer fill:#ffe5b4,stroke:#b36b00,color:#b36b00;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef storage fill:#f8d7da,stroke:#721c24,color:#721c24;
    classDef packaging fill:#d1ecf1,stroke:#0c5460,color:#0c5460;
    classDef assets fill:#fde2e4,stroke:#a71d2a,color:#a71d2a;
```
