# nikhilsearch/google-sheet-email-extractor architecture

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

- Interactive diagram: https://gitdiagram.com/nikhilsearch/google-sheet-email-extractor
- Repository: https://github.com/nikhilsearch/google-sheet-email-extractor

## Overview

##### Project type and purpose
- This is a Google Apps Script “add-on” for Google Sheets.
- Purpose: provide a custom menu in a spreadsheet to extract email addresses either from URLs in cells or from arbitrary cell text.

##### File structure
- Top-level files:
- Email extrator code V3.gs – the entire script.
- README.md – documentation.
- No separate frontend/backend directories; it’s a single-file serverless script running in Google’s Apps Script environment.

##### README for additional insights
- Custom menu named “Email Extractor” with two actions:
a. Extract from URLs in Column A → outputs to Column B.
b. Extract from a specified cell’s text → shows an alert.
- Uses built-in UrlFetchApp and SpreadsheetApp services.
- Handles standard and obfuscated email formats via regex.

##### Components and interactions
a. Main components:
1. Google Sheets UI (custom menu entry)
2. Apps Script Runtime (serverless environment)
3. Script Functions:
– onOpen() → adds menu
– extractFromUrls() → fetch + parse + write to sheet
– extractFromCellText() → prompt + parse + show alert
4. External HTTP Service (web pages fetched via UrlFetchApp)
5. Regex Parser (within extract functions)
6. Spreadsheet Data (cells A and B)
b. Relationships and data flow:
1. User clicks menu → Apps Script Runtime triggers onOpen or extraction function.
2. extractFromUrls reads cell values via SpreadsheetApp, loops URLs → UrlFetchApp sends HTTP GETs → receives HTML responses → regex extracts email addresses → SpreadsheetApp writes results back.
3. extractFromCellText prompts user for a cell reference → reads that cell → regex extracts emails → shows results in an alert dialog.
c. Architectural patterns/design principles:
- Single responsibility: each function handles one workflow.
- Layered approach: UI layer (menu + prompts), service layer (UrlFetchApp), processing layer (regex), persistence layer (SpreadsheetApp).
d. Key technologies/frameworks/libraries:
- Google Apps Script Services: SpreadsheetApp, UrlFetchApp, Ui.
- JavaScript Regex for email extraction.

##### Detail
- Both workflows (URLs vs. cell text) in parallel branches.
- Triggers (onOpen event) that add the menu.
- Denote user interactions (menu click, prompt, alert).

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]:::ui
    User -->|clicks menu| Menu["Custom Menu\n(onOpen)"]:::ui
    subgraph "Apps Script Runtime"
        Menu --> extractUrls["extractFromUrls()"]:::process
        Menu --> extractCell["extractFromCellText()"]:::process

        extractUrls --> readURLs["SpreadsheetApp API\nread URLs"]:::data
        readURLs --> httpFetch["UrlFetchApp Service"]:::external
        httpFetch --> regexURL["Regex Parser"]:::process
        regexURL --> writeEmails["SpreadsheetApp API\nwrite emails"]:::data
        writeEmails --> sheetUI["Spreadsheet UI"]:::ui

        extractCell --> promptCell["Ui.prompt"]:::ui
        promptCell --> readCell["SpreadsheetApp API\nread cell"]:::data
        readCell --> regexCell["Regex Parser"]:::process
        regexCell --> alertUI["Ui.alert\nshow emails"]:::ui
    end
    ExternalHTTP["External HTTP Service"]:::external
    httpFetch -->|HTTP GET| ExternalHTTP

    Doc["Documentation\nREADME.md"]:::doc

    click Menu "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click extractUrls "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click extractCell "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click readURLs "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click writeEmails "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click promptCell "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click readCell "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click regexURL "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click regexCell "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click httpFetch "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/Email extrator code V3.gs"
    click Doc "https://github.com/nikhilsearch/google-sheet-email-extractor/blob/main/README.md"

    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef process fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef data fill:#90EE90,stroke:#333,stroke-width:1px
    classDef doc fill:#D3D3D3,stroke:#333,stroke-width:1px
```
