# Your First Kernel URL: /docs/getting-started/your-first-kernel Your First Kernel [#your-first-kernel] Build a parametric box with rounded edges using the Replicad kernel. You will learn how to set up a runtime client, write parametric CAD code, render geometry, and export to STEP format. What You'll Learn [#what-youll-learn] * How to configure a runtime client with [`createRuntimeClient`](../api/client) * How to write parametric CAD models that accept user parameters * How to render models and inspect the result * How to export models to STEP format for professional CAD workflows Prerequisites [#prerequisites] * [Install @taucad/runtime](./installation) * Completed the [Quick Start](./quick-start) Step 1: Set Up the Client [#step-1-set-up-the-client] Create a runtime client with the Replicad kernel, esbuild bundler, and an in-memory filesystem: ```typescript import { createRuntimeClient, fromMemoryFS } from '@taucad/runtime'; import { replicad } from '@taucad/runtime/kernels'; import { esbuild } from '@taucad/runtime/bundler'; const client = createRuntimeClient({ kernels: [replicad()], bundlers: [esbuild()], fileSystem: fromMemoryFS(), }); client.on('log', ({ message }) => console.log('[kernel]', message)); ``` The `createRuntimeClient` function creates a high-level client that manages worker lifecycle, kernel selection, and middleware. The `fromMemoryFS()` function provides an in-memory filesystem for passing code to the kernel without touching disk. **Verify:** No output yet. The client initializes lazily -- the worker is only created when you call `render()` or `connect()`. Step 2: Write a Parametric Model [#step-2-write-a-parametric-model] Define a CAD model that creates a box with configurable dimensions and fillet radius. Parameters make your model flexible -- users can adjust dimensions without editing code. ```typescript const modelCode = ` import { drawRoundedRectangle } from 'replicad'; const defaultParams = { width: 30, height: 20, depth: 10, fillet: 3, }; export default function main(params = defaultParams) { const { width, height, depth, fillet } = params; return drawRoundedRectangle(width, height, fillet) .sketchOnPlane('XY') .extrude(depth); } `; ``` The `main` function is the entry point that the kernel calls. It receives a `params` object whose shape is inferred from `defaultParams`. The kernel extracts these parameters automatically and provides a JSON Schema for UI generation. **Verify:** This step assigns a string -- no execution yet. Confirm that `modelCode` is a valid string with no syntax errors. Step 3: Render the Model [#step-3-render-the-model] Pass the code and optional parameter overrides to `client.render()`: ```typescript @ts-nocheck const result = await client.render({ code: { 'main.ts': modelCode }, parameters: { width: 50, depth: 15 }, }); if (result.success) { console.log(`Rendered ${result.data.length} geometries`); } else { for (const issue of result.issues) { console.error(`[${issue.severity}] ${issue.message}`); } } ``` The `success` field is the discriminant -- TypeScript narrows the result type so you can safely access `result.data` in the `true` branch. If rendering fails, the `issues` array contains structured errors with messages, locations, and severity levels. **Verify:** You should see `Rendered 1 geometries` in the console. If you see errors instead, check that your model code has correct Replicad imports and a default-exported `main` function. Step 4: Export to STEP [#step-4-export-to-step] Export the rendered geometry to STEP format for use in professional CAD tools: ```typescript @ts-nocheck const exportResult = await client.export('step'); if (exportResult.success) { const { name, bytes, mimeType } = exportResult.data; console.log(`Exported: ${name} (${bytes.byteLength} bytes, ${mimeType})`); } else { console.error('Export failed:', exportResult.issues); } ``` You can also export directly from code without a separate `render()` call: ```typescript @ts-nocheck const result = await client.export('step', { code: { 'main.ts': modelCode }, parameters: { width: 50, depth: 15 }, }); ``` STEP export is available for the Replicad and OpenCASCADE kernels. Other kernels support different export formats -- see [Choose a Kernel](../guides/choosing-a-kernel) for a comparison. **Verify:** You should see output like `Exported: main.step (12345 bytes, model/step)`. The byte count varies with model complexity. Step 5: Clean Up [#step-5-clean-up] Terminate the client to shut down workers and release resources: ```typescript @ts-nocheck client.terminate(); ``` **Verify:** The process should exit cleanly. If it hangs, `terminate()` was not called or a listener is keeping the event loop alive. Recap [#recap] You built a parametric 3D model using the Replicad kernel: 1. Created a [`RuntimeClient`](../api/client) with `createRuntimeClient` 2. Wrote a parametric model with configurable dimensions 3. Rendered it to glTF with parameter overrides 4. Exported the result to STEP format 5. Used `result.success` to handle success and error cases Next Steps [#next-steps] * [Use Middleware](../guides/using-middleware) -- Add caching and post-processing to your pipeline * [Set Up the Filesystem](../guides/filesystem-setup) -- Use Node.js or browser filesystems instead of in-memory * [Architecture](../concepts/architecture) -- Understand how client, transport, worker, and kernel layers interact * [API Reference: Client](../api/client) -- Complete documentation for `RuntimeClient` methods