# heartstchr/notion-p architecture

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

- Interactive diagram: https://gitdiagram.com/heartstchr/notion-p
- Repository: https://github.com/heartstchr/notion-p

## Overview

##### Project type and purpose
- This is a full-stack, serverless web application (“Notion-P”) for handling customer service requests.
- It uses a static frontend (HTML/JS/CSS) hosted on Netlify, several Netlify Functions as the backend, Notion as the database, Netlify Blobs for file storage, and Gmail SMTP for email notifications.

##### File structure
- Top-level files:
- package.json / package-lock.json – project metadata and dependencies
- netlify.toml – deploy/build settings for Netlify
- env.example – shows required environment variables
- public/index.html – single-page form UI
- Netlify Functions (serverless “microservices”):
- check-status-changes.js – cron-style status watcher
- get-issue-types.js – fetches dropdown options from Notion
- serve-blob.js / upload-image.js – handles file upload via Netlify Blobs
- submit-to-notion.js – writes new requests into Notion
- email-templates.js, email-utils.js, config.js – SMTP setup and templating
- “Step-by-Step Guide” folder contains documentation, not part of runtime.

##### Key architectural insights from README
- Workflow:
1. Customer → fills form on the static site
2. Browser → invokes serverless functions to upload images, fetch issue types, and submit form data
3. Netlify Blob service → stores files
4. Notion API → persists request records
5. Cron-style function → polls Notion every 2 minutes for status changes
6. SMTP (Gmail) → sends update emails
- All sensitive credentials (Notion API key, DB ID, SMTP user/pass) are injected as Netlify environment variables.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["User's Browser"]:::frontend
        StaticSite["Static Site (public/index.html)"]:::frontend
    end

    %% Configuration Files
    subgraph "Configuration"
        NetlifyConfig["Netlify Config (netlify.toml)"]:::config
        EnvExample["Env Variables Example (env.example)"]:::config
        BlobInit["Blob Initialization (enable-blobs.js)"]:::config
        Doc["Documentation (Step-by-Step Guide/)"]:::docs
    end

    %% Serverless Functions
    subgraph "Netlify Functions" 
        direction TB
        submit["Netlify Function: submit-to-notion"]:::functions
        getTypes["Netlify Function: get-issue-types"]:::functions
        upload["Netlify Function: upload-image"]:::functions
        serveBlob["Netlify Function: serve-blob"]:::functions
        checkStatus["Netlify Function: check-status-changes"]:::functions
        configFn["Shared Config (config.js)"]:::functions
        templates["Email Templates (email-templates.js)"]:::functions
        emailUtils["SMTP Utils (email-utils.js)"]:::functions
    end

    %% External Services
    subgraph "External Services"
        direction TB
        blobService["Netlify Blobs"]:::external
        notion["Notion API & Database"]:::external
        smtp["Gmail SMTP"]:::external
    end

    %% Flows
    Browser -->|"HTTP GET"| StaticSite
    StaticSite -->|"Served via CDN"| Browser

    Browser -->|"AJAX POST: upload-image"| upload
    upload -->|"Store file"| blobService
    blobService -->|"Return URL"| upload
    upload -->|"Return URL"| Browser

    Browser -->|"AJAX POST: submit-to-notion"| submit
    submit -->|"Write record"| notion
    notion -->|"Response"| submit
    submit -->|"Response"| Browser

    Browser -->|"AJAX GET: get-issue-types"| getTypes
    getTypes -->|"Query DB"| notion
    notion -->|"Return types"| getTypes
    getTypes -->|"Return options"| Browser

    checkStatus -. scheduled trigger .-> checkStatus
    checkStatus -->|"Poll DB"| notion
    notion -->|"Data"| checkStatus
    checkStatus -->|"Use Templates"| templates
    templates -->|"Use Utils"| emailUtils
    emailUtils -->|"Send Email"| smtp

    %% Shared config usage
    submit --> configFn
    getTypes --> configFn
    upload --> configFn
    serveBlob --> configFn
    checkStatus --> configFn
    templates --> configFn
    emailUtils --> configFn

    %% Click Events
    click StaticSite "https://github.com/heartstchr/notion-p/blob/main/public/index.html"
    click NetlifyConfig "https://github.com/heartstchr/notion-p/blob/main/netlify.toml"
    click EnvExample "https://github.com/heartstchr/notion-p/blob/main/env.example"
    click BlobInit "https://github.com/heartstchr/notion-p/blob/main/enable-blobs.js"
    click submit "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/submit-to-notion.js"
    click getTypes "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/get-issue-types.js"
    click upload "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/upload-image.js"
    click serveBlob "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/serve-blob.js"
    click checkStatus "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/check-status-changes.js"
    click templates "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/email-templates.js"
    click emailUtils "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/email-utils.js"
    click configFn "https://github.com/heartstchr/notion-p/blob/main/netlify/functions/config.js"
    click Doc "https://github.com/heartstchr/notion-p/tree/main/Step-by-Step Guide/"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef functions fill:#DFF7D8,stroke:#1A7F37,color:#1A7F37;
    classDef external fill:#FFE6C2,stroke:#D97706,color:#C2410C;
    classDef config fill:#F0F0F0,stroke:#666666,color:#333333;
    classDef docs fill:#F8E9FF,stroke:#9C27B0,color:#6A1B9A;
```
