# gustavscirulis/snapgrid architecture

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

- Interactive diagram: https://gitdiagram.com/gustavscirulis/snapgrid
- Repository: https://github.com/gustavscirulis/snapgrid

## Overview

##### Main Components
- Electron Main Process: Located in the “electron” directory (files such as main.js, preload.cjs, secureStorage.cjs) handle window management, IPC communications, and integration with Node.js capabilities.
- Renderer Process: The front-end is built in the “src” folder. The entry point is main.tsx, with pages (e.g., Index.tsx, NotFound.tsx), various reusable React components (inside src/components and src/components/ui), and hooks/services (in src/hooks and src/services).
- Build & Configuration Tools: Vite (vite.config.ts), TypeScript (various tsconfig files), Tailwind CSS configurations (tailwind.config.ts), and Electron Builder (electron-builder.json) are used in bundling and building processes.
- External Services and APIs: The app interfaces with the OpenAI Vision API (indicated in src/services/aiAnalysisService.ts) to power AI detection, and a separate analytics and update service handle usage tracking and app updates.
- Local Storage: According to the README, SnapGrid stores images, metadata, and a “trash” folder on disk in user-specific directories (e.g., ~/Documents/SnapGrid on macOS).

##### Architectural Patterns and Design Principles
- Modularity of the ui/components (with reusable UI segments) and the clean separation of concerns among services (AI analysis, analytics, updates).
- That the build process (using Vite and Electron Builder) encapsulates the entire project, preparing it for cross-platform deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Electron Main Process Group
    subgraph "Electron Main Process"
        E_MAIN["Main Process"]
        EM_JS["main.js"]:::electronFile
        EP_CJS["preload.cjs"]:::electronFile
        ES_CJS["secureStorage.cjs"]:::electronFile
        E_MAIN --- EM_JS
        E_MAIN --- EP_CJS
        E_MAIN --- ES_CJS
    end

    %% Renderer Process Group
    subgraph "Renderer Process (React UI)"
        R_MAIN["UI Entry & Core Pages"]
        RTX["main.tsx"]:::rendererFile
        RPAGES["Pages (Index.tsx, NotFound.tsx)"]:::rendererFile
        RCOMP["Components (components & components/ui)"]:::rendererFile
        R_MAIN --- RTX
        R_MAIN --- RPAGES
        R_MAIN --- RCOMP
    end

    %% Build & Deployment Tools Group
    subgraph "Build & Deployment Tools"
        B_MAIN["Build Tools & Configurations"]
        BVITECONF["vite.config.ts"]:::buildFile
        BTWCONF["tailwind.config.ts"]:::buildFile
        BTSCONF["tsconfig.json"]:::buildFile
        BBUILDER["electron-builder.json"]:::buildFile
        B_MAIN --- BVITECONF
        B_MAIN --- BTWCONF
        B_MAIN --- BTSCONF
        B_MAIN --- BBUILDER
    end

    %% External APIs & Services Group
    subgraph "External APIs & Services"
        X_MAIN["APIs & Services"]
        X_AI["aiAnalysisService.ts"]:::apiFile
        X_ANALYTICS["analyticsService.ts"]:::apiFile
        X_UPDATE["updateService.ts"]:::apiFile
        X_MAIN --- X_AI
        X_MAIN --- X_ANALYTICS
        X_MAIN --- X_UPDATE
    end

    %% Local Storage Component
    LS["Local Storage (Screenshots, Metadata, Trash)"]:::localStorage

    %% Connections between groups
    R_MAIN -->|"IPC"| E_MAIN
    B_MAIN -->|"Build/Config"| E_MAIN
    B_MAIN -->|"Build/Config"| R_MAIN
    R_MAIN -->|"APIcalls"| X_MAIN
    E_MAIN -->|"FileOps"| LS
    R_MAIN -->|"Persistence"| LS

    %% Click Events for Electron Main Process files
    click EM_JS "https://github.com/gustavscirulis/snapgrid/blob/main/electron/main.js"
    click EP_CJS "https://github.com/gustavscirulis/snapgrid/blob/main/electron/preload.cjs"
    click ES_CJS "https://github.com/gustavscirulis/snapgrid/blob/main/electron/secureStorage.cjs"

    %% Click Events for Renderer Process files
    click RTX "https://github.com/gustavscirulis/snapgrid/blob/main/src/main.tsx"
    click RPAGES "https://github.com/gustavscirulis/snapgrid/tree/main/src/pages"
    click RCOMP "https://github.com/gustavscirulis/snapgrid/tree/main/src/components"

    %% Click Events for Build & Deployment Tools
    click BVITECONF "https://github.com/gustavscirulis/snapgrid/blob/main/vite.config.ts"
    click BTWCONF "https://github.com/gustavscirulis/snapgrid/blob/main/tailwind.config.ts"
    click BTSCONF "https://github.com/gustavscirulis/snapgrid/blob/main/tsconfig.json"
    click BBUILDER "https://github.com/gustavscirulis/snapgrid/blob/main/electron-builder.json"

    %% Click Events for External APIs & Services
    click X_AI "https://github.com/gustavscirulis/snapgrid/blob/main/src/services/aiAnalysisService.ts"
    click X_ANALYTICS "https://github.com/gustavscirulis/snapgrid/blob/main/src/services/analyticsService.ts"
    click X_UPDATE "https://github.com/gustavscirulis/snapgrid/blob/main/src/services/updateService.ts"

    %% Styles
    classDef electronFile fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef rendererFile fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef buildFile fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef apiFile fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef localStorage fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef default fill:#ffffff,stroke:#333,stroke-width:1px;
```
