# aziontech/lib architecture

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

- Interactive diagram: https://gitdiagram.com/aziontech/lib
- Repository: https://github.com/aziontech/lib

## Overview

##### Project type and purpose
- Project type: A monorepo‐style open-source toolkit (NPM packages) for interacting with the Azion Edge platform.
- Purpose: Provide libraries (Storage, SQL, Purge, Applications, Domains, Cookies, JWT, AI, etc.), a unified client façade, build/config presets, and utility modules—usable both inside the Azion Runtime (using internal hooks & polyfills) and outside via REST APIs.

##### File structure
- Root–level
– CI/CD config (.github/workflows, scripts/)
– Linting & formatting (.eslintrc, .prettierrc, commit hooks)
– tsup.config.json, tsconfig.json for build & TS settings
- packages/
– Core/Facade
- client: exposes createClient() → unifies all services
- config & types: shared configuration processor and TS types
– Service Packages
- storage, sql, purge, domains, applications, ai
– Each has src/services/api (REST wrappers) and src/services/runtime (Azion Runtime hooks)
– Utilities & Plugins
- cookies, jwt, router, utils
– Build & Bundling
- bundler: esbuild & webpack plugin architecture + polyfills for Azion runtime
- presets: preset definitions for frameworks (Next.js, React, Vue, etc.)
- unenv-preset & wasm-image-processor: runtime polyfills & asset processing

##### Key README insights
- Dual-mode operation: inside Azion Runtime (runtime hooks, polyfills) vs. outside (REST API calls).
- Unified client façade (createClient) on top of individual package functions.
- Config library: defineConfig → validates and composes build/domain/origin/cache/rules/purge/networkList/firewall/WAF.
- Preset/plugin pattern for framework-specific build and handler logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Consumer
    DevApp["Developer Application"]:::consumer

    %% Facade Layer
    Client["Azion Client Facade"]:::client

    %% Service Libraries
    subgraph "Service Libraries"
        Storage["Storage Service Package"]:::service
        SQL["SQL Service Package"]:::service
        Purge["Purge Service Package"]:::service
        Domains["Domains Service Package"]:::service
        Applications["Applications Service Package"]:::service
        AI["AI Service Package"]:::service
    end

    %% Shared Core
    subgraph "Shared Core"
        Config["Shared Config Processor"]:::core
        Types["Shared Type Definitions"]:::core
    end

    %% Utility Modules
    subgraph "Utility Modules"
        Cookies["Cookies Utility Module"]:::util
        JWT["JWT Utility Module"]:::util
        Router["Router Utility Module"]:::util
        Utils["General Utilities"]:::util
    end

    %% Build & Bundling
    subgraph "Build & Bundling"
        Bundler["Build System (Bundler & Polyfills)"]:::build
        Presets["Framework Presets"]:::build
        Unenv["Unenv Runtime Preset"]:::build
        Wasm["Wasm Image Processor Plugin"]:::build
    end

    %% External Systems
    subgraph "External Systems"
        AzionRuntime["Azion Runtime Environment"]:::external
        AzionREST["Azion REST API"]:::external
    end

    %% Relationships
    DevApp -->|"uses createClient()"| Client
    Client -->|routes calls| Storage
    Client -->|routes calls| SQL
    Client -->|routes calls| Purge
    Client -->|routes calls| Domains
    Client -->|routes calls| Applications
    Client -->|routes calls| AI

    Storage -->|imports| Config
    SQL -->|imports| Config
    Purge -->|imports| Config
    Domains -->|imports| Config
    Applications -->|imports| Config
    AI -->|imports| Config

    Storage -->|imports| Types
    SQL -->|imports| Types
    Purge -->|imports| Types
    Domains -->|imports| Types
    Applications -->|imports| Types
    AI -->|imports| Types

    Storage -->|"In-Runtime"| AzionRuntime
    SQL -->|"In-Runtime"| AzionRuntime
    Purge -->|"In-Runtime"| AzionRuntime
    Domains -->|"In-Runtime"| AzionRuntime
    Applications -->|"In-Runtime"| AzionRuntime
    AI -->|"In-Runtime"| AzionRuntime

    Storage -->|"Out-of-Runtime"| AzionREST
    SQL -->|"Out-of-Runtime"| AzionREST
    Purge -->|"Out-of-Runtime"| AzionREST
    Domains -->|"Out-of-Runtime"| AzionREST
    Applications -->|"Out-of-Runtime"| AzionREST
    AI -->|"Out-of-Runtime"| AzionREST

    Client -->|imports| Cookies
    Client -->|imports| JWT
    Client -->|imports| Router
    Client -->|imports| Utils

    Storage -->|imports| Cookies
    SQL -->|imports| Cookies
    Purge -->|imports| Cookies
    Domains -->|imports| Cookies
    Applications -->|imports| Cookies
    AI -->|imports| Cookies

    %% Build pipeline
    Config -->|feed build config| Bundler
    Bundler -->|uses presets| Presets
    Bundler -->|uses unenv preset| Unenv
    Bundler -->|uses plugin| Wasm
    Bundler -->|output bundle| AzionRuntime

    %% Click Events
    click Client "https://github.com/aziontech/lib/blob/main/packages/client/src/index.ts"
    click Storage "https://github.com/aziontech/lib/tree/main/packages/storage/src"
    click SQL "https://github.com/aziontech/lib/tree/main/packages/sql/src"
    click Purge "https://github.com/aziontech/lib/tree/main/packages/purge/src"
    click Domains "https://github.com/aziontech/lib/tree/main/packages/domains/src"
    click Applications "https://github.com/aziontech/lib/tree/main/packages/applications/src"
    click AI "https://github.com/aziontech/lib/tree/main/packages/ai/src"
    click Config "https://github.com/aziontech/lib/tree/main/packages/config/src"
    click Types "https://github.com/aziontech/lib/tree/main/packages/types/src"
    click Cookies "https://github.com/aziontech/lib/tree/main/packages/cookies/src"
    click JWT "https://github.com/aziontech/lib/tree/main/packages/jwt/src"
    click Router "https://github.com/aziontech/lib/tree/main/packages/router/src"
    click Utils "https://github.com/aziontech/lib/tree/main/packages/utils/src"
    click Bundler "https://github.com/aziontech/lib/tree/main/packages/bundler/src"
    click Presets "https://github.com/aziontech/lib/tree/main/packages/presets/src"
    click Unenv "https://github.com/aziontech/lib/tree/main/packages/unenv-preset/src"
    click Wasm "https://github.com/aziontech/lib/tree/main/packages/wasm-image-processor/src"

    %% Styles
    classDef consumer fill:#FFD700,stroke:#333,stroke-width:1px;
    classDef client fill:#1E90FF,stroke:#333,stroke-width:1px;
    classDef service fill:#32CD32,stroke:#333,stroke-width:1px;
    classDef core fill:#FF8C00,stroke:#333,stroke-width:1px;
    classDef util fill:#9370DB,stroke:#333,stroke-width:1px;
    classDef build fill:#20B2AA,stroke:#333,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
