backend-scaffolding
Skill1 starsChanged 10 months agoMITView on GitHub
Scaffold a Koa-based backend server with standard structure including config, logging, routes, models, and database setup. Use when asked to "create a backend", "scaffold backend", "set up an API server", or "initialize backend structure".
- Reads credentials
- Installs packages
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skill-creatorSkill
- backend-ai-agentSkill
- backend-ai-toolsSkill
- backend-auth-clerkSkill
- backend-compressionSkill
- backend-metricsSkill
- backend-model-creationSkill
- backend-route-creationSkill
- backend-websocketSkill
- frontend-auth-clerkSkill
- frontend-hooks-creationSkill
- frontend-scaffoldingSkill
- new-project-scaffoldingSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 147
Config: Always use config object, never process.env directly
- Very specific: line 148
Logging: Use createLogger('module-name'), never console.log
- Very specific: line 149
Routes: Use koa-zod-router with Zod schemas for validation
- Very specific: line 150
Models: Use generateId() for IDs, stripId transform for JSON output
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Backend Scaffolding
Scaffold a Koa-based backend server with configuration, logging, routing with Zod validation, Mongoose models, and database connectivity.
Structure Overview
apps/backend/src/
├── config/
│ └── index.ts # Centralized configuration (env vars)
├── lib/
│ └── logger/
│ └── index.ts # Pino logger with pretty printing
├── models/
│ ├── _utils.ts # Model utilities (generateId, stripId)
│ ├── db.ts # MongoDB connection
│ └── {Model}.ts # Mongoose models
├── routes/
│ └── {resource}.ts # koa-zod-router routes
└── main.ts # Application entry pointInstallation
npm install koa @koa/cors koa-bodyparser koa-mount koa-static koa-zod-router mongoose pino zod uuid
npm install -D @types/koa @types/koa__cors @types/koa-bodyparser @types/koa-mount @types/koa-static pino-prettyFor WebSocket support: npm install koa-websocket @types/koa-websocket
Implementation Steps
1. Config Module (config/index.ts)
Centralize all environment variables. Never use process.env directly outside this file.
const isDev = process.env.NODE_ENV !== 'production';
const config = {
isDev,
port: process.env.PORT || 3333,
mongo: {
database: process.env.MONGO_DATABASE || 'myapp',
protocol: process.env.MONGO_PROTOCOL || 'mongodb',
host: process.env.MONGO_HOST || 'localhost:27017',
username: process.env.MONGO_USERNAME || '',
password: process.env.MONGO_PASSWORD || '',
},
logging: {
level: process.env.LOG_LEVEL || (isDev ? 'debug' : 'info'),
routeLogging: process.env.ROUTE_LOGGING !== 'false',
},
};
export default config;2. Logger Module (lib/logger/index.ts)
import pino from 'pino';
import config from '../../config';
export const logger = pino({
level: config.logging.level,
transport: config.isDev
? { target: 'pino-pretty', options: { colorize: true, translateTime: 'SYS:standard', ignore: 'pid,hostname' } }
: undefined,
});
export const createLogger = (name: string) => logger.child({ name });
export default logger;3. Model Utilities (models/_utils.ts)
import { v4 as uuidv4 } from 'uuid';
export const generateId = (): string => uuidv4();
export const stripId = (_doc: unknown, ret: Record<string, unknown>) => {
delete ret._id;
return ret;
};4. Database Connection (models/db.ts)
import mongoose from 'mongoose';
import config from '../config';
import { createLogger } from '../lib/logger';
const log = createLogger('db');
export async function init() {
const user = config.mongo.username && config.mongo.password
? `${encodeURIComponent(config.mongo.username)}:${encodeURIComponent(config.mongo.password)}@`
: '';
const connectionString = `${config.mongo.protocol}://${user}${config.mongo.host}/${config.mongo.database}`;
await mongoose.connect(connectionString);
log.info({ database: config.mongo.database }, 'Connected to MongoDB');
}5. Models, Routes, and Main Entry Point
See references/examples.md for complete code examples including:
- Example Mongoose model with proper typing
- Example routes with Zod validation (CRUD operations)
- Main entry point with middleware setup
- Shared types definition
Environment Variables
PORT=3333
NODE_ENV=development
MONGO_DATABASE=myapp
MONGO_PROTOCOL=mongodb
MONGO_HOST=localhost:27017
MONGO_USERNAME=
MONGO_PASSWORD=
LOG_LEVEL=debug
ROUTE_LOGGING=trueChecklist
- Install dependencies:
npm install - Start MongoDB:
docker compose up -dor local MongoDB - Set environment: Copy
.env.exampleto.env.local, rundirenv allow - Start backend:
just serve-backend - Test health:
curl http://localhost:3333/api - Test CRUD: See examples in references/examples.md
Best Practices
- Config: Always use
configobject, neverprocess.envdirectly - Logging: Use
createLogger('module-name'), neverconsole.log - Routes: Use
koa-zod-routerwith Zod schemas for validation - Models: Use
generateId()for IDs,stripIdtransform for JSON output - Types: Define shared types in
libs/types, import via@{project}/types - Errors: Return structured error responses with appropriate status codes
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

