Api backend
Skill undp/carbon-footprint-program/.claude/skills/api-backend
Backend conventions for apps/api (Fastify + Prisma). Use when building or modifying an API endpoint — feature structure, efficient Prisma queries, transactions, helper placement, and the packages/types layout.From its SKILL.md
npx -y skills add undp/carbon-footprint-program --skill api-backendAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.5 KB, as published. Nobody here has run it
API & Backend Rules
Feature structure
Follow the existing pattern — route.ts → handler.ts → service.ts (→ helpers.ts if needed) per feature, under apps/api/src/features/.
Efficient database usage
Endpoints must be efficient and mindful that datasets grow over time. Apply these principles in order of preference:
- Push logic to the database: use aggregations, filters, and calculations at the query level (
groupBy,count,_sum, Views as last resort) instead of fetching raw rows and processing in memory. - Parallelize independent queries: use
Promise.allorprisma.$transactionto run independent queries concurrently instead of sequentially. - Avoid overfetching: use
selectto retrieve only the fields you need. The dataset will grow and overfetching will degrade performance. - Use
includewisely: prefer a single query withincludeover multiple sequential queries, but only include relations that are actually needed.
Transactions
When an endpoint performs validations followed by updates (read-then-write), wrap them in a prisma.$transaction to avoid TOCTOU (time-of-check to time-of-use) race conditions. Use the interactive form (prisma.$transaction(async (tx) => { ... })) so that all reads and writes share the same transaction context and data stays consistent.
Helper functions
Feature-specific helpers go in a separate helpers.ts within the feature directory, not inside service.ts. Keep service.ts focused on business logic and database operations. Promote a helper to the shared apps/api/src/helpers/ directory only when reuse is actually observed — never speculatively.
Types package structure (packages/types/src/)
Organized by domain (e.g., organizations/, carbonInventories/). Each domain contains:
schemas.ts+types.tsat the domain root for shared schemas/types.app/and/oradmin/subfolders to separate public and admin endpoints.- Inside each subfolder, one directory per endpoint (e.g.,
app/getOrganizationById/) with its ownschemas.tsandtypes.tsfor params, query, body, and response. - An
index.tsat each level to re-export everything.
See also the typescript-typing, api-authorization, and error-handling skills.