Production-ready features, right out of the box.
ποΈ Multiple Source Folders β
Organize distinct concerns - public site, customer app, admin dashboard - as independent source folders within a single Vite project. Each gets its own set of frameworks, base URL, development workflow and build pipeline.
π£οΈ Directory-Based Routing β
Your folder structure defines your routes - for both API and client pages.
api/users/[id]/index.ts β /api/users/:id
pages/users/[id]/index.tsx β /users/:idDynamic parameters: [id] required Β· {id} optional Β· {...path} splat. No separate routing config to maintain - restructure files and routes update automatically.
Also mixed sections supported for backend routes (and some frontend integrations):
products/[category].html/index.ts β products/electronics.html
files/[name].[ext]/index.ts β files/document.pdf, /files/logo.pngβ‘ Power Syntax for Params β
When standard named parameters aren't enough, use raw path-to-regexp v8 patterns directly in your folder names:
book{-:id}-info β /book-info or /book-123-info
locale{-:lang{-:country}} β /locale, /locale-en, /locale-en-US
api/{v:version}/users β /api/users or /api/v2/usersAny param name containing non-alphanumeric characters is treated as a raw pattern - giving you precise control over URL structure without sacrificing the directory-based routing model.
π‘οΈ End-to-End Type Safety β
Write TypeScript types once - KosmoJS generates runtime validators automatically. The same definition drives compile-time checking, runtime validation, type-safe fetch clients, and OpenAPI specs.
export default defineRoute(({ POST }) => [
POST<{
json: {
email: VRefine<string, { format: "email" }>;
age: VRefine<number, { minimum: 18 }>;
},
response: [200, "json", User],
}>(async (ctx) => {
const { email, age } = ctx.validated.json;
// payload validated before reaching here
// response validated before sending
}),
]);π Generated Fetch Clients + OpenAPI β
For every API route, KosmoJS generates a fully-typed fetch client and an OpenAPI 3.1 spec - both derived from the same type definitions.
import fetchClients from "_/fetch";
const user = await fetchClients["users/[id]"].GET([123]);
// fully typed, validates payload client-side before the request is sentFetch Clients β Β· OpenAPI β
ποΈ Composable Middleware (Slots) β
Global middleware defined in api/use.ts can be overridden per-route or per-subtree using named slots - without removing or bypassing parent middleware entirely.
// global default in api/use.ts
use(async (ctx, next) => { /* ... */ }, { slot: "logger" })
// override for a specific route
use(async (ctx, next) => { /* custom logger */ }, { slot: "logger" })Slots give you surgical control over middleware composition: replace only what needs replacing, inherit everything else. Custom slot names are supported by extending the UseSlots interface.
π Cascading Middleware β
Place a use.ts file in any folder and its middleware automatically wraps all routes in that folder and its subfolders - no imports or wiring needed.
api/admin/use.ts β wraps all routes under /api/admin
api/admin/users/use.ts β wraps only routes under /api/admin/usersParent middleware always runs before child middleware. Combine with slots to override globals for entire route subtrees.
πͺ Nested Layouts β
Frontend pages support nested layout components that wrap child routes - compose shared UI (nav, sidebars, auth shells) at any level of the route hierarchy.
pages/
app/
layout.tsx β wraps all /app/* pages
dashboard/
layout.tsx β wraps all /app/dashboard/* pages
index.tsx
settings/
index.tsxπ¨ Multiple Frameworks β
Backend: Koa or Hono - same routing architecture, same type safety. Frontend: React, Vue, SolidJS, MDX - same routing/layout/SSR conventions.
Different source folders can use different framework combinations. When you add a source folder, KosmoJS generates a ready-to-go setup for your chosen stack.
π§ Built on Proven Tools β
Koa/Hono Β· React/Vue/Solid/MDX Β· Vite Β· TypeScript. No proprietary abstractions - just structure on top of tools you already know.