Imported from diegopatinodoprr/woter (
woter-api/AGENTS.md). Install upstream withnpx skills add diegopatinodoprr/woter --skill woter-api. Copyright stays with the author.
Woter API - Route Rules
Purpose
This file defines the rules to follow when creating or updating API routes for Woter.
Route Folder Structure (Required)
- For each new route, create a folder named after the route.
- The folder must be created under
src/routes, following the same structure assrc/routes/authentication. - Inside the folder, create these files:
router.tsservice.tsdomain-adapter.tscomponent.tsvalidator.ts(when input validation is needed, as done inauthentication)
Mandatory Steps For New Route
- Create the new route folder in
src/routesby takingsrc/routes/authenticationas the reference pattern. - Implement and wire
router.ts,service.ts,domain-adapter.ts,component.ts(andvalidator.tswhen relevant). - Update
src/server.tsto mount/register the new route.
Component Rule
- The
component.tsfile must instantiate the other files/classes in its constructor and wire them together.
Router.ts Generation Rules (Required)
- Every
router.tsmust expose anisAliveendpoint:- Route declaration:
this.router.get('/isAlive/', this.isAlive);- Handler declaration:
public isAlive = (req: any, res: any): Promise<any> => { return this.returnResp(Promise.resolve(true), req, res); }; - All
GETroutes must follow the same direct handler style:this.router.get('/path', this.myGetHandler); - All routes that require a request body must register
parseBodybefore the handler.- Example for
POST:
this.router.post('/invitations', this.parseBody, this.invitations);- Apply the same rule to
PUTandPATCHroutes with body.
- Example for
General Principles
- Keep routes RESTful and resource-oriented.
- Prefer plural nouns for resources:
/users,/products. - Use nouns for resources, verbs only for actions that are not CRUD:
/auth/login. - Version the API using a prefix:
/api/v1. - All responses must be JSON.
- Always validate inputs at the edge (params, query, body).
- Never expose internal errors or stack traces in responses.
Request & Response
-
All route inputs and outputs must use shared interfaces defined in
woter-library. -
Do not define request/response interfaces locally in
woter-apiwhen a shared contract is required. -
Create or update the interface contract in
woter-libraryfirst, then import it into the API route files. -
Use standard HTTP methods:
GET,POST,PUT,PATCH,DELETE. -
POSTcreates a resource;PUTreplaces;PATCHpartially updates. -
Use proper status codes:
200OK201Created204No Content400Bad Request401Unauthorized403Forbidden404Not Found409Conflict422Unprocessable Entity500Internal Server Error
-
Errors must follow this shape:
{"error": {"code": "SOME_CODE", "message": "Human readable"}} -
Success responses must wrap data:
{"data": {}}
Routing Conventions
- Base path:
/api/v1. - Route folders live in
src/routesand are grouped by domain. - Each domain route folder exports a router and is mounted in
src/server.ts. - Middlewares live in
src/middlewares. - Validators live in
src/validators.
Auth & Security
- Protect private routes with auth middleware.
- Use JWT for access tokens.
- Refresh tokens are stored server-side (db or cache) and rotated.
- Rate-limit auth endpoints.
- Use CORS and secure headers.
Logging & Observability
- Log every request with method, path, status, duration, request-id.
- Errors must be logged with stack trace on server only.
Examples
POST /api/v1/auth/loginGET /api/v1/users/{id}PATCH /api/v1/users/{id}