# mrtracker-new/bar architecture

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

- Interactive diagram: https://gitdiagram.com/mrtracker-new/bar
- Repository: https://github.com/mrtracker-new/bar

## Overview

##### Project Type and Purpose
- BAR is a standalone, offline desktop application (Python + PyQt5) for secure file management with built-in self-destruct mechanisms. There is no client-server communication; all components run locally. Its goals are file encryption, secure deletion, hardware-bound key management, user authentication (with 2FA), and comprehensive audit logging.

##### High-Level Architecture Overview
- Layered, modular design with clearly separated concerns:
- Presentation Layer (GUI)
- Application Core / Orchestration
- Domain Services (File Management, Crypto, Security, User Management, Config)
- Persistence (Local Filesystem storage under `~/.bar`, logs)

##### Main Components
a. Presentation (src/gui)
- LoginDialog, RegisterDialog, TwoFactorDialog → handle user auth flows
- MainWindow, FileViewer, FileDialog, SettingsDialog → core UI for file operations
- Styles → theming

b. Application Core
- main.py → entry point; initializes config, logging, GUI event loop, thread pools
- build.py, setup.py → packaging and installation

c. Configuration (src/config)
- config_manager.py → loads/saves app settings, theme, default security policies

d. User Management (src/user_manager)
- user_manager.py → local user registration, password hashing (PBKDF2), 2FA setup/integration

e. File Management (src/file_manager)
- file_manager.py → creates/decrypts .bar files, enforces time/access limits
- file_scanner.py → multi-threaded scanning of drives for .bar files

f. Cryptography (src/crypto)
- encryption.py → AES-256-GCM encryption/decryption, key derivation, secure memory handling

g. Security (src/security)
- session_manager.py → tracks user login session and expiration
- two_factor_auth.py → TOTP generation/verification
- audit_log.py → writes audit events to `~/.bar/logs`
- secure_delete.py → multi-pass overwrite per DoD standards
- hardware_id.* → hardware-binding support (C/Cython bridge)
- screen_protection.py, win_screenshot_prevention.py → screenshot blocking

h. Persistence
- Local filesystem under user home (`~/.bar`) for encrypted files, configs, logs

##### Interactions and Data Flows
1. Startup: main.py → config_manager loads settings → GUI (MainWindow)
2. User Login: GUI → session_manager + user_manager → two_factor_auth → audit_log
3. File: GUI → file_manager
→ crypto.encrypt(file, policy)
→ secure_delete (for overwritten originals)
→ write to `~/.bar/files`
→ audit_log
4. Access File: GUI → file_manager → crypto.decrypt
→ session_manager checks policy (time/access count)
→ audit_log
5. Scan Drives: GUI → file_scanner (thread pool) → each thread invokes file_manager integrity checks, crypto.verify → returns found items to GUI
6. Background Enforcement: security background threads monitor policies (deadman switch, anti-brute force), trigger secure_delete if violated

##### Architectural Patterns & Principles
- Layered architecture: GUI → Services → Persistence
- Dependency inversion: high-level modules (GUI/core) depend on abstractions in domain services
- Single Responsibility: each module handles one aspect (config vs. crypto vs. scanning vs. UI)
- Observer/Event logging: audit_log captures events from all layers
- Concurrency: file scanning and background enforcement run in separate threads

- file_manager ↔ encryption (bidirectional: supplies plaintext/ciphertext)
- security modules (session_manager, hardware_id) → file_manager and crypto (to enforce policy/timeouts)
- file_scanner → file_manager → crypto (for integrity checks)
- audit_log ← all major operations (login, encrypt, decrypt, delete)

