# laughing-man-dev/stegano-g architecture

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

- Interactive diagram: https://gitdiagram.com/laughing-man-dev/stegano-g
- Repository: https://github.com/laughing-man-dev/stegano-g

## Overview

##### Project Type and Purpose
- This is a **browser extension** (Chrome/Firefox) that runs entirely client-side.
- Key responsibilities:
– Embedding/extracting hidden data in images (LSB steganography)
– Cryptographic signing, verification, and stamping using Web Crypto API
– UI for user interactions via popup and options pages

##### File Structure
Top-level:
- manifest.json – declares extension components and permissions
/src:
- background/background.js – the **event‐driven background script** (core logic: key management, crypto, stego)
- content/content.js – optional **content script** (page injections, not yet used)
- popup/{popup.html, popup.js, popup.css} – **popup UI** for user workflows
- options/{options.html, options.js, options.css} – **options page** for key & settings management
- utils/*.js – **helper libraries** (steganography, image loading/overlay, keypairs, crypto wrappers)
/testing – sample images and keys for offline testing

##### Extract Architectural Insights from the README
- Uses **Canvas API** for image processing
- Uses **Web Crypto API** for AES-GCM and RSA operations
- Entirely offline, runs in browser sandbox
- Messaging between UI and background (chrome.runtime.sendMessage / onMessage)

##### Main Components & Their Roles
a. **Manifest & Extension Shell**
– Entry point: declares background, popup, options, content scripts, permissions (storage, activeTab, etc.)
b. **Background Script**
– Central coordinator:
- Generates/manages RSA keypairs
- Performs AES encryption/decryption and LSB steganography
- Listens to UI messages, returns results
c. **Popup UI**
– User initiates actions:
- Choose image, embed/extract data
- Sign or verify content
- Requests background via messaging
d. **Options Page**
– Manage stored keys, metadata settings, alt-text
e. **Content Script (future use)**
– Injects UI into web pages, or operates on page images directly
f. **Utilities**
– LSB functions, image loaders, overlays, keypair storage helper
g. **Web APIs (external)**
– Canvas API – manipulate pixel data
– Web Crypto API – encryption, signing
h. **Testing Assets**
– Predefined images & JSON keys to verify integration and data flow

##### Relationships & Interactions
- **User ↔ Popup UI**: clicks buttons, chooses files.
- **Popup UI ↔ Background**: via message passing (chrome.runtime.sendMessage).
- **Background ↔ Utils**: calls steganography.js, imageOverlay.js, keypairs.js.
- **Background ↔ Web Crypto API**: for AES-GCM, RSA.
- **Background ↔ Canvas API**: for pixel‐level manipulation.
- **Options UI ↔ Background**: same messaging channel for key management.
- **Content Script (future)** ↔ Background/UI: via messaging or DOM injection.

##### Architectural Patterns & Principles
- **Modular separation**: UI logic (popup/options), business logic (background), utility library, data store.
- **Event‐driven architecture**: background script reacts to messages.
- **Single Responsibility**: each module focuses on one domain (UI, crypto, stego, key management).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Manifest
    subgraph "Manifest & Extension Shell"
        Manifest["manifest.json"]:::core
    end

    %% UI Components
    subgraph "UI Components"
        direction TB
        subgraph "Popup UI"
            PopupHTML["popup.html"]:::frontend
            PopupJS["popup.js"]:::frontend
            PopupCSS["popup.css"]:::frontend
        end
        subgraph "Options UI"
            OptionsHTML["options.html"]:::frontend
            OptionsJS["options.js"]:::frontend
            OptionsCSS["options.css"]:::frontend
        end
    end

    %% Core Logic
    subgraph "Core Logic"
        direction TB
        Background["Background Script"]:::core
        subgraph "Utilities"
            Stego["steganography.js"]:::utils
            ImgLoad["imageLoading.js"]:::utils
            ImgOverlay["imageOverlay.js"]:::utils
            Keypairs["keypairs.js"]:::utils
            Helper["helper.js"]:::utils
        end
    end

    %% External APIs
    subgraph "External APIs"
        CanvasAPI["Canvas API"]:::external
        CryptoAPI["Web Crypto API"]:::external
    end

    %% Future Feature
    Content["Content Script"]:::future

    %% Testing Assets
    subgraph "Testing Assets"
        Images["images/"]:::testing
        Keys["testing_keys/"]:::testing
    end

    %% Extension Icons
    Icons["icons/"]:::assets

    %% Connections
    Manifest -->|declares| PopupHTML
    Manifest -->|declares| OptionsHTML
    Manifest -->|declares| Background
    Manifest -->|declares| Content
    Manifest -->|uses| Icons

    PopupJS -->|"chrome.runtime.sendMessage"| Background
    Background -->|"response"| PopupJS

    OptionsJS -->|"chrome.runtime.sendMessage"| Background
    Background -->|"response"| OptionsJS

    Background -->|"uses"| Stego
    Background -->|"uses"| ImgLoad
    Background -->|"uses"| ImgOverlay
    Background -->|"uses"| Keypairs
    Background -->|"uses"| Helper

    Background -->|"pixel manipulation"| CanvasAPI
    Background -->|"crypto operations"| CryptoAPI

    Images -->|"offline testing"| Background
    Keys -->|"offline testing"| Background

    Content -.->|future messaging| Background
    Content -.->|future UI injection| PopupJS

    %% Click Events
    click Manifest "https://github.com/laughing-man-dev/stegano-g/blob/main/manifest.json"
    click Background "https://github.com/laughing-man-dev/stegano-g/blob/main/src/background/background.js"
    click PopupHTML "https://github.com/laughing-man-dev/stegano-g/blob/main/src/popup/popup.html"
    click PopupJS "https://github.com/laughing-man-dev/stegano-g/blob/main/src/popup/popup.js"
    click PopupCSS "https://github.com/laughing-man-dev/stegano-g/blob/main/src/popup/popup.css"
    click OptionsHTML "https://github.com/laughing-man-dev/stegano-g/blob/main/src/options/options.html"
    click OptionsJS "https://github.com/laughing-man-dev/stegano-g/blob/main/src/options/options.js"
    click OptionsCSS "https://github.com/laughing-man-dev/stegano-g/blob/main/src/options/options.css"
    click Content "https://github.com/laughing-man-dev/stegano-g/blob/main/src/content/content.js"
    click Stego "https://github.com/laughing-man-dev/stegano-g/blob/main/src/utils/steganography.js"
    click ImgLoad "https://github.com/laughing-man-dev/stegano-g/blob/main/src/utils/imageLoading.js"
    click ImgOverlay "https://github.com/laughing-man-dev/stegano-g/blob/main/src/utils/imageOverlay.js"
    click Keypairs "https://github.com/laughing-man-dev/stegano-g/blob/main/src/utils/keypairs.js"
    click Helper "https://github.com/laughing-man-dev/stegano-g/blob/main/src/utils/helper.js"
    click Images "https://github.com/laughing-man-dev/stegano-g/tree/main/testing/images/"
    click Keys "https://github.com/laughing-man-dev/stegano-g/tree/main/testing/testing_keys/"
    click Icons "https://github.com/laughing-man-dev/stegano-g/tree/main/icons/"

    %% Styles
    classDef frontend fill:#D6E9FF,stroke:#2196F3,stroke-width:2px
    classDef core fill:#E8F5E9,stroke:#4CAF50,stroke-width:2px
    classDef utils fill:#F1F8E9,stroke:#8BC34A,stroke-width:2px
    classDef external fill:#ECEFF1,stroke:#90A4AE,stroke-width:2px
    classDef future fill:#FFF3E0,stroke:#FF9800,stroke-width:2px,stroke-dasharray:5 5
    classDef testing fill:#FFFDE7,stroke:#FBC02D,stroke-width:2px
    classDef assets fill:#F3E5F5,stroke:#9C27B0,stroke-width:2px
```
