Skip to content

Web Application Compositions

Higher-level compositions that wire together CNPG PostgreSQL, Valkey cache, Inngest workflow engine, and your application deployment. All connection strings are automatically injected as environment variables.

Import

typescript
import { webAppWithProcessing } from 'typekro/webapp';

webAppWithProcessing

Deploys a complete application stack with automatic wiring:

ComponentResourceWired env var
PostgreSQLCNPG Cluster + PgBouncer PoolerDATABASE_URL
CacheValkey clusterVALKEY_URL, REDIS_URL
Workflow engineInngest (external DB mode)INNGEST_BASE_URL, INNGEST_EVENT_KEY, INNGEST_SIGNING_KEY
ApplicationDeployment + Service

Quick Example

typescript
import { webAppWithProcessing } from 'typekro/webapp';

// 'kro' = continuous reconciliation, 'direct' = immediate apply
const factory = webAppWithProcessing.factory('kro', {
  namespace: 'production',
  waitForReady: true,
});

const instance = await factory.deploy({
  name: 'collectorbills',
  namespace: 'production',
  app: {
    image: 'collectorbills:latest',
    port: 5173,
    replicas: 2,
    env: {
      NODE_ENV: 'production',
      BETTER_AUTH_SECRET: 'your-secret',
    },
  },
  database: {
    instances: 3,
    storageSize: '50Gi',
    storageClass: 'gp3',
    database: 'collector_bills',
  },
  cache: {
    shards: 3,
    replicas: 1,
  },
  processing: {
    eventKey: 'your-hex-event-key',
    signingKey: 'your-hex-signing-key',
    sdkUrl: ['http://collectorbills:5173/api/inngest'],
  },
});

What gets deployed

Given name: 'collectorbills', the composition creates:

ResourceNameType
PostgreSQL clustercollectorbills-dbCNPG Cluster (3 instances)
Connection poolercollectorbills-db-poolerCNPG Pooler (PgBouncer, transaction mode)
Cachecollectorbills-cacheValkey cluster
Workflow enginecollectorbills-inngestInngest (HelmRelease, external DB)
ApplicationcollectorbillsDeployment + Service

Environment variables injected into the app

DATABASE_URL=postgresql://app@collectorbills-db-pooler:5432/collector_bills
VALKEY_URL=redis://collectorbills-cache:6379
REDIS_URL=redis://collectorbills-cache:6379
INNGEST_BASE_URL=http://collectorbills-inngest:8288
INNGEST_EVENT_KEY=<from config>
INNGEST_SIGNING_KEY=<from config>

User-provided app.env values are merged on top, so you can override any of these.

Status

typescript
instance.status.ready       // all components healthy
instance.status.databaseUrl // postgresql://app@...-db-pooler:5432/...
instance.status.cacheUrl    // redis://...-cache:6379
instance.status.inngestUrl  // http://...-inngest:8288
instance.status.appUrl      // http://...:5173

instance.status.components.app       // app deployment ready
instance.status.components.database  // CNPG cluster healthy
instance.status.components.cache     // Valkey ready
instance.status.components.inngest   // Inngest ready

Configuration

FieldRequiredDescription
nameYesApp name (prefix for all resources)
namespaceNoTarget namespace (default: 'default')
app.imageYesContainer image
app.portNoContainer port (default: 3000)
app.replicasNoReplica count (default: 1)
app.envNoExtra env vars (merged with auto-wired ones)
database.storageSizeYesPG storage (e.g., '50Gi')
database.instancesNoPG replicas (default: 1)
database.storageClassNoStorage class
database.databaseNoDatabase name (default: app name)
database.ownerNoDB owner (default: 'app')
cache.shardsNoValkey shards (default: 3)
cache.replicasNoReplicas per shard (default: 0)
processing.eventKeyYesInngest event key (hex string)
processing.signingKeyYesInngest signing key (hex string)
processing.sdkUrlNoApp SDK URLs for function sync
processing.replicasNoInngest server replicas (default: 1)

Prerequisites

The following operators must be installed before deploying:

  • CloudNativePG operator — cnpgBootstrap from typekro/cnpg
  • Valkey operator — valkeyBootstrap from typekro/valkey
  • Flux CD — for Inngest HelmRelease
typescript
import { cnpgBootstrap } from 'typekro/cnpg';
import { valkeyBootstrap } from 'typekro/valkey';

// Install operators first
await cnpgBootstrap.factory('direct', { ... }).deploy({ ... });
await valkeyBootstrap.factory('direct', { ... }).deploy({ ... });

// Then deploy the full stack
await webAppWithProcessing.factory('kro', { ... }).deploy({ ... });

Next Steps

Released under the Apache 2.0 License.