ktor-backend-endpoint

Creates and modifies Ktor REST endpoints with Exposed repositories, SQL migrations, and Clean Architecture layers.

Updated Apr 1, 2026
One-click install
npx skills add https://github.com/DCueto/zen-track --skill ktor-backend-endpoint-dcueto
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ktor-backend-endpoint
Source: https://github.com/DCueto/zen-track/tree/main/ZenTrackApp/.agents/skills/ktor-backend-endpoint
Command: npx skills add https://github.com/DCueto/zen-track --skill ktor-backend-endpoint-dcueto

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building backend endpoints in a Ktor + PostgreSQL + Exposed stack without enforced architecture leads to business logic leaking into routes, missing Row Level Security, and full table scans in production. This Skill enforces a strict, repeatable procedure for creating or modifying REST endpoints in the ZenTrack server/ module while preserving Clean Architecture boundaries, tenant isolation, and database performance. ## Core Features & Use Cases - Layered endpoint scaffolding: Step-by-step procedure covering SQL migration, Exposed table, Repository, Use Case, Ktor route, and Koin registration with strict layer boundaries. - Security enforcement: Mandatory JWT-based tenant extraction, Row Level Security policies per table, and signature validation for public webhook endpoints. - Performance guardrails: Required foreign-key indexes, tenant-filtered queries, and SELECT FOR UPDATE for atomic task_number generation. - Use Case: When asked to add a new POST /api/projects/{id}/tasks endpoint, the Skill produces the idempotent migration with RLS, the Exposed table descriptor, a suspend Repository returning domain models, a framework-free Use Case, and a thin Ktor route wired through Koin. ## Quick Start Ask the AI to create a new REST endpoint in the server module, for example: add an endpoint to list all tasks in a sprint following the ktor-backend-endpoint procedure.

Frequently Asked Questions about ktor-backend-endpoint

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a new REST endpoint in Ktor with Clean Architecture?▼

Follow a six-step procedure: write the SQL migration, define the Exposed table, implement a suspend Repository returning domain models, create a framework-free Use Case, add a thin Ktor route that only parses and serializes, then register everything in Koin and Application.kt.

How to implement Row Level Security in PostgreSQL for multi-tenant tables?▼

Enable RLS on every new table with ALTER TABLE ... ENABLE ROW LEVEL SECURITY and create a policy filtering by workspace_id using current_setting('app.current_workspace_id'). Never bypass RLS with superuser roles or run tenant queries without a WHERE filter.

How do I generate sequential task numbers safely in PostgreSQL?▼

Use SELECT ... FOR UPDATE on the parent Project row inside a transaction, increment its last_task_number counter, then insert the task with that locked number. Global database sequences and in-memory counters are not acceptable for this pattern.

Can Ktor routes call repositories directly instead of use cases?▼

No. Routes must only parse requests, extract the tenant from the JWT, call a Use Case, and serialize the response. Calling Repositories from routes breaks layer boundaries and makes business logic untestable without a running server.

How do I secure a public webhook endpoint without JWT in Ktor?▼

Validate the provider's signature header (X-Hub-Signature-256 or X-Gitlab-Token) against the raw request body before processing any payload. Document explicitly why the endpoint omits the authenticate block, and ensure lookups by git_branch_name use a dedicated index.

Why must use cases avoid importing Ktor or Exposed?▼

Use Cases contain pure business logic and must be testable without a server or database framework. Importing io.ktor.* or org.jetbrains.exposed.* couples the domain layer to infrastructure, violating Clean Architecture boundaries and breaking unit testability.