Skip to content
Back to skills

Stacks Routes

ASecurity

Use when defining or organizing route files in a Stacks application - creating route files in routes/, registering them in app/Routes.ts, using route prefixes and middleware groups, or the default API routes structure. For the router API itself (request helpers, response helpers, middleware classes), see stacks-router.

  • 631 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 5, 2026
developmenttypescriptgobashapi

Works with

  • cli
  • api

Security analysis

A100/100

Scanned September 3, 2026

npx -y skills add stacksjs/stacks --skill stacks-routes --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Stacks Routes?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Stacks Routes
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/stacksjs-stacks-routes/badge)](https://www.skillsdirectory.com/skills/stacksjs-stacks-routes)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: stacks-routes
description: Use when defining or organizing route files in a Stacks application - creating route files in routes/, registering them in app/Routes.ts, using route prefixes and middleware groups, or the default API routes structure. For the router API itself (request helpers, response helpers, middleware classes), see stacks-router.
license: MIT
compatibility: Bun >= 1.3.0, TypeScript
allowed-tools: Read Edit Write Bash Grep Glob
---

# Stacks Route Definitions

How to define and organize routes in a Stacks application.

## Key Paths
- Route files: `routes/` (api.ts, v1.ts, buddy.ts, users.ts)
- Route registry: `app/Routes.ts`

## Route Registry (app/Routes.ts)

Maps route files to URL prefixes:
```typescript
export default {
  'api': 'api',                                    // routes/api.ts → /api/* (auto-prefixed; see #1835)
  'v1': { path: 'v1', prefix: 'v1' },            // routes/v1.ts → /v1/*
  'admin': { path: 'admin', prefix: 'admin', middleware: ['auth'] }
} satisfies Record<string, string | RouteDefinition>
```

## Creating a Route File

```typescript
// routes/api.ts
import { route } from '@stacksjs/router'

route.get('/users', 'Actions/ListUsers')
route.post('/users', 'Actions/CreateUser')
route.get('/users/{id}', 'Actions/ShowUser')
route.put('/users/{id}', 'Actions/UpdateUser')
route.delete('/users/{id}', 'Actions/DeleteUser')

// With inline handler
route.get('/health', (req) => Response.json({ status: 'ok' }))

// Groups
route.group({ prefix: '/admin', middleware: ['auth'] }, () => {
  route.get('/dashboard', 'Actions/Dashboard')
  route.get('/settings', 'Actions/Settings')
})

// Health check
route.health()
```

## Default API Routes (routes/api.ts)

### Authentication
- `POST /login` → LoginAction
- `POST /register` → RegisterAction
- `POST /auth/refresh` → RefreshTokenAction
- `GET /me` → GetMeAction (auth)
- `POST /logout` → LogoutAction (auth)

### Email
- `POST /api/email/subscribe`
- `GET /api/email/unsubscribe`

### AI
- `POST /ai/ask`, `POST /ai/summary`

### CMS & Commerce
- `/cms/posts/*`, `/cms/authors/*`, `/cms/categories/*`, `/cms/tags/*`
- `/commerce/products/*`, `/commerce/orders/*`, `/commerce/customers/*`

### Health
- `GET /health` — status, uptime, memory, PID, Bun version

## Versioned Routes (routes/v1.ts)

```typescript
// routes/v1.ts — prefixed with /v1
route.get('/users', 'Actions/V1/ListUsers')
```

## Handler Types

```typescript
// 1. Action string (auto-loaded from app/Actions/)
route.get('/users', 'Actions/ListUsers')

// 2. Controller method
route.get('/users', 'Controllers/UserController@index')

// 3. Inline function
route.get('/ping', (req) => Response.json({ pong: true }))
```

## CLI Commands
- `buddy route:list` — list all registered routes

## Gotchas
- Route files must be registered in `app/Routes.ts` to be loaded
- String handlers (Actions/X) are dynamically imported at request time
- Route order matters — first match wins
- Use groups for shared middleware instead of repeating on each route
- The `health()` helper registers `GET /health` automatically
- For the router API (request helpers, middleware, responses), see the `stacks-router` skill

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.