# akahoshi1421/gassma architecture

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

- Interactive diagram: https://gitdiagram.com/akahoshi1421/gassma
- Repository: https://github.com/akahoshi1421/gassma

## Overview

##### Project type and purpose
- GASsma is an open-source TypeScript library that provides a Prisma-like ORM API for Google Sheets via Google Apps Script (GAS).
- Its primary goal is to let developers perform CRUD, filtering, aggregation, grouping, and other operations on spreadsheet data using a fluent, type-safe client.

##### File structure
- Top-level build and config:
- webpack.config.js, tsconfig.json, .clasp.json (GAS deployment), package.json, jest.config.ts
- Source code under src/:
- src/gassma.ts: entry-point exposing GassmaClient
- src/gassmaController.ts: orchestrates method calls and error handling
- src/util: modules for each operation (find, create, update, delete, count, aggregate, groupBy, changeSettings, filterConditions, andOrNot, etc.)
- src/errors: custom error classes per operation
- src/types: TypeScript type definitions for all public APIs
- Tests under src/__test__: validate each utility’s logic
- Build output in dist/: compiled JS and GAS manifest (appsscript.json)

##### Key points from README
- Shows how a user instantiates new GassmaClient and calls methods in either Clasp-driven TS code or directly in GAS script editor.
- Mentions the library is distributed via npm and linked into GAS via its Script ID.

1. Build & Distribution Layer
- TypeScript source
- Webpack/tsc compiler
- npm package registry
2. Client Application / GAS Runtime
- User’s Clasp project or GAS script editor
3. GassmaClient (public API)
4. GassmaController (core orchestrator)
5. Utility Modules (business logic)
- find, create, update, delete, count, aggregate, groupBy, changeSettings, filterConditions, andOrNot, etc.
6. Error Modules (operation-specific errors)
7. Type Definitions (compile-time contracts)
8. Google Apps Script Services
- SpreadsheetApp (GAS API)

