16 KiB
Attune Data Models Reference
This document describes the SQLAlchemy ORM models that define the Attune automation platform's database schema.
Overview
Attune is an event-driven automation and orchestration platform with built-in multi-tenancy, RBAC, and workflow capabilities. The data models are organized into several functional areas:
- Packaging & Distribution: Organization of automation components
- Runtime Environment: Execution environments and workers
- Event-Driven Architecture: Triggers, sensors, and events
- Actions & Automation: Executable operations and rules
- Execution & Orchestration: Action execution and workflow management
- User Interactions: Asynchronous user input and approvals in workflows
- Policy & Permissions: Access control and execution policies
- Identity & Access: User and service account management
- Configuration & Secrets: Secure key-value storage
- Notifications: Real-time event streaming
- Artifacts & Storage: Execution output management
Core Infrastructure
Base
Purpose: SQLAlchemy declarative base class for all models.
- Configured with "attune" schema metadata
- Parent class for all database models
Packaging & Distribution
Pack
Purpose: A package/bundle of automation components (sensors, actions, rules, policies, etc.).
Key Fields:
ref: Unique reference (e.g., "slack", "github")label: Human-readable nameversion: Semantic version string (validated)conf_schema: JSON schema for configurationconfig: Configuration valuesruntime_deps: List of required runtime referencesis_standard: Whether this is a core/built-in pack
Relationships:
- Contains: runtimes, triggers, sensors, actions, rules, permission_sets, policies
Purpose: Primary organizational unit for distributing and managing related automation components.
Runtime Environment
Runtime
Purpose: Defines a unified execution environment for actions and sensors.
Key Fields:
ref: Unique reference (format:pack.name, e.g.,core.python,core.shell)name: Runtime name (e.g., "Python", "Shell", "Node.js")distributions: JSON describing available distributions and verification metadatainstallation: JSON describing installation requirementsexecution_config: JSON describing how to execute code (interpreter, environment setup, dependencies). Runtimes without anexecution_config(e.g.,core.builtin) cannot execute actions — the worker skips them.pack: Parent pack ID
Relationships:
- Belongs to: pack
- Used by: workers, sensors, actions
Purpose: Defines how to install and execute code (Python, Node.js, containers, etc.). Runtimes are shared between actions and sensors — there is no type distinction.
WorkerType (Enum)
Values: local, remote, container
Purpose: Categorizes worker deployment types.
WorkerStatus (Enum)
Values: active, inactive, busy, error
Purpose: Tracks current operational state of workers.
Worker
Purpose: Represents a worker process/container that executes actions or monitors sensors.
Key Fields:
name: Worker identifierworker_type: Deployment typeruntime: Associated runtime IDhost,port: Connection details for remote workersstatus: Current operational statecapabilities: JSON describing worker capabilitieslast_heartbeat: Last health check timestamp
Relationships:
- Uses: runtime
Purpose: Manages the actual compute resources that run automation code.
Event-Driven Architecture
Trigger
Purpose: Defines an event type that can activate rules.
Key Fields:
ref: Unique reference (format:pack.name)label: Display nameenabled: Whether trigger is activeparam_schema: JSON schema for trigger parametersout_schema: JSON schema for trigger output/payloadpack: Parent pack ID
Relationships:
- Belongs to: pack
- Referenced by: sensors, rules, events
Examples: "webhook_received", "file_modified", "schedule_fired"
Sensor
Purpose: Monitors for trigger conditions and generates events.
Key Fields:
ref: Unique reference (format:pack.name)entrypoint: Code entry point (e.g., "sensors/webhook.py")runtime: Execution environmenttrigger: Associated triggerenabled: Whether sensor is activeparam_schema: JSON schema for configuration parameters
Relationships:
- Belongs to: pack
- Uses: runtime
- Monitors for: trigger
Purpose: Active monitoring component that detects when triggers fire and creates events.
Event
Purpose: An instance of a trigger firing.
Key Fields:
trigger: Trigger ID (with SET NULL on delete)trigger_ref: Trigger reference (preserved)config: Snapshot of trigger/sensor configuration at event timepayload: Event datasource: Sensor that generated the eventsource_ref: Source sensor reference
Relationships:
- Instance of: trigger
- Generated by: sensor
- Triggers: enforcements
Purpose: Records that a trigger occurred, including all context needed for rule evaluation.
Actions & Automation
Action
Purpose: An executable task/operation.
Key Fields:
ref: Unique reference (format:pack.name)label: Display nameentrypoint: Code entry point (e.g., "actions/send_email.py")runtime: Execution environmentparam_schema: JSON schema for input parametersout_schema: JSON schema for output/resultspack: Parent pack ID
Relationships:
- Belongs to: pack
- Uses: runtime
- Executed by: executions
- Used in: rules
Examples: "send_email", "create_ticket", "deploy_service"
Rule
Purpose: Connects triggers to actions with conditional logic.
Key Fields:
ref: Unique reference (format:pack.name)trigger: Trigger that activates this ruleaction: Action to execute when conditions are metconditions: JSON array of condition expressionsenabled: Whether rule is activepack: Parent pack ID
Relationships:
- Belongs to: pack
- When: trigger
- Then: action
- Creates: enforcements
Purpose: Automation logic that says "when trigger X fires, if conditions Y are met, execute action Z".
EnforcementStatus (Enum)
Values: created, processed, disabled
Purpose: Tracks processing state of rule enforcements.
EnforcementCondition (Enum)
Values: any, all
Purpose: Defines logical operator for multiple conditions (OR vs AND).
Enforcement
Purpose: An instance of a rule being triggered by an event.
Key Fields:
rule: Rule being enforcedrule_ref: Rule reference (preserved)trigger_ref: Trigger reference (preserved)event: Event that triggered this enforcementconfig: Snapshot of rule/trigger configurationstatus: Processing statepayload: Event payload for rule evaluationcondition: Logical operator (any/all)conditions: Condition expressions to evaluate
Relationships:
- Instance of: rule
- Triggered by: event
- Creates: executions
Purpose: Records that a rule was triggered and tracks whether it should execute its action.
Execution & Orchestration
ExecutionStatus (Enum)
Values: requested, scheduling, scheduled, running, completed, failed, canceling, cancelled, timeout, abandoned
Purpose: Tracks detailed lifecycle state of action executions.
Execution
Purpose: Represents a single action execution (can be part of a workflow).
Key Fields:
action: Action being executedaction_ref: Action reference (preserved)config: Snapshot of action configurationparent: Parent execution ID (for workflows)enforcement: Enforcement that triggered this executionexecutor: Identity that initiated executionstatus: Current execution stateresult: JSON output from the action
Relationships:
- Executes: action
- Triggered by: enforcement (if rule-driven) or executor (if manual)
- Parent/child: execution (for workflows)
- Executed by: identity
Purpose: Tracks individual action runs, supports nested workflows, and stores results.
InquiryStatus (Enum)
Values: pending, responded, timeout, cancelled
Purpose: Tracks lifecycle state of user inquiries in workflows.
Inquiry
Purpose: Represents an asynchronous user interaction within a workflow execution.
Key Fields:
execution: Execution that is waiting on this inquiryprompt: Question or prompt text for the userresponse_schema: JSON schema defining expected response formatassigned_to: Identity who should respond to this inquirystatus: Current state of the inquiryresponse: JSON response data from the usertimeout_at: When this inquiry expiresresponded_at: When the response was received
Relationships:
- Belongs to: execution
- Assigned to: identity
Purpose: Enables workflows to pause and wait for human input/approval. When an action needs user interaction (e.g., approval, additional information, decision-making), it creates an Inquiry. The workflow execution pauses until the inquiry is responded to, times out, or is cancelled. This allows for human-in-the-loop automation patterns.
Use Cases:
- Approval workflows (deploy approval, expense approval)
- Information gathering (incident details, configuration choices)
- Decision points (which path to take in a workflow)
- Manual verification steps
Policy & Permissions
PermissionGrant (TypedDict)
Purpose: Defines structure for permission grants.
Fields:
type:system,pack, oruserscope: Pack name for pack-scoped permissionscomponents: List of component references
Purpose: Structured permission definition for RBAC.
PermissionSet
Purpose: A named collection of permissions (like a role).
Key Fields:
ref: Unique reference (format:pack.name)label: Display namegrants: Array of permission grantspack: Parent pack (optional, for pack-defined roles)
Relationships:
- Belongs to: pack (optional)
- Assigned to: identities via permission_assignment
Purpose: Groups permissions together for assignment to users/services.
PermissionAssignment
Purpose: Links identities to permission sets (many-to-many).
Key Fields:
identity: Identity IDpermset: Permission set ID
Purpose: Grants permissions to users/services.
PolicyMethod (Enum)
Values: cancel, enqueue
Purpose: Defines how to handle policy violations.
Policy
Purpose: Defines execution policies for actions (rate limiting, concurrency control, etc.).
Key Fields:
ref: Unique reference (format:pack.name)action: Action this policy applies toparameters: List of parameter names used for policy groupingmethod: How to handle policy violationsthreshold: Numeric limit (e.g., max concurrent executions)pack: Parent pack
Relationships:
- Belongs to: pack
- Applies to: action
Examples: "Max 5 concurrent executions", "Rate limit to 100/hour"
Identity & Access
Identity
Purpose: Represents a user or service account.
Key Fields:
login: Unique login identifierdisplay_name: Human-readable nameattributes: JSON for custom attributes (email, groups, etc.)
Relationships:
- Has: permission_assignments
- Executes: executions
- Owns: keys
- Receives: inquiries (assigned tasks requiring response)
Purpose: User/service account management for authentication and authorization.
Configuration & Secrets
OwnerType (Enum)
Values: system, identity, pack, action, sensor
Purpose: Defines ownership scope for keys.
Key
Purpose: Stores configuration values and secrets with ownership scoping.
Key Fields:
ref: Unique reference (format:[owner.]name)owner_type: Type of ownerowner: Owner identifier (auto-populated)owner_identity,owner_pack,owner_action,owner_sensor: Foreign keys to ownersname: Key nameencrypted: Whether value is encryptedencryption_key_hash: Hash of encryption key usedvalue: The actual value (encrypted ifencrypted=true)
Constraints:
- Unique on: (owner_type, owner, name)
- Exactly one owner FK must be set (validated by trigger)
Purpose: Secure, scoped key-value storage for configuration and secrets.
Notifications
NotificationState (Enum)
Values: created, queued, processing, error
Purpose: Tracks notification delivery state.
Notification
Purpose: System notifications about entity changes.
Key Fields:
channel: Notification channel (typically table name)entity_type: Type of entity (table name)entity: Entity identifier (typically ID or ref)activity: Activity type (e.g., "created", "updated", "completed")state: Processing statecontent: JSON payload with notification details
Behavior:
- Automatically sends PostgreSQL
pg_notifyon insert - Used by triggers throughout the system to notify about changes
Purpose: Real-time event streaming for UI updates and system integration.
Artifacts & Storage
ArtifactType (Enum)
Values:
file_binary: Binary file for downloadfile_datatable: Tabular data for displayfile_image: Image for displayfile_text: Text file for displayurl: URL referenceprogress: Progress tracking dataother: Other types
Purpose: Categorizes artifact display/handling behavior.
RetentionPolicyType (Enum)
Values: versions, days, hours, minutes
Purpose: Defines retention policy type.
Artifact
Purpose: Manages execution output artifacts with retention policies.
Key Fields:
ref: Artifact reference/pathscope: Owner type (system, identity, pack, action, sensor)owner: Owner identifiertype: Artifact typeretention_policy: How to retain artifactsretention_limit: Numeric limit for retention
Purpose: Tracks files, logs, and other outputs from executions with automatic cleanup.
Database Functions & Triggers
The models file defines several PostgreSQL functions and triggers that provide:
- Auto-population: Automatically fill pack references, foreign keys, and refs
- Validation: Ensure referential integrity and format constraints
- Configuration Snapshots: Capture configuration at event/enforcement/execution creation time
- Notifications: Automatically create notification records on entity changes
- Ownership Validation: Enforce key ownership constraints
These ensure data consistency and provide audit trails throughout the system.
Common Patterns
Reference Format
All components use a ref field with format pack.name (e.g., slack.webhook_trigger, core.python, core.shell).
Ref vs ID
- Foreign key relationships use IDs
*_reffields store the string reference and are preserved even if the referenced entity is deleted- Triggers auto-populate IDs from refs and vice versa
Configuration Snapshots
Events, enforcements, and executions capture configuration snapshots in their config field to maintain execution context even if definitions change later.
Soft Cascades
Many foreign keys use SET NULL on delete and preserve *_ref fields, allowing historical tracking even after components are removed.
System Architecture Flow
- Pack Installation: Packs are installed, containing triggers, sensors, actions, rules, and policies
- Sensor Monitoring: Sensors watch for trigger conditions
- Event Generation: When a trigger fires, an event is created
- Rule Evaluation: Events trigger enforcements of matching rules
- Execution: Enforcements create executions of actions
- Worker Processing: Workers pick up and execute actions
- Human Interaction (optional): Actions can create inquiries to pause workflows and wait for user input
- Result Storage: Execution results and artifacts are stored
- Notifications: Changes flow through the notification system for real-time updates
This architecture supports both rule-driven automation and manual action execution, with full audit trails, workflow orchestration capabilities, and human-in-the-loop patterns via inquiries.