# anagh070/gmail-to-calendar-automation architecture

> Architecture diagram of the GitHub repository anagh070/gmail-to-calendar-automation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anagh070/gmail-to-calendar-automation
- Repository: https://github.com/anagh070/gmail-to-calendar-automation

## Overview

##### Project type and purpose
- This is a Google Apps Script “automation tool” that runs inside the Google Cloud/Apps Script environment.
- It scans your Gmail inbox for natural‐language date/time mentions and then uses the Calendar API to create events automatically.

##### File structure
- Top level contains only two files:
- autoAddToCalendar.gs (the single Apps Script source)
- README.md (project description and usage)
- No external modules, no frontend, no database—pure server‐side script triggered on a schedule.

##### Extract architectural insights from the README
- Uses Gmail Service: scans emails from the last 3 days
- Parsing engine: a set of regex patterns in pure JavaScript
- Calendar Service: creates new events
- Trigger configuration: time-driven trigger (hourly or daily)

##### Main components
a. Google Apps Script Host
- The runtime environment where your script lives.
b. Time-Driven Trigger
- The scheduler that invokes `autoAddToCalendar()` on a set interval.
c. Gmail Service
- Reads threads, searches for date/time strings via regex.
d. Parsing Engine
- A pure-JavaScript module inside the script that applies multiple patterns.
e. Calendar Service
- Receives parsed date/time + metadata, creates events on the default calendar.
f. Label Manager
- Applies the “AutoScheduled” label to prevent reprocessing.

##### Relationships and interactions
- Trigger → Apps Script Host → `autoAddToCalendar()`
- Within function:
1. Call Gmail Service → fetch recent threads
2. Pass email bodies to Parsing Engine → extract date/time
3. Invoke Calendar Service → create event if valid
4. Invoke Gmail Service → apply “AutoScheduled” label

##### Architectural patterns and design principles
- Event-driven: uses time triggers instead of manual invocation
- Single responsibility: each step (scan, parse, write, label) is a distinct block inside the function
- Idempotency safeguards: skips duplicates and past events

##### Technologies & frameworks to annotate
- Google Apps Script (JavaScript runtime)
- Gmail Service (Apps Script API)
- Calendar Service (Apps Script API)
- No external libraries

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Components
    Trigger["Time-Driven Trigger"]:::trigger
    Host["Apps Script Host"]:::host

    subgraph "autoAddToCalendar()"
        GService["Gmail Service\nfetchThreads()/applyLabel()"]:::service
        Parser["Parsing Engine\nregex patterns"]:::internal
        CService["Calendar Service\ncreateEvent()"]:::service
        Label["Label Manager\napplyLabel()"]:::service
    end

    Doc["README.md\nProject Documentation"]:::doc

    %% Connections
    Trigger -->|"invokes"| Host
    Host -->|"autoAddToCalendar() starts"| GService
    GService -->|"email bodies"| Parser
    Parser -->|"parsed date/time"| CService
    CService -->|"event metadata"| Label
    Label -->|"tag threads"| GService
    Doc -.->|"instructions"| Trigger

    %% Click Events
    click Trigger "https://github.com/anagh070/gmail-to-calendar-automation/blob/main/autoAddToCalendar.gs"
    click GService "https://github.com/anagh070/gmail-to-calendar-automation/blob/main/autoAddToCalendar.gs"
    click Parser "https://github.com/anagh070/gmail-to-calendar-automation/blob/main/autoAddToCalendar.gs"
    click CService "https://github.com/anagh070/gmail-to-calendar-automation/blob/main/autoAddToCalendar.gs"
    click Label "https://github.com/anagh070/gmail-to-calendar-automation/blob/main/autoAddToCalendar.gs"
    click Doc "https://github.com/anagh070/gmail-to-calendar-automation/blob/main/README.md"

    %% Styles
    classDef trigger fill:#fff2cc,stroke:#e6b800,stroke-width:2px
    classDef host fill:#cfe2f3,stroke:#0b5394,stroke-width:2px
    classDef service fill:#d9ead3,stroke:#38761d,stroke-width:2px
    classDef internal fill:#f2f2f2,stroke:#7f7f7f,stroke-width:2px
    classDef doc fill:#f4cccc,stroke:#cc0000,stroke-width:2px
```
