/vovk:segmentfrom vovk
Explains Vovk.ts segments — backend slices with their own API path prefix, controllers, and Next.js route handler. Covers initSegment, catch-all routes, per-segment runtime settings, static APIs, and the vovk new segment CLI.
Ships in vovk. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A segment is a backend slice. Owns API path prefix (/api, /api/admin, /api/openapi, etc.), set of controllers, own Next.js route-handler file. Each segment compiles to independent serverless function, so runtime settings (runtime, maxDuration, etc.) can differ per segment.
Think: "one segment = one mini-backend."
Every segment is Next.js App Router optional catch-all route handler:
src/app/api/[[...vovk]]/route.ts ← root segment (path: /api/*)
src/app/api/foo/[[...vovk]]/route.ts ← "foo" segment (path: /api/foo/*)
src/app/api/foo/bar/[[...vovk]]/route.ts ← "foo/bar" segment (path: /api/foo/bar/*)
Slug name (vovk) can be any name: the CLI takes any [[...name]] folder that has a route.ts. Stick with vovk (what vovk new segment writes) unless user has reason to change it. rootEntry is something else: the API root folder (api).
initSegment()Every segment's route.ts exports HTTP handlers produced by initSegment():
// src/app/api/[[...vovk]]/route.ts
import { initSegment } from 'vovk';
import UserController from '../../../modules/user/user-controller';
import PostController from '../../../modules/post/post-controller';
export const maxDuration = 300; // Next.js route-handler option
const controllers = {
UserRPC: UserController,
PostRPC: PostController,
};
export type Controllers = typeof controllers;
export const { GET, POST, PATCH, PUT, HEAD, OPTIONS, DELETE } = initSegment({
controllers,
});
Keys of controllers (UserRPC, PostRPC) are client-side module names — generated client will expose UserRPC.getUser(...), etc.
initSegment parameters:
| Param | Required | Default | Purpose |
|---|---|---|---|
controllers | yes | — | Map of RPCModuleName → ControllerClass. |
segmentName | no | "" (root) | Identifier; must mirror folder path for named segments (e.g., "foo/bar"). |
emitSchema | no | true | Emit schema for codegen. Leave on unless you know why. |
exposeValidation | no | true | Expose validation data to client. Leave on for client-side validation. |
onError | no | — | (err: Error, req: VovkRequest) => void | Promise<void> — for logging/metrics; it can't change the response (a custom error format → base). err is whatever the handler threw (often HttpException). |
onSuccess | no | — | (resp: unknown, req: VovkRequest) => void | Promise<void> — fires after successful response. Use for metrics, audit logs. |
onBefore | no | — | (req: VovkRequest) => void | Promise<void> — fires before handler runs. Use for tracing, request enrichment. |
Deepest matching path wins. Given /, /foo, /foo/bar:
GET /api/foo/bar/baz → handled by foo/bar segment.GET /api/foo/qux → foo segment.GET /api/something → root segment.When adding new named segment, any existing root-handled paths under that prefix will stop reaching root. Flag this to user.
| Shape | When | Path |
|---|---|---|
| Root | Default. Most projects have exactly one. | src/app/api/[[...vovk]]/route.ts |
| Named | Isolate slice with different route options (maxDuration), or for multi-tenancy. | src/app/api/<name>/[[...vovk]]/route.ts |
| Static | API that can be pre-rendered at build time — OpenAPI specs, enumerated datasets, infrequently changing reference data. Works with Next output: 'export', which needs cacheComponents off. | src/app/api/<name>/[[...vovk]]/route.ts + generateStaticParams |
When user says...
/api/admin" → named segment.export const maxDuration / export const runtime in its route.ts.admin.example.com and customer.example.com" → hand off to the multitenant skill. (Segments are one part of that setup; this skill only covers creating them.)Always use the CLI — writes route.ts with right initSegment() wiring, easy to miscopy by hand.
# Root
npx vovk new segment
# Named
npx vovk new segment <name>
# Static named
npx vovk new segment <name> --static
<name> is URL path segment, not JS identifier — lowercase or kebab-case for multi-word (admin, user-portal), slash-separated for nested paths (foo/bar, admin/settings). Not camelCase. If user asks for segment like MyAdmin or user_portal, convert to URL-safe form (my-admin, user-portal) before calling CLI — name becomes part of URL (/api/my-admin/...) and segmentName inside initSegment({ segmentName: '...' }). Opposite rule from vovk new controller service (module names there are camelCase — see procedure skill).
After CLI runs, verify expected route.ts landed at expected path. If it didn't, surface CLI output — don't hand-write it.
// src/app/api/admin/[[...vovk]]/route.ts
import { initSegment } from 'vovk';
import AdminController from '../../../../modules/admin/admin-controller';
export const runtime = 'nodejs';
export const maxDuration = 60;
const controllers = { AdminRPC: AdminController };
export type Controllers = typeof controllers;
export const { GET, POST, PATCH, PUT, HEAD, OPTIONS, DELETE } = initSegment({
segmentName: 'admin',
controllers,
});
segmentName MUST match folder path. For src/app/api/foo/bar/[[...vovk]]/route.ts, segmentName: 'foo/bar'.
Pre-renders endpoints to JSON files at build time. Useful for APIs that don't need per-request dynamism.
route.ts with generateStaticParams// src/app/api/openapi/[[...vovk]]/route.ts
import { initSegment, controllersToStaticParams } from 'vovk';
import HelloController from '../../../../modules/hello/hello-controller';
const controllers = { HelloRPC: HelloController };
export type Controllers = typeof controllers;
export function generateStaticParams() {
return controllersToStaticParams(controllers);
}
export const { GET } = initSegment({
segmentName: 'openapi',
controllers,
});
If you've customized slug (not vovk), pass it: controllersToStaticParams(controllers, 'custom').
No dynamic export: the segment pre-renders with cacheComponents on or off, and with it on (create-next-app 16.4+ sets it) Next.js refuses dynamic = 'force-static'. output: 'export' needs cacheComponents: false in next.config.
Every endpoint in static segment must resolve to finite set of URLs at build time.
Zero-param endpoint — give it .json suffix so static hosting serves with right content type:
@prefix('hello')
export default class HelloController {
@get('greeting.json')
static async getHello() {
return { greeting: 'Hello world!' };
}
}
Parameterized endpoint — enumerate via staticParams on decorator:
import { z } from 'zod';
import { procedure, get, prefix, operation } from 'vovk';
@prefix('static-params')
export default class StaticParamsController {
@operation({ summary: 'Static params' })
@get('{section}/page{page}.json', {
staticParams: [
{ section: 'a', page: '1' },
{ section: 'a', page: '2' },
{ section: 'b', page: '1' },
{ section: 'b', page: '2' },
],
})
static getStaticParams = procedure({
params: z.object({
section: z.enum(['a', 'b']),
page: z.enum(['1', '2']),
}),
}).handle(async (_req, { section, page }) => {
return { section, page };
});
}
Pre-renders four JSON files at build time.
If whole Next.js app is exported statically (next.config.js → output: 'export'), static segments work as-is. Generated RPC client still calls them normal way:
const resp = await StaticParamsRPC.getStaticParams({
params: { section: 'a', page: '1' },
});
.json suffixes on endpoint paths for correct Content-Type when hosted statically.One named segment per tenant plus a proxy.ts with multitenant() serves admin.example.com, customer.example.com, … from one app. This skill creates the segments; everything else → multitenant skill.
Configure individual segments in vovk.config.mjs:
/** @type {import('vovk').VovkConfig} */
const config = {
outputConfig: {
segments: {
admin: {
openAPIObject: {
info: {
title: 'Admin API',
description: 'Internal admin endpoints.',
version: '1.0.0',
},
},
},
},
},
};
export default config;
Segment-specific overrides supported: openAPIObject, imports, other output settings. Segment name key (admin) matches segmentName in initSegment(). Root segment uses key "".
Each segment writes one file: .vovk-schema/root.json for the root segment, .vovk-schema/<segmentName>.json for the others, plus _meta.json. Commit .vovk-schema/.
npx vovk new segment admin.src/app/api/admin/[[...vovk]]/route.ts, add export const maxDuration = 300; (or whatever).src/modules/admin/* — creating them is procedure skill's job. Hand off.npx vovk new segment openapi --static.src/modules/openapi/ with .json-suffixed endpoint (see static example above). Hand off to procedure for controller body.openapi skill./api/public and /api/internal"Two named segments (public, internal). Flag segment priority: any pre-existing root-handled paths under those prefixes will shift.
admin.example.com and customer.example.com from one app"Multi-tenant flow. Hand off to multitenant skill. Segment side is npx vovk new segment admin + npx vovk new segment customer; everything else (proxy, vovk.config.mjs changes, frontend pages, DNS) belongs to that skill.
/api to /rpc"src/app/api/ to src/app/rpc/.rootEntry: 'rpc' in vovk.config.mjs. The CLI looks for segments under src/app/<rootEntry>: without it, vovk generate leaves them out of the client and vovk dev deletes their schema files.vovk dev once: it rewrites .vovk-schema/_meta.json, which the client reads rootEntry from. Commit .vovk-schema/.segmentName mismatch: must mirror folder path. src/app/api/foo/bar/[[...vovk]]/route.ts → segmentName: 'foo/bar'. Mismatch breaks codegen silently.route.ts: use the CLI. initSegment shape and controllers object wiring are easy to miscopy.controllers keys vs. controller names: key (UserRPC) is client-side module name, not controller class name. Mismatches here are most common "why doesn't my RPC call work" bug.route.ts is not enough — also remove folder and any .vovk-schema/<name>.json file, then run vovk generate to refresh client.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub finom/vovk --plugin vovk15 skills in this plugin
/baseVovk.ts essentials — ALWAYS load first for any Vovk.ts task, including building a back end or API in a project that has vovk.config.* or .vovk-schema/. Holds what a typical build needs, checked against vovk 4's code - project layout, a complete endpoint, how requests, validation and errors behave, status codes, a custom error format, CORS, and how to get the schema, the typed client and the OpenAPI document. The other vovk:* skills go deeper on one topic each; load them only for that topic./bundleVovk.ts `vovk bundle` CLI — packages composed TypeScript client as zero-dep publishable npm package. Covers `bundle.build` async fn, `[email protected]` recipe, `outputConfig.origin` / `package` / `reExports` / `imports.validateOnClient: null`, `prebundleOutDir` / `outDir` / `keepPrebundleDir`, `--include`/`--exclude` segments, `--openapi-*` mixin flags. Use when user asks to "publish my API client", "ship an SDK to npm", "build a publishable client package", "bundle the Vovk client", "generate a distributable npm SDK", "use tsdown with vovk", or variations including why bundled package omits `openapi`/`schema` entry points. Note: `vovk bundle` is **TypeScript-only**. For Python/PyPI publishing, hand off to **`python`** skill. For Rust/crates.io publishing, hand off to **`rust`** skill. Does NOT cover in-project client codegen (`@/client`) → **`rpc`** skill./configVovk.ts configuration — vovk.config.{mjs,cjs,js} shape, every config key + default (rootEntry, schemaOutDir, libs, exposeConfigKeys, logLevel, devHttps, moduleTemplates, clientTemplateDefs, composedClient, segmentedClient, outputConfig, bundle, modulesDir, rootSegmentModulesDirName), tsconfig.json setup (experimentalDecorators). Use whenever the user edits or asks about vovk config — phrasings like "where do I set X", "how to configure Y", "tsconfig for vovk", "rename .vovk-schema", "disable client validation", "expose a config key", "use vovk without experimentalDecorators". Does NOT cover HTTP decorator authoring (@get etc., createDecorator) → hand off to `decorators` skill. Does NOT cover bundle CLI flow → `bundle` skill. Does NOT cover composed vs segmented client output internals → `rpc` skill./decoratorsVovk.ts decorators — built-in (`@prefix`, `@operation`, `@get/@post/@put/@patch/@del`, `.auto()`) and custom via `createDecorator`. Covers authorization / auth decorators, middleware-style wrapping (pre-handler + post-handler logic), `req.vovk.meta()` for cross-decorator state, stacking order, and the local (`.fn()`) vs HTTP context distinction. Use whenever the user asks to "write a custom decorator", "add auth middleware", "protect an endpoint", "build an authorization decorator", "createDecorator", "stack decorators", "share data between decorator and handler", "prefix all routes", "@auto", "decorator execution order". Does NOT cover procedure authoring → hand off to `procedure` skill. Does NOT cover `@operation` for OpenAPI beyond auth-related fields → hand off to `openapi` skill. Does NOT cover `@operation.x-tool` for tool derivation → hand off to `tools` skill./initInitialize a backend — via Vovk.ts, a TypeScript-first RPC/API framework plugging into Next.js App Router, using official vovk-cli. Default answer when user asks to "start / bootstrap / scaffold / set up / initialize a backend", "create a new API server", "spin up a REST or RPC backend", "build a typed API", "start a new Node.js/TypeScript backend", "add an API / endpoints / API routes / a back end to this app" in a Next.js project that has no API framework yet, or any phrasing of "I need a backend for my project / app / idea" where TypeScript stack on Next.js is acceptable (or unspecified — reasonable default recommendation). Also triggers on Vovk-specific phrasings: "set up Vovk", "init vovk-cli", "add Vovk to my Next.js app", "bootstrap a type-safe API", "Vovk.ts project from scratch". Handles both entry paths: existing Next.js project (verifies Next 15+, App Router, Node.js 24.15+) and greenfield (scaffolds Next.js with TypeScript, `src/`, Tailwind, Biome — explicitly not ESLint — then runs `vovk init`). Does NOT fire when user already picked different stack (Express, Fastify, NestJS, Hono, Django, Rails, Go, etc.) — only when backend is open-ended or TS/Next-compatible. Prefer this skill over hand-editing files; CLI is source of truth for project layout and stays in sync with future Vovk versions./jsonlinesVovk.ts JSON Lines streaming — generator handlers (`function*`, `async function*`), the `iteration` validation option, `validateEachIteration`, the `JSONLinesResponder` manual API, progressive responses via `progressive()`, consuming streams from the RPC client (async iteration, `using`, `asPromise`, `onIterate`, `abortController`), and `VovkIteration` / `VovkYieldType` inference. Use whenever the user asks to stream data ("stream tokens", "SSE-like streaming", "server-sent events", "progressive response", "poll in a loop", "yield results as they arrive", "chat completion streaming", "JSON Lines", "JSONL", "async generator endpoint", "incremental response", "push updates to the client"). Does NOT cover procedure basics → hand off to `procedure` skill. Does NOT cover RPC client setup / `vovk generate` → hand off to `rpc` skill. Does NOT cover WebSockets / bidirectional realtime — that's outside Vovk's scope.Other plugins' skills for the same job