> ## Documentation Index
> Fetch the complete documentation index at: https://docs.glue.wtf/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> Learn the basic nouns of Glue and how things fit together.

### What actually is a Glue?

A Glue is a single TypeScript file that can respond to external events and take actions. We run your Glue code using Deno both locally and in the cloud.

### The nouns

```mermaid theme={null}
flowchart TB
    n1 --> n3
    n3 --> C
    n3 --> D
    n3 --> n4
    C --> n5
    D --> n5
    n4 --> n6

    n1["Glue<br>(failedPaymentsToSlack.ts)"]
    n3["Deployments<br>(live version)"]
    C["Trigger<br>(onStripePaymentFailed)"]
    D["Trigger<br>(onStripeAccountPastDue)"]
    n4["CredentialFetcher<br>(slackCredentials)"]
    n5["Account<br>(stripe)"]
    n6["Account<br>(slack)"]
```

**Glues**: represents a single script you write that can respond to external events and take actions

**Deployments**: represents a deployed version of your Glue code. There is only ever one live deployment for a Glue.

**Triggers**: configuration for events you want to listen to for a particular external service. For example, if you want to listen for Stripe payment failures, you'll create a trigger for the `onStripePaymentFailed` event. Triggers are specified completely in your code as well as the handling code.

**CredentialFetchers**: give you credentials to an account you've authenticated with. This is typically used to when you use a client library that requires credentials. For example, if one of the actions you want to take when you is to send a slack message, you'll interact with Slack using the standard Slack client library which requires credentials.

**Accounts**: credentials Glue will store for services you use in your Glues. An account can be used by multiple Glues. It has a selector (email address, account id, etc.), optional scopes and the actual credentials. For OAuth based accounts, Glue will handle refreshing your access tokens.

**Executions**: represents a single run of your Glue. The input data and any logging your Glue does is stored for later viewing. If your Glue throws an error, the execution is considered Failed.

### How your Glue runs

```mermaid theme={null}
sequenceDiagram
    participant ExternalApplications as External Applications
    participant GlueService
    participant YourCode as Your Code
    participant You as You
    You->>YourCode: Deploy your glue
    YourCode->>GlueService: Registers triggers 
    GlueService->>You: Authenticate to external services
    GlueService->>ExternalApplications: Sets up webhooks
    ExternalApplications->>GlueService: Deliver webhooks
    GlueService->>GlueService: Record execution
    GlueService->>YourCode: Runs your event handlers
    GlueService->>GlueService: Store logs
```

Glue handles all the plumbing of setting up webhooks, delivering events, recording executions, logging data, versioning, and scaling compute to run your code. Your code is responsible for the business logic and that's it.

In order to do this, Glue acts as in intermediary between your code and the external services you want to interact with. You tell Glue what events you want to listen to and how you want to handle them. Glue will then set up webhooks for you and run your code when those events happen.
