# salemove/glia-functions-tools architecture

> Architecture diagram of the GitHub repository salemove/glia-functions-tools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/salemove/glia-functions-tools
- Repository: https://github.com/salemove/glia-functions-tools

## Overview

1. This repository is a CLI and tooling suite for Glia Functions, a serverless functions platform built around the workerd JavaScript runtime. The codebase is centered on managing Glia-hosted functions, scaffolding projects, bundling code, and integrating with the Glia API.

2. The main runtime surface is the Node.js CLI. The primary executable is `bin/glia-functions.js`, with `src/index.js` and older root entrypoints kept for compatibility. The CLI can run in interactive mode or command mode, and it also exposes a separate MCP server mode for AI assistants.

3. CLI dispatch is layered: `src/cli` handles argument parsing, command routing, interactive prompts, and error handling; `src/commands` contains the actual command implementations. This separation is the main boundary between user interaction and business logic.

4. The command set is organized by domain:
   - function lifecycle: create, update, delete, list, invoke, deploy, fetch logs, update env vars
   - versions and deployment: create-and-deploy version, deploy project
   - profiles and site switching: create/list/update/switch/view/delete profiles
   - schedules: create/update/delete/list cron-based triggers
   - KV store operations
   - applet and project scaffolding
   - local dev server and request handling

5. Shared platform behavior lives in `src/lib` and `src/utils`. `src/lib/api.js` is the primary API boundary to Glia services, while adjacent modules add retry, caching, offline behavior, validation, and config handling. These libraries are used by most commands, so they form the core service layer beneath the CLI.

6. Authentication and environment state flow through config/profile management. The README’s `GLIA_KEY_ID`, `GLIA_KEY_SECRET`, `GLIA_SITE_ID`, and bearer token support are reflected in profile commands and config utilities. In practice, the CLI reads credentials and profile/site selection, derives an API context, then reuses that context across function and project operations.

7. Project scaffolding is template-driven. `src/templates` contains reusable project/function/applet templates, base package definitions, and template inheritance artifacts. `src/utils/template-*` and related managers/processors handle selecting a template, expanding variables, generating files, and validating the resulting project manifest.

8. The templates are not just boilerplate; they represent distinct project archetypes and deployment shapes. Examples include basic functions, API integrations, KV store functions, export handlers, and React-based applets. Some templates inherit from base templates, which means the architecture supports layered generation rather than one-off copies.

9. Local development and packaging are handled as a separate workflow from remote deployment. The repo includes esbuild configuration, a local dev command, request simulation helpers, and code validation utilities. The intended flow is: author function code, bundle it into an output file, test it locally against a simulated runtime, then create/deploy a version to Glia.

10. The MCP server is a distinct subsystem under `mcp-server/` and is also invokable from the CLI. It exposes Glia Functions operations over STDIO for AI assistants, acting as a protocol adapter over the same underlying API/command capabilities rather than a separate backend.

11. `examples/` contains standalone example projects and applets that demonstrate integration patterns such as AI, AWS Bedrock, HubSpot, SMS/IVR flows, S3 export, and Teams presence. These examples are consumer-facing reference implementations, not part of the CLI’s execution path, but they clarify how generated projects are expected to be structured.

12. There is a clear compatibility boundary between the modern `src/*` architecture and older legacy entrypoints/utilities. The README marks root-level `index.js`, `commands/`, and `utils/` as deprecated or removed in favor of `bin/` and `src/`, so an architecture diagram should show the modern path as primary and legacy paths as backward-compatibility only.

13. Supporting infrastructure includes Jest-based tests, GitHub Actions workflows, and documentation generation scripts. These do not affect runtime behavior, but they reinforce that the repository is a packaged developer toolchain with heavy emphasis on command correctness, template generation, and API integration.

