Skip to content

Overview

DieselEngine is a self-hosted backend platform built on Spring Boot and GraalVM. Scripts are ES modules (ECMAScript 2023+) executed by the GraalVM JavaScript engine, with direct access to PostgreSQL, Redis, S3 storage, email, outbound HTTP, and more.

What Can Scripts Do?

Scripts in DieselEngine can:

  • Serve HTTP requests — map URL routes to JavaScript handler functions
  • Handle WebSocket connections — build real-time features with rooms and broadcast
  • Run on a schedule — cron jobs with standard cron expressions
  • Execute at startup — initialization scripts that run once when the engine boots
  • Run on demand — triggered manually from the UI or via MCP tools
  • Access databases — full JDBC with prepared statements, JSONB, and PostgreSQL arrays
  • Connect to services — Redis, MinIO/S3, SMTP email, outbound HTTP
  • Spawn agent runs — kick off autonomous LLM-powered tasks from code
  • Interop with Java — call any Java class via Java.type()

Global Bindings

Every script execution receives these globals automatically:

BindingTypeDescription
dieselDieselEngineMain API: database, Redis, MinIO, email, PDF, crypto, file I/O
ResultsResultsProxyHTTP response builder (ingress handlers)
okHttpClientOkHttpClientOutbound HTTP client (OkHttp 4)
RequestBodyClassokhttp3.RequestBody for building HTTP request bodies
RequestBuilderClassokhttp3.Request.Builder for constructing HTTP requests
MediaTypeClassokhttp3.MediaType for MIME types
TimeUnitClassjava.util.concurrent.TimeUnit
SQLTypeClassjava.sql.SQLType for null parameter types
RedisClientClassLettuce RedisClient (available in ingress handlers)

Your First Script

Here is a minimal HTTP ingress handler that returns JSON:

javascript
export function handleRequest(context) {
  return Results.json().renderRaw(JSON.stringify({
    message: "Hello from DieselEngine!",
    timestamp: Date.now()
  }));
}

To make this accessible at GET /api/hello, create an ingress rule mapping the route to this script. This can be done through the UI or via the MCP ingress_create tool.

Execution Modes at a Glance

ModeTriggerEntry Point
HTTP ingressHTTP request matches a routeexport function handleRequest(context) { ... }
WebSocketClient connects to a WS routeexport function onOpen/onMessage/onClose(session) { ... }
On-demandUser or agent triggers a runTop-level module code
Cron jobSchedule firesTop-level module code
StartupEngine bootsTop-level module code

TIP

All execution modes share the same diesel API and global bindings. The only difference is how the script is triggered and what entry point it uses.

Console Output

console.log(), console.error(), and print() output appears in the DieselEngine UI console in real time. Script exceptions are also displayed with file and line information.

What's Next?

DieselEngine Scripting Documentation