TypeScript modules
A Kyku module is a TypeScript function that returns BaseResource[]. It does not call plan or apply. The config file (infrastructure.ts) is the only place that exports { provider, resources }.
This is a convention, not a registry. There is no kyku init --from and no codegen.
Factory
Section titled “Factory”Install the types package and return resource objects. Use object references for dependencies (not string IDs):
import { type BaseResource, SecurityGroup, Vm, Vpc } from '@kykucloud/types'
export function webStack(opts: { prefix: string cidr: string region: string sshSources: string[]}): BaseResource[] { const vpc = new Vpc({ id: `${opts.prefix}-vpc`, name: `${opts.prefix}-vpc`, cidr: opts.cidr, region: opts.region, distributeAcrossAzs: 1, })
const sg = new SecurityGroup({ id: `${opts.prefix}-sg`, name: `${opts.prefix}-sg`, vpc, // object ref → SecurityGroup depends on Vpc ingress: [ { protocol: 'tcp', fromPort: 22, toPort: 22, sources: opts.sshSources }, ], })
const vm = new Vm({ id: `${opts.prefix}-vm`, name: `${opts.prefix}-web`, instanceType: 'small', image: 'ubuntu-22.04', network: vpc, securityGroups: [sg], })
return [vpc, sg, vm]}From an npm install the import path is @kykucloud/types — the same path this repo uses.
Compose in infrastructure.ts
Section titled “Compose in infrastructure.ts”import { webStack } from './modules/web-stack'
export default { provider: 'hetzner', resources: [ ...webStack({ prefix: 'app', cidr: '10.0.0.0/16', region: 'eu-central', sshSources: ['203.0.113.10/32'], }), ],}kyku graph walks the composed array. Object refs show up as edges (app-vm depends on app-vpc and app-sg).
See examples/modules/web-stack.ts and examples/composed.ts in the repo.
- Factories are pure: construct objects, return them. No
engine.apply(), no network, no writing.kyku/. - Give every resource a stable
id. Colliding IDs across modules will fail validation. - Spread multiple factories into
resourcesto compose stacks. - String IDs (
network: 'app-vpc') do not create graph edges.