Main entry points: [`src/commands/index.js`](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/index.js) (Commands index), [`src/utils/project-template-manager.js`](https://github.com/salemove/glia-functions-tools/blob/master/src/utils/project-template-manager.js) (Template manager), [`src/lib/api.js`](https://github.com/salemove/glia-functions-tools/blob/master/src/lib/api.js) (API client), [`src/lib/project-deployer.js`](https://github.com/salemove/glia-functions-tools/blob/master/src/lib/project-deployer.js) (Project deployer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_runtime["CLI runtime"]
  node_bin_glia_functions_js["CLI entry<br/>entrypoint<br/>[glia-functions.js]"]
  node_src_index_js["Main entry<br/>entrypoint<br/>[index.js]"]
  node_src_cli_index_js["CLI core<br/>dispatcher<br/>[index.js]"]
  node_src_cli_command_router_js["Router<br/>[command-router.js]"]
end

subgraph group_group_commands["Commands"]
  node_src_commands_index_js["Commands index<br/>command registry<br/>[index.js]"]
  node_src_commands_create_function_js["Create func<br/>function command<br/>[createFunction.js]"]
  node_src_commands_update_function_js["Update func<br/>function command<br/>[updateFunction.js]"]
  node_src_commands_invoke_function_js["Invoke func<br/>function command<br/>[invokeFunction.js]"]
  node_src_commands_profiles_index_js["Profiles<br/>account command group<br/>[index.js]"]
  node_src_commands_projects_deploy_project_js["Deploy project<br/>project command<br/>[deployProject.js]"]
  node_src_commands_applets_create_applet_js["Create applet<br/>applet command<br/>[createApplet.js]"]
  node_src_commands_schedules_index_js["Schedules<br/>schedule command group<br/>[index.js]"]
  node_src_commands_kv_store_base_js["KV store<br/>kv command group<br/>[base.js]"]
  node_src_commands_exports_setup_export_handler_js["Export handler<br/>export command"]
  node_src_commands_start_mcp_server_js["Start MCP<br/>mcp command<br/>[startMcpServer.js]"]
end

subgraph group_group_service["Service layer"]
  node_src_lib_api_js["API client<br/>service boundary<br/>[api.js]"]
  node_src_lib_config_js["Config<br/>[config.js]"]
  node_src_lib_project_deployer_js["Project deployer<br/>deployment service"]
  node_src_lib_project_validator_js["Validator<br/>validation service"]
end

subgraph group_group_templates["Templates"]
  node_src_utils_project_template_manager_js["Template manager<br/>generation service"]
  node_src_utils_template_engine_js["Template engine<br/>rendering engine<br/>[template-engine.js]"]
  node_src_templates_projects_basic_function["Basic function<br/>project template"]
  node_src_templates_applets_react_app["React applet<br/>applet template"]
end

subgraph group_group_adapters["Adapters"]
  node_mcp_server_server_js["MCP server<br/>protocol adapter<br/>[server.js]"]
  node_examples_readme["Examples<br/>reference projects<br/>[README.md]"]
  node_root_index_js["Legacy entry<br/>compatibility entrypoint<br/>[index.js]"]
end

node_bin_glia_functions_js -->|"boots"| node_src_index_js
node_src_index_js -->|"starts"| node_src_cli_index_js
node_src_cli_index_js -->|"routes"| node_src_cli_command_router_js
node_src_cli_command_router_js -->|"dispatches"| node_src_commands_index_js
node_src_commands_index_js -->|"includes"| node_src_commands_create_function_js
node_src_commands_index_js -->|"includes"| node_src_commands_update_function_js
node_src_commands_index_js -->|"includes"| node_src_commands_invoke_function_js
node_src_commands_index_js -->|"includes"| node_src_commands_profiles_index_js
node_src_commands_index_js -->|"includes"| node_src_commands_projects_deploy_project_js
node_src_commands_index_js -->|"includes"| node_src_commands_applets_create_applet_js
node_src_commands_index_js -->|"includes"| node_src_commands_schedules_index_js
node_src_commands_index_js -->|"includes"| node_src_commands_kv_store_base_js
node_src_commands_index_js -->|"includes"| node_src_commands_exports_setup_export_handler_js
node_src_commands_index_js -->|"includes"| node_src_commands_start_mcp_server_js
node_src_commands_create_function_js -->|"uses"| node_src_lib_config_js
node_src_commands_update_function_js -->|"calls"| node_src_lib_api_js
node_src_commands_invoke_function_js -->|"calls"| node_src_lib_api_js
node_src_commands_profiles_index_js -->|"writes"| node_src_lib_config_js
node_src_commands_projects_deploy_project_js -->|"orchestrates"| node_src_lib_project_deployer_js
node_src_lib_project_deployer_js -->|"checks"| node_src_lib_project_validator_js
node_src_lib_project_deployer_js -->|"publishes"| node_src_lib_api_js
node_src_commands_applets_create_applet_js -->|"scaffolds"| node_src_utils_project_template_manager_js
node_src_utils_project_template_manager_js -->|"renders"| node_src_utils_template_engine_js
node_src_utils_project_template_manager_js -->|"selects"| node_src_templates_projects_basic_function
node_src_utils_project_template_manager_js -->|"selects"| node_src_templates_applets_react_app
node_src_commands_start_mcp_server_js -->|"launches"| node_mcp_server_server_js
node_mcp_server_server_js -->|"adapts"| node_src_lib_api_js
node_examples_readme -.->|"demonstrates"| node_src_templates_projects_basic_function
node_root_index_js -.->|"compat"| node_src_index_js

click node_bin_glia_functions_js "https://github.com/salemove/glia-functions-tools/blob/master/bin/glia-functions.js"
click node_src_index_js "https://github.com/salemove/glia-functions-tools/blob/master/src/index.js"
click node_src_cli_index_js "https://github.com/salemove/glia-functions-tools/blob/master/src/cli/index.js"
click node_src_cli_command_router_js "https://github.com/salemove/glia-functions-tools/blob/master/src/cli/command-router.js"
click node_src_commands_index_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/index.js"
click node_src_commands_create_function_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/createFunction.js"
click node_src_commands_update_function_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/updateFunction.js"
click node_src_commands_invoke_function_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/invokeFunction.js"
click node_src_commands_profiles_index_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/profiles/index.js"
click node_src_commands_projects_deploy_project_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/projects/deployProject.js"
click node_src_commands_applets_create_applet_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/applets/createApplet.js"
click node_src_commands_schedules_index_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/schedules/index.js"
click node_src_commands_kv_store_base_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/kv-store/base.js"
click node_src_commands_exports_setup_export_handler_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/exports/setupExportHandler.js"
click node_src_commands_start_mcp_server_js "https://github.com/salemove/glia-functions-tools/blob/master/src/commands/startMcpServer.js"
click node_src_lib_api_js "https://github.com/salemove/glia-functions-tools/blob/master/src/lib/api.js"
click node_src_lib_config_js "https://github.com/salemove/glia-functions-tools/blob/master/src/lib/config.js"
click node_src_lib_project_deployer_js "https://github.com/salemove/glia-functions-tools/blob/master/src/lib/project-deployer.js"
click node_src_lib_project_validator_js "https://github.com/salemove/glia-functions-tools/blob/master/src/lib/project-validator.js"
click node_src_utils_project_template_manager_js "https://github.com/salemove/glia-functions-tools/blob/master/src/utils/project-template-manager.js"
click node_src_utils_template_engine_js "https://github.com/salemove/glia-functions-tools/blob/master/src/utils/template-engine.js"
click node_src_templates_projects_basic_function "https://github.com/salemove/glia-functions-tools/tree/master/src/templates/projects/basic-function"
click node_src_templates_applets_react_app "https://github.com/salemove/glia-functions-tools/tree/master/src/templates/applets/react-app"
click node_mcp_server_server_js "https://github.com/salemove/glia-functions-tools/blob/master/mcp-server/server.js"
click node_examples_readme "https://github.com/salemove/glia-functions-tools/blob/master/examples/README.md"
click node_root_index_js "https://github.com/salemove/glia-functions-tools/blob/master/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bin_glia_functions_js,node_src_index_js,node_src_cli_index_js,node_src_cli_command_router_js toneBlue
class node_src_commands_index_js,node_src_commands_create_function_js,node_src_commands_update_function_js,node_src_commands_invoke_function_js,node_src_commands_profiles_index_js,node_src_commands_projects_deploy_project_js,node_src_commands_applets_create_applet_js,node_src_commands_schedules_index_js,node_src_commands_kv_store_base_js,node_src_commands_exports_setup_export_handler_js,node_src_commands_start_mcp_server_js toneAmber
class node_src_lib_api_js,node_src_lib_config_js,node_src_lib_project_deployer_js,node_src_lib_project_validator_js toneMint
class node_src_utils_project_template_manager_js,node_src_utils_template_engine_js,node_src_templates_projects_basic_function,node_src_templates_applets_react_app toneRose
class node_mcp_server_server_js,node_examples_readme,node_root_index_js toneIndigo
```

## Components

### CLI runtime

Primary executable path, argument handling, and command dispatch.

- [CLI entry](https://github.com/salemove/glia-functions-tools/blob/master/bin/glia-functions.js): entrypoint · Primary executable for the Node.js CLI. · `bin/glia-functions.js`
- [Main entry](https://github.com/salemove/glia-functions-tools/blob/master/src/index.js): entrypoint · Modern package entrypoint with compatibility support. · `src/index.js`
- [CLI core](https://github.com/salemove/glia-functions-tools/blob/master/src/cli/index.js): dispatcher · Parses arguments, routes commands, and handles interactive flow. · `src/cli/index.js`
- [Router](https://github.com/salemove/glia-functions-tools/blob/master/src/cli/command-router.js): router · Dispatches parsed input to command implementations. · `src/cli/command-router.js`

### Commands

User-facing operations organized by domain.

- [Commands index](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/index.js): command registry · Exports the command surface for CLI wiring. · `src/commands/index.js`
- [Create func](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/createFunction.js): function command · Creates a new Glia function project or function artifact. · `src/commands/createFunction.js`
- [Update func](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/updateFunction.js): function command · Updates an existing function definition or code bundle. · `src/commands/updateFunction.js`
- [Invoke func](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/invokeFunction.js): function command · Runs a function through the Glia platform context. · `src/commands/invokeFunction.js`
- [Profiles](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/profiles/index.js): account command group · Manages credentials, site selection, and profile switching. · `src/commands/profiles/index.js`
- [Deploy project](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/projects/deployProject.js): project command · Deploys a local project as a Glia Functions project. · `src/commands/projects/deployProject.js`
- [Create applet](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/applets/createApplet.js): applet command · Scaffolds or creates an applet-based function project. · `src/commands/applets/createApplet.js`
- [Schedules](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/schedules/index.js): schedule command group · Creates, updates, lists, and deletes cron-triggered schedules. · `src/commands/schedules/index.js`
- [KV store](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/kv-store/base.js): kv command group · Base operations for key-value store commands. · `src/commands/kv-store/base.js`
- [Export handler](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/exports/setupExportHandler.js): export command · Wires up export handler scaffolding and setup flow. · `src/commands/exports/setupExportHandler.js`
- [Start MCP](https://github.com/salemove/glia-functions-tools/blob/master/src/commands/startMcpServer.js): mcp command · Launches the MCP server mode from the CLI. · `src/commands/startMcpServer.js`

### Service layer

Shared API, config, validation, cache, and deployment behavior.

- [API client](https://github.com/salemove/glia-functions-tools/blob/master/src/lib/api.js): service boundary · Primary boundary to Glia services and remote operations. · `src/lib/api.js`
- [Config](https://github.com/salemove/glia-functions-tools/blob/master/src/lib/config.js): auth/config · Resolves credentials, profile state, and API context. · `src/lib/config.js`
- [Project deployer](https://github.com/salemove/glia-functions-tools/blob/master/src/lib/project-deployer.js): deployment service · Coordinates project packaging and deployment steps. · `src/lib/project-deployer.js`
- [Validator](https://github.com/salemove/glia-functions-tools/blob/master/src/lib/project-validator.js): validation service · Validates project structure and manifests before deployment. · `src/lib/project-validator.js`

### Templates

Project and applet scaffolding assets plus template processing.

- [Template manager](https://github.com/salemove/glia-functions-tools/blob/master/src/utils/project-template-manager.js): generation service · Selects and expands project templates into files. · `src/utils/project-template-manager.js`
- [Template engine](https://github.com/salemove/glia-functions-tools/blob/master/src/utils/template-engine.js): rendering engine · Interpolates variables and materializes template output. · `src/utils/template-engine.js`
- [Basic function](https://github.com/salemove/glia-functions-tools/tree/master/src/templates/projects/basic-function): project template · Representative starter template for a plain function project. · `src/templates/projects/basic-function`
- [React applet](https://github.com/salemove/glia-functions-tools/tree/master/src/templates/applets/react-app): applet template · Representative applet archetype with React-based UI. · `src/templates/applets/react-app`

### Adapters

MCP server, examples, and compatibility entrypoints.

- [MCP server](https://github.com/salemove/glia-functions-tools/blob/master/mcp-server/server.js): protocol adapter · STDIO adapter exposing Glia Functions operations to assistants. · `mcp-server/server.js`
- [Examples](https://github.com/salemove/glia-functions-tools/blob/master/examples/README.md): reference projects · Standalone example implementations showing common integration patterns. · `examples/README.md`
- [Legacy entry](https://github.com/salemove/glia-functions-tools/blob/master/index.js): compatibility entrypoint · Deprecated root-level entrypoint kept for backward compatibility. · `index.js`

## Connections

- CLI entry → Main entry: boots · CLI executable loads the modern package entrypoint.
- Main entry → CLI core: starts · Entrypoint hands control to the CLI runtime.
- CLI core → Router: routes · CLI core delegates command selection and dispatch.
- Router → Commands index: dispatches · Router resolves requested commands from the registry.
- Commands index → Create func: includes · Command surface includes function creation.
- Commands index → Update func: includes · Command surface includes function updates.
- Commands index → Invoke func: includes · Command surface includes function invocation.
- Commands index → Profiles: includes · Command surface includes profile management.
- Commands index → Deploy project: includes · Command surface includes project deployment.
- Commands index → Create applet: includes · Command surface includes applet scaffolding.
- Commands index → Schedules: includes · Command surface includes schedule management.
- Commands index → KV store: includes · Command surface includes KV store operations.
- Commands index → Export handler: includes · Command surface includes export handler setup.
- Commands index → Start MCP: includes · Command surface includes MCP server mode.
- Create func → Config: uses · Function commands resolve credentials and site context.
- Update func → API client: calls · Function updates go through the Glia API boundary.
- Invoke func → API client: calls · Invocation uses platform API operations.
- Profiles → Config: writes · Profile commands manage local auth and site state.
- Deploy project → Project deployer: orchestrates · Project deployment command delegates to deployment logic.
- Project deployer → Validator: checks · Deployment validates the project before publishing.
- Project deployer → API client: publishes · Deployer sends packaged artifacts through the API.
- Create applet → Template manager: scaffolds · Applet creation pulls from template selection and expansion.
- Template manager → Template engine: renders · Template manager uses the rendering engine to expand files.
- Template manager → Basic function: selects · Project template manager can materialize starter project archetypes.
- Template manager → React applet: selects · Template manager can materialize applet archetypes.
- Start MCP → MCP server: launches · CLI command starts the dedicated MCP server process.
- MCP server → API client: adapts · MCP server exposes the same underlying Glia API capabilities.
- Examples → Basic function: demonstrates · Examples document expected project shapes and integrations.
- Legacy entry → Main entry: compat · Legacy entrypoint points to the modern entry path.
