# paulinotech1/state-gaurd architecture

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

- Interactive diagram: https://gitdiagram.com/paulinotech1/state-gaurd
- Repository: https://github.com/paulinotech1/state-gaurd

## Overview

State Guard is a local Windows/Linux endpoint auditing and JSON configuration drift/remediation tool, with CLI and Tkinter interfaces. The principal workflow loads a desired-state policy, compares it with a configuration, previews changes, and—only when explicitly applied—creates recovery material and replaces the file; rollback can restore original bytes. Endpoint indicators are read-only. The graph separates interface, audit/policy stages, JSON handling, and guarded local storage. Source excerpts show the main calls; README statements support the documented platform checks and recovery behavior.

Main entry points: [`state_guard.py`](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py) (Preview and apply), [`state_guard_gui.py`](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_gui.py) (Desktop interface), [`state_guard_storage.py`](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py) (File safety primitives), [`state_guard_json.py`](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_json.py) (Strict JSON decode)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_cli["CLI dispatcher<br/>[state_guard.py]"]
  node_gui["Desktop interface<br/>[state_guard_gui.py]"]
end

subgraph group_audit_policy["Audit and policy"]
  node_audit["Endpoint checks<br/>[state_guard.py]"]
  node_platform_checks["Platform indicators<br/>[state_guard.py]"]
  node_policy["Policy loading<br/>[state_guard.py]"]
  node_drift["Config comparison<br/>[state_guard.py]"]
  node_remediate["Preview and apply<br/>[state_guard.py]"]
  node_rollback["Rollback checks<br/>[state_guard.py]"]
end

subgraph group_json["JSON processing"]
  node_json_decode["Strict JSON decode"]
  node_json_render["Minimal JSON edits"]
end

subgraph group_storage["Guarded file operations"]
  node_storage["File safety primitives"]
  node_locks["Operation locks"]
  node_recovery["Private recovery files"]
  node_replacement["Atomic replacement"]
end

node_cli_user(("CLI user"))
node_desktop_user(("Desktop user"))
node_endpoint_sources{{"Windows/Linux settings"}}

node_cli_user -->|"runs"| node_cli
node_desktop_user -->|"uses"| node_gui
node_cli -->|"dispatches"| node_audit
node_cli -->|"loads"| node_policy
node_cli -->|"checks"| node_drift
node_cli -->|"dispatches"| node_remediate
node_cli -->|"dispatches"| node_rollback
node_audit -->|"collects"| node_platform_checks
node_platform_checks -->|"reads indicators"| node_endpoint_sources
node_gui -->|"calls"| node_audit
node_gui -->|"calls"| node_policy
node_gui -->|"calls"| node_drift
node_gui -->|"calls"| node_remediate
node_gui -->|"calls"| node_rollback
node_drift -->|"reads config"| node_storage
node_drift -->|"decodes"| node_json_decode
node_remediate -->|"inspects config"| node_drift
node_remediate -->|"renders edits"| node_json_render
node_remediate -->|"locks operation"| node_locks
node_remediate -->|"creates recovery"| node_recovery
node_remediate -->|"updates config"| node_replacement
node_rollback -->|"locks operation"| node_locks
node_rollback -->|"reads recovery"| node_recovery
node_rollback -->|"restores bytes"| node_replacement
node_locks -->|"uses primitives"| node_storage
node_recovery -->|"uses primitives"| node_storage
node_replacement -->|"uses primitives"| node_storage

click node_cli "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_gui "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_gui.py"
click node_audit "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_platform_checks "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_policy "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_drift "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_remediate "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_rollback "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py"
click node_json_decode "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_json.py"
click node_json_render "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_json.py"
click node_storage "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py"
click node_locks "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py"
click node_recovery "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py"
click node_replacement "https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_gui,node_cli_user,node_desktop_user toneBlue
class node_audit,node_platform_checks,node_policy,node_drift,node_remediate,node_rollback toneAmber
class node_json_decode,node_json_render toneMint
class node_storage,node_locks,node_recovery,node_replacement toneRose
class node_endpoint_sources toneIndigo
```

## Components

### User interfaces

- [CLI dispatcher](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`
- [Desktop interface](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_gui.py): `state_guard_gui.py`

### Audit and policy

- [Endpoint checks](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`
- [Platform indicators](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`
- [Policy loading](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`
- [Config comparison](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`
- [Preview and apply](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`
- [Rollback checks](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard.py): `state_guard.py`

### JSON processing

- [Strict JSON decode](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_json.py): `state_guard_json.py`
- [Minimal JSON edits](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_json.py): `state_guard_json.py`

### Guarded file operations

- [File safety primitives](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py): `state_guard_storage.py`
- [Operation locks](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py): `state_guard_storage.py`
- [Private recovery files](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py): `state_guard_storage.py`
- [Atomic replacement](https://github.com/paulinotech1/state-gaurd/blob/main/state_guard_storage.py): `state_guard_storage.py`

### Other components

- **CLI user**
- **Desktop user**
- **Windows/Linux settings**

## Connections

- CLI user → CLI dispatcher: runs (evidence: `README.md`)
- Desktop user → Desktop interface: uses (evidence: `README.md`)
- CLI dispatcher → Endpoint checks: dispatches (evidence: `state_guard.py`)
- CLI dispatcher → Policy loading: loads (evidence: `state_guard.py`)
- CLI dispatcher → Config comparison: checks (evidence: `state_guard.py`)
- CLI dispatcher → Preview and apply: dispatches (evidence: `state_guard.py`)
- CLI dispatcher → Rollback checks: dispatches (evidence: `state_guard.py`)
- Endpoint checks → Platform indicators: collects (evidence: `state_guard.py`)
- Platform indicators → Windows/Linux settings: reads indicators (evidence: `README.md`)
- Desktop interface → Endpoint checks: calls (evidence: `state_guard_gui.py`)
- Desktop interface → Policy loading: calls (evidence: `state_guard_gui.py`)
- Desktop interface → Config comparison: calls (evidence: `state_guard_gui.py`)
- Desktop interface → Preview and apply: calls (evidence: `state_guard_gui.py`)
- Desktop interface → Rollback checks: calls (evidence: `state_guard_gui.py`)
- Config comparison → File safety primitives: reads config (evidence: `state_guard.py`)
- Config comparison → Strict JSON decode: decodes (evidence: `state_guard.py`)
- Preview and apply → Config comparison: inspects config (evidence: `state_guard.py`)
- Preview and apply → Minimal JSON edits: renders edits (evidence: `state_guard.py`)
- Preview and apply → Operation locks: locks operation (evidence: `state_guard.py`)
- Preview and apply → Private recovery files: creates recovery (evidence: `state_guard.py`)
- Preview and apply → Atomic replacement: updates config (evidence: `state_guard.py`)
- Rollback checks → Operation locks: locks operation (evidence: `state_guard.py`)
- Rollback checks → Private recovery files: reads recovery (evidence: `state_guard.py`)
- Rollback checks → Atomic replacement: restores bytes (evidence: `state_guard.py`)
- Operation locks → File safety primitives: uses primitives (evidence: `state_guard_storage.py`)
- Private recovery files → File safety primitives: uses primitives (evidence: `state_guard_storage.py`)
- Atomic replacement → File safety primitives: uses primitives (evidence: `state_guard_storage.py`)
