# krystianhub/stayawake architecture

> Architecture diagram of the GitHub repository krystianhub/stayawake, 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/krystianhub/stayawake
- Repository: https://github.com/krystianhub/stayawake

## Overview

##### Main Components

a) Core System Components:
- Configuration Manager (handling .env and environment variables)
- Mouse Activity Monitor
- Offset Generator (for calculating mouse movements)
- Platform-Specific Power Management
- Windows Implementation
- MacOS Implementation
- Default Implementation

b) Input/Output Systems:
- Mouse Input Detection
- Mouse Movement Simulation
- Configuration File Reader
- Logging System

##### Architecture Pattern
The project follows a modular architecture with platform-specific implementations. Here's how to represent this:

**Top Layer: Main Application Logic**
**Middle Layer: Platform-Agnostic Components**
**Bottom Layer: Platform-Specific Implementations**

##### Configuration Flow
- .env file → Configuration Manager → System Settings
##### Main Process Flow
- Mouse Activity Monitor → Offset Generator → Platform-Specific Implementation
##### Platform-Specific Flow
- Separate paths for Windows/MacOS implementations

##### Key Relationships

**Config Manager ─────┐**
- ↓
**Mouse Monitor ──→ Main Logic ──→ Offset Generator**
- ↓
- Platform Layer
- ╱     ╲
- Windows  MacOS

##### Important Details

a) Timing Components:
- 15-second activity check interval
- 100-150 pixel movement range

b) Configuration Parameters:
- 6 configurable properties
- Their flow into the system

##### Technical Specifications

A technical notes section showing:
- Built with Rust
- Platform support (Windows & MacOS)
- Environment variable configuration
- Logging levels

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Configuration
        ENV[".env File"]
        CM["Configuration Manager"]
        Models["Data Models"]
    end

    subgraph "Core Logic"
        MAM["Mouse Activity Monitor"]
        ML["Main Logic"]
        OG["Offset Generator"]
    end

    subgraph "Platform Layer"
        PM["Power Management"]
        subgraph "Platform Implementations"
            WIN["Windows Implementation"]
            MAC["MacOS Implementation"]
            DEF["Default Implementation"]
        end
    end

    %% Relationships
    ENV --> CM
    CM --> ML
    Models --> ML
    MAM --> ML
    ML --> OG
    OG --> PM
    PM --> WIN
    PM --> MAC
    PM --> DEF

    %% Click Events
    click CM "https://github.com/krystianhub/StayAwake/blob/master/src/config.rs"
    click ENV "https://github.com/krystianhub/StayAwake/blob/master/.env"
    click OG "https://github.com/krystianhub/StayAwake/blob/master/src/offset_generator.rs"
    click WIN "https://github.com/krystianhub/StayAwake/blob/master/src/power/platform/windows.rs"
    click MAC "https://github.com/krystianhub/StayAwake/blob/master/src/power/platform/macos.rs"
    click DEF "https://github.com/krystianhub/StayAwake/blob/master/src/power/platform/default.rs"
    click PM "https://github.com/krystianhub/StayAwake/blob/master/src/power/mod.rs"
    click Models "https://github.com/krystianhub/StayAwake/blob/master/src/models.rs"
    click ML "https://github.com/krystianhub/StayAwake/blob/master/src/main.rs"

    %% Styling
    classDef config fill:#ff9,stroke:#333
    classDef core fill:#9cf,stroke:#333
    classDef platform fill:#9f9,stroke:#333
    classDef file fill:#ddd,stroke:#333

    class ENV,CM,Models config
    class MAM,ML,OG core
    class PM,WIN,MAC,DEF platform

    %% Technical Notes
    subgraph "Technical Specifications"
        TN1["Built with Rust"]
        TN2["15s Activity Check"]
        TN3["100-150px Movement"]
    end

    %% Legend
    subgraph "Legend"
        L1["Configuration Component"]:::config
        L2["Core Component"]:::core
        L3["Platform Component"]:::platform
        L4["File"]:::file
    end
```
