# KosmoJS > KosmoJS is a full-stack meta-framework for building several apps in a scalable codebase. Each gets its own backend and frontend framework and its own routes, sharing one install, one set of types, one build. Built on Vite. ## Table of Contents ### Essentials - [Project Structure](/essentials/project-structure.md): The anatomy of a KosmoJS project - source folders, the derived var/lib directory, build output, and the reserved @/ ~/ _/ path mappings. - [Configuration](/essentials/config.md): Complete reference for kosmo.config.ts - the frontend, backend and validation blocks, base URLs, stack plugins and vite options, and the project-level settings in package.json. - [Framework Support Matrix](/essentials/frameworks.md): What each backend and frontend framework supports in KosmoJS - mixed segments, power syntax, streaming SSR, SSG, TanStack Query, layouts, data loading and hooks - in one table. - [Migration Tips](/essentials/migration-tips.md): Translation guide for developers moving to KosmoJS from Next.js App Router, TanStack Start/Router or tRPC - server actions, route groups, parallel routes, loading.tsx, revalidateTag, next/image, validateSearch, routeTree.gen.ts and middleware.ts, each mapped to its KosmoJS equivalent or explicitly marked as having none. - [Why HTTP](/essentials/why-http.md): The industry spent two decades pulling server logic out of the page, and is now putting it back? A look at what actually moved, and why KosmoJS keeps an explicit HTTP boundary while making it cost nothing during SSR - one isomorphic fetch client, two transports, validation on both ends. - [Why Codegen](/essentials/why-codegen.md): Two very different things share the word "codegen". KosmoJS only does the safe kind - derivation into a git-ignored var/lib/ folder, plus boilerplate seeded into blank files and never touched again. ### CLI - [CLI Overview](/cli/intro.md): Every KosmoJS command - create kosmo and kosmo folder for scaffolding, serve, preview, build and typecheck for everything after, plus the interactive and flag-driven modes and every message a command exits with. - [create kosmo](/cli/create.md): Bootstrapping a KosmoJS project with npm create kosmo - the interactive flow, the flags, and what the new project contains. - [kosmo folder](/cli/folder.md): Adding a source folder to an existing project, interactively or from flags, and installing the dependencies a new folder needs. - [kosmo sidecar](/cli/sidecar.md): Adding a sidecar folder to an existing project - a source folder that builds entry points instead of serving HTTP. - [kosmo serve](/cli/serve.md): The development server - one process for the whole project, client modules through Vite with HMR, API routes hot-reloaded in the same process, on devHost. - [kosmo preview](/cli/preview.md): Building and serving the production output on previewHost, rebuilt on change - the only way to see SSR, bundling and the production validation policy locally. - [kosmo build](/cli/build.md): The production build - what it emits per folder, how partial builds stay safe, and the manifest dist/run.js reads at startup. - [kosmo typecheck](/cli/typecheck.md): Typechecking each source folder against its own tsconfig, plus the project root run and what its include list decides. ### Routing - [Routing: Overview](/routing/intro.md): KosmoJS uses directory-based routing to map file system structure directly to URL paths. Folder names become path segments with index files defining endpoints and components. - [Routing: Rationale](/routing/rationale.md): Understanding why directory-based routing scales better than file-based routing for organizing large applications with clear navigation, colocalization, and visual hierarchy. - [Routing: Parameters](/routing/params.md): Handle dynamic URL segments with required [id], optional {id} and splat {...path} parameters. SolidStart-inspired syntax that works identically for API routes and client pages. ### Backend - [Backend Overview](/backend/intro.md): KosmoJS API layer supports Hono, H3 and Koa frameworks, with elegant middleware composition, end-to-end type safety, and flexible route definitions inspired by Sinatra framework. - [Backend Routing](/backend/routing.md): How API routes are resolved in KosmoJS - folders become URLs, method builders become endpoints, and the route name ties a handler to its generated types. Params, dispatch, 405 and HEAD semantics, aliases and per-framework routing support for Hono, H3 and Koa. - [Request Context](/backend/context.md): Learn about KosmoJS's enhanced context - unified bodyparser and metaparser APIs, and ctx.validated for type-safe validated data access - [Type Safety](/backend/type-safety.md): Refine params/payload/response types in KosmoJS with compile-time TypeScript checking and automatic runtime validation using type arguments - [Middleware](/backend/middleware.md): Middleware chains and the Hono/H3/Koa onion model. Global middleware in api/use.ts that runs for every route in a source folder, method restrictions, and overriding defaults through slots. - [Cascading Middleware](/backend/cascading-middleware.md): Organize middleware hierarchically using use.ts files that wrap route subtrees. Apply authentication, logging, and custom parsers to folders and their descendants without cluttering individual route definitions. - [Edge Middleware](/backend/edge-middleware.md): The first middleware a matched route runs - any use() entry under an edge-prefixed slot, at any level, ahead of validation, so authentication answers 401 before a schema can answer 400. - [Error Handling](/backend/error-handling.md): Handle errors gracefully in KosmoJS with customizable error handlers for Hono, H3 and Koa. Learn about default error handling, route-level overrides, and framework differences. - [Aliases](/backend/aliases.md): Serve an existing API route at an additional public URL - well-known paths, legacy URLs, and public-facing names that differ from the route on disk. - [Custom Templates](/backend/custom-templates.md): Override the seeded defineRoute boilerplate for specific API routes using glob pattern matching. Seed consistent CRUD endpoints across many routes in Hono, H3 and Koa. - [Backend Testing](/backend/testing.md): Run your API routes through the real stack - routing, middleware, validation, error handling - with no network, no server, and no mocks. ### Frontend - [Frontend Overview](/frontend/intro.md): Integrate KosmoJS directory-based routing with React, SolidJS, Vue, Svelte, or MDX. Automatic route configuration, type-safe navigation, and optimized lazy loading for modern frontend applications. - [Application Structure](/frontend/application.md): Seeded foundation files for React, SolidJS, Vue, Svelte and MDX applications - root app component, AppProvider seam, router configuration and client entry point with SSR hydration support. - [Frontend Routing](/frontend/routing.md): How pages are routed in KosmoJS - folders become URLs, page and layout files become nested routes, and the framework's own router does the matching. Params, layouts, lazy loading, data loading and typed navigation for React, Solid, Vue, Svelte and MDX. - [Nested Layouts](/frontend/layouts.md): Compose shared UI at any level of the route hierarchy using layout files. Navigation, sidebars, auth shells, and data loading scoped to route subtrees for React, SolidJS, Vue, Svelte and MDX applications. - [Data Preloading](/frontend/data-preload.md): Prefetch route data before components render using React Router's loader pattern, SolidJS Router's query/preload, and Vue, Svelte and MDX loader exports. Type-safe data availability derived from API endpoint definitions. - [The _/use Hooks](/frontend/hooks.md): Reference for the derived _/use module - useLoaderData, useParams, useRoute, useParamsEntries, useSearchParams and useFrontmatter - and which frameworks provide it. - [Server-Side Rendering](/frontend/server-side-render.md): Add SSR capabilities to React, SolidJS, Vue, Svelte and MDX applications using KosmoJS SSR setup. String and stream rendering patterns, production builds, and deployment configurations for server-rendered applications. - [Static Site Generation](/frontend/static-site-generation.md): Pre-render React, SolidJS, Vue, Svelte and MDX pages to static HTML at build time with the KosmoJS SSG setup. Declaring staticParams for dynamic routes per framework, building in CI against production data, output layout, and deploying to a static host or CDN. - [Error Boundaries](/frontend/error-boundaries.md): Catch rendering errors with each framework's native error boundary at the layout level. How boundaries behave during client rendering versus server-side rendering. - [Error Pages](/frontend/error-pages.md): The pages/404 component KosmoJS renders for unmatched routes - where it lives per framework, how it is registered as the router's catch-all, and how it behaves under CSR, SSR and SSG, including which HTTP status each one returns. - [TanStack Query](/frontend/tanstack-query.md): Integrate TanStack Query with KosmoJS. Build your app around the query provider using the client from _/query, prefetch in loaders for warm SSR with no duplicated payload, and read with useQuery. Per-framework guides for React, SolidJS, Vue and Svelte. - [Type-Safe Navigation](/frontend/link-navigation.md): Link component wrapping each framework's native router with compile-time route validation. Autocomplete navigation targets, parameter enforcement, and query string handling for React, SolidJS, Vue, Svelte and MDX. - [Custom Templates](/frontend/custom-templates.md): Override default seeded page components for specific routes using glob pattern matching. Seed specialized boilerplate for landing pages, admin dashboards, marketing sections etc. - [MDX Content](/frontend/mdx.md): Create content-focused source folders with MDX - static HTML rendering with Preact, nested layouts, frontmatter-driven head injection, typed Link component. - [Frontend Testing](/frontend/testing.md): Test pages against a real server - drive a real browser, or assert on server-rendered HTML with no browser at all. ### Runtype Validation - [Runtime Validation](/validation/intro.md): KosmoJS runtype validation automatically converts TypeScript types into JSON Schema with runtime validators. Write types once, get compile-time and runtime safety without schema duplication. - [Parameter Validation](/validation/params.md): Validate route parameters at runtime with type refinements using defineRoute type arguments. Convert string URL parameters to validated numbers, integers, or constrained values with VRefine. - [Payload Validation](/validation/payload.md): Validate request payloads with inline TypeScript types or imported type definitions. Support for nested structures, conditional validation, generics, and complex domain models with VRefine constraints. - [Response Validation](/validation/response.md): Validate API responses before sending to clients. Catch bugs where handlers return incomplete objects, wrong types, or unexpected structures. Enabled by default in development; opt in per handler for production. - [VRefine for Refinement](/validation/refine.md): Advanced validation constraints with VRefine using JSON Schema keywords. Validate string formats, numeric ranges, array constraints, and custom patterns directly in TypeScript types. - [Skip Validation](/validation/skip-validation.md): Set runtimeValidation option to false to keep TypeScript type checking without runtime validation for gradual adoption, performance optimization, or trusted internal endpoints. - [Error Handling](/validation/error-handling.md): Handle ValidationError instances with detailed error information including scope, error messages, field paths, and structured ValidationErrorEntry data. - [Naming Conventions](/validation/naming-conventions.md): Avoid TypeScript built-in type names when defining types for validation. Use suffix T or prefix T conventions to prevent runtime validation failures. - [Silent Failure Checklist](/validation/gotchas.md): The four validation mistakes that typecheck cleanly and fail at runtime - non-inline VRefine constraints, built-in type names, float IDs, and non-coercing targets. - [About Performance](/validation/performance.md): Understand KosmoJS validation performance with TypeScript compiler analysis, intelligent caching, and background processing that doesn't impact development workflow. ### Fetch Clients - [Fetch Clients](/fetch/intro.md): KosmoJS automatically derives fully-typed fetch clients with runtime validation for every API route. End-to-end type safety from frontend to backend with validation schemas and URL utilities. - [Quick Start](/fetch/start.md): Import and use KosmoJS fetch clients with full TypeScript typing. Access routes directly or through a centralized map with automatic parameter and payload validation. - [Integration](/fetch/integration.md): Integrate KosmoJS fetch clients with SolidJS query/createAsync, React, Vue and Svelte useLoaderData, and MDX hooks. Type safety flows through all framework abstractions. - [Isomorphic Clients](/fetch/isomorphic-clients.md): One fetch client, two transports - a same-origin request in the browser and an in-process dispatch into your API during SSR. What decides which one runs, what the in-process path actually does, how hydration reuses the result, and what happens when an SSR fetch fails. - [Validation](/fetch/validation.md): Automatic client-side validation with TypeBox schemas before network requests. Use check, errors, errorMessage methods for form validation with performance optimization patterns. - [Type Safety](/fetch/type-safety.md): Fetch clients are fully typed - parameters, payload, and response all mirror the backend route. Access response types on the client with the ResponseT map. - [Error Handling](/fetch/error-handling.md): Fetch clients always throw on failure, so every failure is catchable. Distinguish ValidationError from network and server errors, and handle them with a try-catch or an error boundary at layout or app level. - [Path Utilities](/fetch/utilities.md): Build URLs with path and href utility functions that handle route parameters, query strings, and base URL configuration for navigation and external references. ### Sidecar Folders - [Sidecar Folders](/sidecar/intro.md): A source folder that builds a standalone process instead of serving routes - background workers, queue consumers, listeners. - [Sidecar config](/sidecar/config.md): The sidecar block - entry, run, serve and viteConfig - and opting a sidecar out of typechecking. - [Entry and runner](/sidecar/entry.md): The two files a sidecar is made of - defineService for the service itself, and the runner that supervises it in production. - [Sidecars in development](/sidecar/development.md): Running a sidecar under kosmo serve - how the reload works, why the close function is what frees the port, and when not to set serve at all. - [Preview and production](/sidecar/production.md): Starting sidecars outside development - why the dispatcher never does it, and what running them separately looks like. ### OpenAPI - [OpenAPI](/openapi/intro.md): Deriving an OpenAPI 3.1 specification from KosmoJS routes - what it covers, and how to switch it on for a source folder. - [OpenAPI config](/openapi/config.md): Every key of the backend.openapi block - outfile, info, servers and the rest - and what happens when a required one is missing. - [Generated spec](/openapi/spec.md): What lands in the generated document - paths, schemas, parameters, request bodies, responses and VRefine constraints, including path variations for optional parameters. ### Dev / Build / Run - [Development Workflow](/dev-build-run/development-workflow.md): The KosmoJS dev server - HMR for client code, hot reload for the API, custom request routing, and resource cleanup with teardown handlers. - [Production Preview](/dev-build-run/production-preview.md): Run the real KosmoJS production build locally with kosmo preview - server-rendered pages, bundled assets and production validation policy, still reloading on change. - [Building for Production](/dev-build-run/building-for-production.md): Build and deploy KosmoJS applications to production - a single dist/run.js entry point across all source folders, plus per-folder servers for containers, serverless, and edge runtimes. ### FAQ / LLMs - [KosmoJS FAQ](/faq.md): Frequently asked questions about KosmoJS for developers and LLM agents - [Notes for LLM Agents](/agents.md): What an LLM agent must check before emitting KosmoJS code - which framework the folder runs, who writes the boilerplate, the four validation mistakes that typecheck but fail at runtime, middleware placement, and why the dev server never shows the SSR path. ### 2026 - [v0.6.10: a $/ prefix and smarter templates](/blog/2026/v0.6.10.md): v0.6.10 adds a $/ prefix for reaching any folder's derived code, and function templates that seed layouts and use.ts files too. Plus two fixes. - [v0.6.9: frontend tests without a browser](/blog/2026/v0.6.9.md): v0.6.9 adds a frontend.test.ssr option, so the test harness can serve server-rendered HTML, and tests can assert on it without driving a browser. - [v0.6.8: empty replies and content types](/blog/2026/v0.6.8.md): v0.6.8 finishes the empty-reply fix from v0.6.7 for Chrome, and fetch clients now pick how to read a reply from its content type. - [v0.6.7: two more fixes](/blog/2026/v0.6.7.md): v0.6.7 fixes double slashes in paths of routes that start with an optional param, and fetch clients throwing on empty 204 and 205 replies. - [v0.6.6: three small fixes](/blog/2026/v0.6.6.md): v0.6.6 fixes links to index pages that pointed at the current page, dist/run.js failing to start without --host, and Vue server rendering mistaking /administrator for a path under /admin. - [v0.6.5: fixes after the move](/blog/2026/v0.6.5.md): v0.6.5 fixes the root .gitignore that stopped committing the derivation cache, static files with spaces in their names, and aliases that answered differently in dev and production. - [v0.6.4: lib/ relocated into var/](/blog/2026/v0.6.4.md): v0.6.4 moves derived code out of the project root, and seeds new source folders with a default page and a default API route. - [v0.6.2: tests, built in](/blog/2026/v0.6.2.md): Vitest integration lands. A test file next to every route, backend tests through the real stack with no network, and frontend tests driving a real browser against a real server. - [v0.5.2: sidecars and edge middleware](/blog/2026/v0.5.2.md): Two additions with little in common, except that both started as annoyances. A folder that builds a process instead of serving routes, and middleware that runs before validation. ### Retrospective - [A year of silence](/blog/retrospective/overview.md): KosmoJS has been on GitHub for a year with no blog posts. This is the series that should have been written monthly. It arrives now because the API finally stopped moving. - [Params syntax, three attempts](/blog/retrospective/params.md): Every routing framework has its own way of writing `[id]`. KosmoJS uses one syntax everywhere. Getting there took three attempts, and I'm glad I don't like the first one anymore. - [Middleware: step by step](/blog/retrospective/middleware.md): Middleware in KosmoJS did not start with slots, cascading or edge. It started as all or nothing, and every step after it was a fix for one specific annoyance. - [Validation: TS at runtime](/blog/retrospective/validation.md): You write a type. Then you write the same shape again in Zod. Then the client needs its own copy. Making the type the source took a search for a library that did not exist, and shaped more than validation. - [Config: from wiring to describing](/blog/retrospective/config.md): A source folder's config went through three shapes, a Vite config, a list of generators, a declarative description. Each one took a decision away from the developer, and none of them was planned. - [Fetch clients: typed, validated, isomorphic](/blog/retrospective/fetch-clients.md): A generated client that started as just types, and grew one bug at a time into one that validates like the server, runs anywhere, and fails loudly. - [Three backends, one route spec](/blog/retrospective/backends.md): Hono, H3 and Koa all work in KosmoJS. They share no context, no response shape and no error model, and that's on purpose. How "support" slowly came to mean something narrower and more useful. - [Five frontends, one contract](/blog/retrospective/frontends.md): KosmoJS started as a Solid template and went public with two frontends. Today it runs five, each keeping its own idioms. - [Error handling: let handlers fail](/blog/retrospective/error-handling.md): A framework's job isn't to prevent failures, it's to give them one place to land. How KosmoJS's error model moved, one step at a time, away from the handler and toward the framework. - [SSR and SSG: one powering another](/blog/retrospective/ssr-ssg.md): KosmoJS was never built around SSR. How it arrived anyway, how much of it Vite had already covered, and how SSG grew out of a disposable SSR server. - [The first five minutes](/blog/retrospective/cli.md): Starting a KosmoJS project used to take two runs, seven questions, two installs, and ended on a 404. Today it is three questions and a working page. No question got better. They just stopped being asked. - [Runtime: from many ports to one process](/blog/retrospective/runtime.md): Every source folder used to be its own server, on its own port, and the docs defended it. A year later one process serves them all. The boundary never moved. It was just never where I thought it was. ### Other - [About KosmoJS](/about.md): KosmoJS - the composable meta-framework. Organize multiple apps with directory-based routing, automatic runtime validation, fetch clients, and OpenAPI specs. - [Features](/features.md): Explore KosmoJS features including multiple source folders, directory-based routing, end-to-end type safety, derived fetch clients, OpenAPI specs, and framework freedom - Hono, H3, Koa, React, Solid, Svelte, Vue, MDX. - [Quick Start](/start.md): Get a KosmoJS project running in under five minutes. - [Tutorial](/tutorial.md): Build a full KosmoJS application step by step - routing, validation, middleware, fetch clients, pages, SSR, and multi-folder architecture.