# kleneway/pastemax architecture

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

- Interactive diagram: https://gitdiagram.com/kleneway/pastemax
- Repository: https://github.com/kleneway/pastemax

## Overview

##### Main Components
a. Electron Main Process:
- Represented by files like main.js and preload.js.
- Manages application window creation, integration with Node.js modules, and coordination of application lifecycle events.
b. Renderer Process (React Application):
- Located under the src/ directory containing App.tsx, components/ (like FileCard.tsx, FileList.tsx, Sidebar.tsx, etc.), context (ThemeContext.tsx), and styles.
- This layer is responsible for rendering the UI, handling user interactions, and performing client-side logic (e.g., search, token count).
c. Build and Packaging:
- Build scripts such as build.js, dev.js, and configuration files like vite.config.ts, tsconfig.json.
- CI/CD-related files under .github/workflows indicate automated builds, tests, and release/deployment processes.
d. External Utilities & Libraries:
- tiktoken for token counting.
- “ignore” library for file-exclusion logic, as configured in excluded-files.js.
- Docker & Docker Compose are present (Dockerfile, docker-compose.yml) for containerization/deployment.
e. Documentation and Supporting Scripts:
- Documentation in docs/ (design.md, KnownIssue.md, etc.), and additional scripts for dependency fixing and notarizing (scripts/fix-dependencies.js, scripts/notarize.js).

##### Relationships and Interactions
- Preload layer, which securely exposes necessary APIs between Node and the Renderer.
- Bidirectional communication (using IPC mechanisms) between the main and renderer processes.

##### Architectural Patterns and Design Principles
- Separation of concerns:
- Main Process (Electron orchestration) vs. Renderer Process (UI logic).
- Use of modular React components (listed under src/components) which follow component-based UI design.
- That the project makes use of Context API (ThemeContext) for state management like dark/light mode toggling.
- That there is a build-time pipeline (with Vite, build.js, and various npm scripts) that bundles the React codebase and integrates it with Electron’s packaging process.

- Electron for cross-platform desktop apps.
- React for UI.
- TypeScript for type safety.
- Vite for fast development and production builds.
- tiktoken for token counting and “ignore” for file filtering.
- Docker related files indicate containerization support.
- GitHub workflows for CI/CD automation.

- Under Application Runtime:
- Under it, detail the Preload module that connects to the Renderer.
- Divide the Renderer section to highlight the React App, including key components (Sidebar, FileList, SearchBar) and mention state management (ThemeContext).
- Interaction with external utilities (e.g., token counting and file exclusion).
- Under Build/Deployment:
- Vite configuration and build scripts.
- CI/CD pipeline (using GitHub workflows) and packaging processes (Docker support, executable generation).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Runtime Layer
    subgraph "Application Runtime"
        %% Electron Shell
        subgraph "Electron Shell"
            EM["Electron Main Process"]:::electron
            PL["Preload Module"]:::electron
        end

        %% IPC Communication between Main and Renderer (bidirectional)
        EM ---|IPC| PL

        %% Renderer Process Layer
        subgraph "Renderer Process"
            RA["App (React Root)"]:::react
            subgraph "React UI Components"
                SB["Sidebar"]:::react
                FL["FileList"]:::react
                SH["SearchBar"]:::react
                FC["FileCard"]:::react
                TI["TreeItem"]:::react
                TT["ThemeToggle"]:::react
                UI["UserInstructions"]:::react
            end
            TC["ThemeContext"]:::react
            ST["Styles"]:::react
        end

        %% Communication between Preload and Renderer
        PL ---|Secure Bridge| RA

        %% Interaction with External Utilities (from Renderer)
        RA ---|"calls"| EX1["File Exclusion Logic"]:::utility
        RA ---|"calls"| EX2["Token Counting"]:::utility
        RA ---|"calls"| EX3["Path Utilities"]:::utility

    end

    %% Build and Deployment Layer
    subgraph "Build/Deployment"
        BS["Build Scripts"]:::build
        VC["Vite Config"]:::build
        TSC["TypeScript Configs"]:::build
        GH["GitHub Workflows"]:::build
        DC["Containerization"]:::build
        DS["Support Scripts"]:::build
        DOC["Documentation"]:::build
    end

    %% Build Pipeline Flow
    GH --> BS
    BS --> VC
    VC --> RA
    BS --> TSC
    TSC --> RA
    BS --> DC
    DS --- DOC

    %% Styles
    classDef electron fill:#ffd1dc,stroke:#c2185b,stroke-width:2px;
    classDef react fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef build fill:#bbdefb,stroke:#1976d2,stroke-width:2px;
    classDef utility fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;

    %% Click Events for Electron Main Process and Preload Module
    click EM "https://github.com/kleneway/pastemax/blob/main/main.js"
    click PL "https://github.com/kleneway/pastemax/blob/main/preload.js"

    %% Click Events for Renderer Process Components
    click RA "https://github.com/kleneway/pastemax/blob/main/src/App.tsx"
    click SB "https://github.com/kleneway/pastemax/blob/main/src/components/Sidebar.tsx"
    click FL "https://github.com/kleneway/pastemax/blob/main/src/components/FileList.tsx"
    click SH "https://github.com/kleneway/pastemax/blob/main/src/components/SearchBar.tsx"
    click FC "https://github.com/kleneway/pastemax/blob/main/src/components/FileCard.tsx"
    click TI "https://github.com/kleneway/pastemax/blob/main/src/components/TreeItem.tsx"
    click TT "https://github.com/kleneway/pastemax/blob/main/src/components/ThemeToggle.tsx"
    click UI "https://github.com/kleneway/pastemax/blob/main/src/components/UserInstructions.tsx"
    click TC "https://github.com/kleneway/pastemax/blob/main/src/context/ThemeContext.tsx"
    click ST "https://github.com/kleneway/pastemax/tree/main/src/styles"

    %% Click Events for Build and Packaging Layer
    click BS "https://github.com/kleneway/pastemax/blob/main/build.js"
    click VC "https://github.com/kleneway/pastemax/blob/main/vite.config.ts"
    click TSC "https://github.com/kleneway/pastemax/blob/main/tsconfig.json"
    click GH "https://github.com/kleneway/pastemax/tree/main/.github/workflows"
    click DC "https://github.com/kleneway/pastemax/tree/main/Dockerfile"

    %% Click Events for External Utilities & Libraries
    click EX1 "https://github.com/kleneway/pastemax/blob/main/excluded-files.js"
    click EX2 "https://github.com/kleneway/pastemax/blob/main/docs/tiktoken.md"
    click EX3 "https://github.com/kleneway/pastemax/blob/main/src/utils/pathUtils.ts"

    %% Click Events for Documentation and Supporting Scripts
    click DOC "https://github.com/kleneway/pastemax/tree/main/docs"
    click DS "https://github.com/kleneway/pastemax/tree/main/scripts"
```