1. Build & Distribution → npm registry → User’s project
2. User calls → GassmaClient methods
3. GassmaClient forwards → GassmaController
4. GassmaController invokes → appropriate util module (e.g., findMany → util/find/findMany.ts)
5. Util module uses → GAS SpreadsheetApp API to fetch/update raw sheet data
6. Raw data flows back → util module transforms → GassmaController
7. GassmaController applies → error handling (errors/*)
8. Final data returned → GassmaClient → User’s code

c. Architectural patterns & principles
- Layered architecture: public client → controller → utilities → external service
- Separation of concerns: each util module handles one CRUD or aggregation concern
- Error-first design: custom error classes per feature
- Type safety: TypeScript types in types/ enforce schema at compile time
- Modular design: small, testable units, validated by jest tests

d. Key technologies & frameworks
- TypeScript (tsc, type definitions)
- Webpack (bundling for GAS deployment)
- Google Apps Script (SpreadsheetApp service)
- Jest (unit tests)
- npm (package management)
- Clasp (GAS deployment)

##### Final recommendations
- TypeScript → JavaScript compile step feeding into dist/.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & Distribution Layer
    subgraph "Build & Distribution Layer"
        direction TB
        WebpackConf["webpack.config.js"]:::build
        TSConfig["tsconfig.json"]:::build
        ClaspConfig[".clasp.json"]:::build
        PackageJSON["package.json"]:::build
        distDir["dist/"]:::build
        WebpackConf --> TSConfig --> ClaspConfig --> PackageJSON --> distDir
    end
    Registry[(NPM Registry)]:::build
    distDir -->|"publish"| Registry
    Registry -->|"install"| User["User's Project (Clasp/GAS)"]:::runtime

    %% Public API and Controller
    User -->|"calls"| Client["GassmaClient"]:::api
    Client -->|"forwards"| Controller["GassmaController"]:::api

    %% Utility Modules
    subgraph "Utility Modules"
        direction TB
        F1["findMany"] 
        F2["findFirst"] 
        FUtil["findUtil"] 
        C1["create"] 
        C2["createManyFunc"]
        U1["updateMany"]
        D1["deleteMany"]
        CNT["count"]
        AGG["aggregate"]
        AGGUtil["aggregateUtil"]
        GB["groupBy"]
        GBUtil["groupByUtil"]
        CS["changeSettings"]
        CSUtil["changeSettingsUtil"]
        FC["filterConditions"]
        AND["and"] 
        OR["or"] 
        NOT["not"] 
        UPS["upsertMany"]
        ISD["isDict"]
    end
    Controller -->|"invokes"| F1
    Controller -->|"invokes"| F2
    Controller -->|"invokes"| FUtil
    Controller -->|"invokes"| C1
    Controller -->|"invokes"| C2
    Controller -->|"invokes"| U1
    Controller -->|"invokes"| D1
    Controller -->|"invokes"| CNT
    Controller -->|"invokes"| AGG
    Controller -->|"invokes"| AGGUtil
    Controller -->|"invokes"| GB
    Controller -->|"invokes"| GBUtil
    Controller -->|"invokes"| CS
    Controller -->|"invokes"| CSUtil
    Controller -->|"invokes"| FC
    Controller -->|"invokes"| AND
    Controller -->|"invokes"| OR
    Controller -->|"invokes"| NOT
    Controller -->|"invokes"| UPS
    Controller -->|"invokes"| ISD

    %% Error Modules
    subgraph "Error Modules"
        direction TB
        AE["aggregateError"] 
        CSE["changeSettingsError"] 
        GBE["groupByError"]
    end
    Controller -->|"error handling"| AE
    Controller -->|"error handling"| CSE
    Controller -->|"error handling"| GBE

    %% Type Definitions
    subgraph "Type Definitions"
        direction TB
        Types["src/types/*.ts"]
        IndexD["src/index.d.ts"]
    end
    Client -->|"uses"| Types

    %% External Service
    subgraph "External GAS Services"
        direction TB
        SP[(SpreadsheetApp)]:::external
    end
    F1 -->|"calls"| SP
    F2 -->|"calls"| SP
    FUtil -->|"calls"| SP
    C1 -->|"calls"| SP
    C2 -->|"calls"| SP
    U1 -->|"calls"| SP
    D1 -->|"calls"| SP
    CNT -->|"calls"| SP
    AGG -->|"calls"| SP
    GB -->|"calls"| SP
    CS -->|"calls"| SP
    FC -->|"calls"| SP
    AND -->|"calls"| SP
    OR -->|"calls"| SP
    NOT -->|"calls"| SP
    UPS -->|"calls"| SP
    ISD -->|"calls"| SP
    SP -->|"data"| F1

    %% Returned Data Flow
    F1 -->|"returns"| Controller
    Controller -->|"returns"| Client
    Client -->|"returns"| User

    %% Click Events
    click WebpackConf "https://github.com/akahoshi1421/gassma/blob/main/webpack.config.js"
    click TSConfig "https://github.com/akahoshi1421/gassma/blob/main/tsconfig.json"
    click ClaspConfig "https://github.com/akahoshi1421/gassma/blob/main/.clasp.json"
    click PackageJSON "https://github.com/akahoshi1421/gassma/blob/main/package.json"
    click distDir "https://github.com/akahoshi1421/gassma/tree/main/dist/"
    click Client "https://github.com/akahoshi1421/gassma/blob/main/src/gassma.ts"
    click Controller "https://github.com/akahoshi1421/gassma/blob/main/src/gassmaController.ts"
    click F1 "https://github.com/akahoshi1421/gassma/blob/main/src/util/find/findMany.ts"
    click F2 "https://github.com/akahoshi1421/gassma/blob/main/src/util/find/findFirst.ts"
    click FUtil "https://github.com/akahoshi1421/gassma/tree/main/src/util/find/findUtil/"
    click C1 "https://github.com/akahoshi1421/gassma/blob/main/src/util/create/create.ts"
    click C2 "https://github.com/akahoshi1421/gassma/blob/main/src/util/create/createManyFunc.ts"
    click U1 "https://github.com/akahoshi1421/gassma/blob/main/src/util/update/updateMany.ts"
    click D1 "https://github.com/akahoshi1421/gassma/blob/main/src/util/delete/deleteMany.ts"
    click CNT "https://github.com/akahoshi1421/gassma/blob/main/src/util/count/count.ts"
    click AGG "https://github.com/akahoshi1421/gassma/blob/main/src/util/aggregate/aggregate.ts"
    click AGGUtil "https://github.com/akahoshi1421/gassma/tree/main/src/util/aggregate/aggregateUtil/"
    click GB "https://github.com/akahoshi1421/gassma/blob/main/src/util/groupby/groupby.ts"
    click GBUtil "https://github.com/akahoshi1421/gassma/tree/main/src/util/groupby/groubyUtil/"
    click CS "https://github.com/akahoshi1421/gassma/blob/main/src/util/changeSettings/changeSettings.ts"
    click CSUtil "https://github.com/akahoshi1421/gassma/tree/main/src/util/changeSettings/changeSettingsUtil/"
    click FC "https://github.com/akahoshi1421/gassma/blob/main/src/util/filterConditions/filterConditions.ts"
    click AND "https://github.com/akahoshi1421/gassma/blob/main/src/util/andOrNot/and.ts"
    click OR "https://github.com/akahoshi1421/gassma/blob/main/src/util/andOrNot/or.ts"
    click NOT "https://github.com/akahoshi1421/gassma/blob/main/src/util/andOrNot/not.ts"
    click UPS "https://github.com/akahoshi1421/gassma/blob/main/src/util/upsert/upsertMany.ts"
    click ISD "https://github.com/akahoshi1421/gassma/blob/main/src/util/other/isDict.ts"
    click AE "https://github.com/akahoshi1421/gassma/blob/main/src/errors/aggregate/aggregateError.ts"
    click CSE "https://github.com/akahoshi1421/gassma/blob/main/src/errors/changeSettings/changeSettingsError.ts"
    click GBE "https://github.com/akahoshi1421/gassma/blob/main/src/errors/groupBy/groupByError.ts"
    click Types "https://github.com/akahoshi1421/gassma/blob/main/src/types/*.ts"
    click IndexD "https://github.com/akahoshi1421/gassma/blob/main/src/index.d.ts"

    %% Styles
    classDef build fill:#BBBBBB,stroke:#888888,color:#000000
    classDef api fill:#ADD8E6,stroke:#5DADE2,color:#000000
    classDef util fill:#90EE90,stroke:#28B463,color:#000000
    classDef error fill:#F08080,stroke:#C0392B,color:#000000
    classDef types fill:#D3D3D3,stroke:#A6ACAF,color:#000000
    classDef external fill:#FFA500,stroke:#D35400,color:#000000
    classDef runtime fill:#E0FFFF,stroke:#48C9B0,color:#000000
```
