controller-patterns

Conventions for organizing request-handling controllers in the Koapp web framework. Controllers contain methods that read request data and return HTTP responses.

In plain words
What is it for?
Use it when creating controllers, reading URL parameters, query values, or request bodies, returning success or error responses, logging debug information, and separating business logic into services or models.
Why use it?
It keeps request handling consistent and helps prevent controllers from becoming overloaded with business logic. It also explains the available response and logging methods.

Cursor rule for Codex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/axiosleo/node-koapp/controller-patterns
Clone the repo
git clone --depth 1 https://github.com/AxiosLeo/node-koapp

Made for: Codex.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 294 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00294
Opus 5 $0.00000 $0.00147
Sonnet 5 $0.00000 $0.00059
Haiku 4.5 $0.00000 $0.00029

Measured yesterday against content hash f954a930f19d, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

controller-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/rules/controller-patterns.mdc · 51 lines

What it actually says

Controller Patterns

Controller Base Class

Extend the Controller class for organized request handling:

const { Controller } = require("@axiosleo/koapp");

class UserController extends Controller {
  async getUser(context) {
    // Access path params: context.params.id
    // Access query params: context.query
    // Access request body: context.body

    this.success({ user: userData });
  }

  async createUser(context) {
    this.success({ message: "User created" });
  }
}

Response Methods

Controllers inherit response methods:

  • this.success(data, headers) - 200 OK
  • this.failed(data, code, status, headers) - Error response
  • this.result(data, status, headers) - Custom response
  • this.error(status, msg, headers) - HTTP error
  • this.response(data, code, status, headers) - Full control

Logging

Use this.log(...data) for debug logging within controllers.

Best Practices

  1. Keep controllers thin - delegate business logic to services/models
  2. Use async/await for asynchronous operations
  3. Validate input using router validators rather than in controllers
  4. Use appropriate response methods for different scenarios
  5. Handle errors gracefully with try/catch blocks
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 51 lines · 294 tokens per session scan A f954a930f19d

Subscribe to this mod's changes

controller-patterns is a cursor rule published in the GitHub repository AxiosLeo/node-koapp (129 stars, last pushed 18d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 294 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.