InsForge backend
Use this skill when contributing to InsForge's backend package. This is for maintainers editing backend routes, services, providers, auth, database logic, realtime, schedules, or backend tests in the InsForge monorepo.
install
source · Clone the upstream repo
git clone https://github.com/InsForge/InsForge
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/InsForge/InsForge "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.claude/skills/insforge-dev/backend" ~/.claude/skills/insforge-insforge-backend-562495 && rm -rf "$T"
manifest:
.claude/skills/insforge-dev/backend/SKILL.mdsource content
InsForge Dev Backend
Use this skill for
backend/ work in the InsForge repository.
Scope
backend/src/api/**backend/src/services/**backend/src/providers/**backend/src/infra/**backend/tests/**
Working Rules
-
Keep the route -> service -> provider/infra split intact.
- Routes handle auth, parsing, validation, and delegation.
- Services own business logic and orchestration.
- Providers and infra wrap external systems or lower-level integrations.
- Service layer code should be the only layer that interacts with the core PostgreSQL database.
- Do not put direct database access in routes.
- Do not bypass services when reading from or writing to Postgres.
-
Follow backend conventions.
- Use ESM-style
import specifiers in TypeScript source..js - InsForge's core database is PostgreSQL.
- InsForge currently runs as a single-instance server, so be careful about introducing logic that assumes distributed coordination, cross-instance locking, or background worker separation.
- Reuse shared schemas from
when contracts cross packages.@insforge/shared-schemas - Use
plussafeParse
for invalid input.AppError - Return successful results through
.successResponse - Preserve existing auth middleware patterns such as
,verifyAdmin
, andverifyUser
.verifyApiKey - Never use the TypeScript
type. Prefer precise interfaces, schema-derived types,any
, or constrained generics.unknown - For schema changes, write a new migration file instead of editing database structure manually.
- Put schema changes under
.backend/src/infra/database/migrations/
- Use ESM-style
-
Write idempotent migrations. Every SQL migration must be safe to re-run.
- Use
,CREATE TABLE IF NOT EXISTS
,CREATE INDEX IF NOT EXISTS
.ADD COLUMN IF NOT EXISTS - Never use bare
— it fails if the target name already exists. Wrap renames in aALTER TABLE ... RENAME TO
block that checksDO
for both source and target.information_schema.tables - Always
beforeDROP TRIGGER IF EXISTS
.CREATE TRIGGER - Guard data migrations and
behindDROP COLUMN
checks when the column may already be gone.information_schema.columns - Use
orON CONFLICT
for seedWHERE NOT EXISTS
statements.INSERT
- Use
-
Preserve existing behavior around mutation flows.
- Keep audit logging when surrounding routes already log state changes.
- Keep error handling flowing through shared middleware.
- Do not introduce a new response envelope unless the existing feature already uses one.
- For critical flows with multiple dependent database writes, use an explicit transactional process so the whole operation succeeds or fails together.
- Be especially careful with transactions around auth, secrets, billing-like usage updates, schema changes, and any flow that would leave the system inconsistent if partially applied.
-
Always write unit tests for new code.
- Every new feature, migration, service, or bug fix should have accompanying unit tests.
- For migrations, write tests that validate SQL structure and idempotency guards (see
for the pattern).tests/unit/redirect-url-whitelist-migration.test.ts - For services, test business logic and error cases.
- Run the full test suite before submitting work:
.cd backend && npm test
Validation
cd backend && npm testcd backend && npm run build
For contract changes, also validate
packages/shared-schemas/ and any affected dashboard consumers.