KosmoJS uses directory-based routing: folder names become URL path segments, and index files define the actual endpoints or components.
No separate routing configuration - your file structure is your route definition.
π£οΈ How It Works β
The same pattern applies to both API routes and client pages:
api/
index/
index.ts β /api
users/
index.ts β /api/users
[id]/
index.ts β /api/users/:id
pages/
index/
index.tsx β /
users/
index.tsx β /users
[id]/
index.tsx β /users/:idThe parallel structure between api/ and pages/ is intentional - if you have a /users/[id] page, the corresponding /api/users/[id] endpoint is easy to find.
Every route lives in a folder, including the root - the base route uses a folder named index. This consistency means no special cases: every route is a folder with an index file inside.
π Route File Requirements β
API routes export a route definition (HTTP methods + handlers). Client pages export a component function.
The auto-generation feature creates the correct boilerplate for you when you create a new file, so you rarely need to write it from scratch.
The folder-per-route pattern gives each route its own namespace for colocating related files - utilities, types, tests - without cluttering parent directories.
ποΈ Nested Routes β
Nesting works by nesting folders. api/users/[id]/posts/index.ts maps to /api/users/:id/posts, and can go as deep as needed.
For client pages, nested routes support layout components that wrap child routes with shared UI like navigation or headers. (Details β )