##### Final Checklist
- [ ] All 8 major modules represented
- [ ] Layer labels (Presentation, Core, Services, Persistence)
- [ ] Note storage location (`~/.bar`) and logging directory

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    subgraph "Presentation Layer"
        direction TB
        LD["LoginDialog"]:::gui
        RD["RegisterDialog"]:::gui
        TF["TwoFactorDialog"]:::gui
        MW["MainWindow"]:::gui
        FV["FileViewer"]:::gui
        FD["FileDialog"]:::gui
        SD["SettingsDialog"]:::gui
        ST["Styles"]:::gui
    end

    subgraph "Application Core / Orchestration"
        direction TB
        MP["main.py"]:::core
        BS["build.py"]:::core
        SP["setup.py"]:::core
    end

    subgraph "Domain Services"
        direction TB
        subgraph "Configuration"
            CM["config_manager.py"]:::services
        end
        subgraph "User Management"
            UM["user_manager.py"]:::services
        end
        subgraph "File Management"
            FM["file_manager.py"]:::services
            FS["file_scanner.py"]:::services
        end
        subgraph "Cryptography"
            CR["encryption.py"]:::services
        end
        subgraph "Security"
            SM["session_manager.py"]:::services
            TFA["two_factor_auth.py"]:::services
            AL["audit_log.py"]:::services
            SDT["secure_delete.py"]:::services
            HIc["hardware_id.c"]:::services
            HIpy["hardware_id.py"]:::services
            HIpx["hardware_id.pyx"]:::services
            HIB["hardware_id_bridge.py"]:::services
            HIP["hardware_id_cy.pyi"]:::services
            SPROT["screen_protection.py"]:::services
            WSP["win_screenshot_prevention.py"]:::services
        end
    end

    subgraph "Persistence (Local Filesystem under ~/.bar)" 
        direction TB
        FSYS["Filesystem Storage"]:::persistence
        LOGS["Audit Logs"]:::persistence
    end

    %% Interactions
    LD -->|auth event| MP
    RD -->|registration event| MP
    TF -->|2FA event| MP
    MW -->|UI action| MP
    FV --> MP
    FD --> MP
    SD --> MP
    ST --> MW

    MP -->|loads settings| CM
    MP -->|init session| SM
    MP -->|init user manager| UM
    MP -->|init file manager| FM
    MP -->|init security| SM

    FM -->|Encrypt/Decrypt calls| CR
    CR -->|returns ciphertext/plain| FM
    SM -->|policy check| FM
    SM -->|session validation| CR
    TFA -->|TOTP verify| UM
    UM -->|2FA setup| TFA

    FS -->|scan drives| FM
    FS -->|integrity check| CR
    FS -->|results| MW

    FM -->|writes files| FSYS
    FM -->|audit event| AL
    FM -->|secure delete originals| SDT

    MP -->|audit startup| AL
    SM -->|audit session| AL
    UM -->|audit auth| AL
    AL -->|writes log| LOGS

    %% Background enforcement
    classDef dashed stroke-dasharray: 5 5
    Deadman["Deadman Switch"]:::services
    BruteForce["Anti-Brute Force"]:::services
    Deadman -.->|monitor| SM
    BruteForce -.->|monitor| SM
    Deadman -.->|trigger delete| SDT
    BruteForce -.->|trigger delete| SDT

    %% Click Events
    click LD "https://github.com/mrtracker-new/bar/blob/main/src/gui/login_dialog.py"
    click RD "https://github.com/mrtracker-new/bar/blob/main/src/gui/register_dialog.py"
    click TF "https://github.com/mrtracker-new/bar/blob/main/src/gui/two_factor_dialog.py"
    click MW "https://github.com/mrtracker-new/bar/blob/main/src/gui/main_window.py"
    click FV "https://github.com/mrtracker-new/bar/blob/main/src/gui/file_viewer.py"
    click FD "https://github.com/mrtracker-new/bar/blob/main/src/gui/file_dialog.py"
    click SD "https://github.com/mrtracker-new/bar/blob/main/src/gui/settings_dialog.py"
    click ST "https://github.com/mrtracker-new/bar/blob/main/src/gui/styles.py"
    click MP "https://github.com/mrtracker-new/bar/blob/main/main.py"
    click BS "https://github.com/mrtracker-new/bar/blob/main/build.py"
    click SP "https://github.com/mrtracker-new/bar/blob/main/setup.py"
    click CM "https://github.com/mrtracker-new/bar/blob/main/src/config/config_manager.py"
    click UM "https://github.com/mrtracker-new/bar/blob/main/src/user_manager/user_manager.py"
    click FM "https://github.com/mrtracker-new/bar/blob/main/src/file_manager/file_manager.py"
    click FS "https://github.com/mrtracker-new/bar/blob/main/src/file_manager/file_scanner.py"
    click CR "https://github.com/mrtracker-new/bar/blob/main/src/crypto/encryption.py"
    click SM "https://github.com/mrtracker-new/bar/blob/main/src/security/session_manager.py"
    click TFA "https://github.com/mrtracker-new/bar/blob/main/src/security/two_factor_auth.py"
    click AL "https://github.com/mrtracker-new/bar/blob/main/src/security/audit_log.py"
    click SDT "https://github.com/mrtracker-new/bar/blob/main/src/security/secure_delete.py"
    click HIc "https://github.com/mrtracker-new/bar/blob/main/src/security/hardware_id.c"
    click HIpy "https://github.com/mrtracker-new/bar/blob/main/src/security/hardware_id.py"
    click HIpx "https://github.com/mrtracker-new/bar/blob/main/src/security/hardware_id.pyx"
    click HIB "https://github.com/mrtracker-new/bar/blob/main/src/security/hardware_id_bridge.py"
    click HIP "https://github.com/mrtracker-new/bar/blob/main/src/security/hardware_id_cy.pyi"
    click SPROT "https://github.com/mrtracker-new/bar/blob/main/src/security/screen_protection.py"
    click WSP "https://github.com/mrtracker-new/bar/blob/main/src/security/win_screenshot_prevention.py"

    %% Styles
    classDef gui fill:#cce5ff,stroke:#004085,color:#004085
    classDef core fill:#d4edda,stroke:#155724,color:#155724
    classDef services fill:#ffe5b4,stroke:#856404,color:#856404
    classDef persistence fill:#e2e3e5,stroke:#383d41,color:#383d41
    class Deadman,BruteForce dashed
```
