Skip to content
Back to skills

Api

ASecurity

**Template:** `.antigravity/templates/TEMPLATE_API_route.md` for full scaffold (GET/POST with auth, Zod, org scope). **Contracts:** `.antigravity/contracts/CONTRACTS.md` — invariants.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 24, 2026
developmenttypescriptapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 5 files and shows the line behind each finding

Scanned November 24, 2026

npx -y skills add iDorgham/Workspace-Factory --skill api --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/idorgham-api/badge)](https://www.skillsdirectory.com/skills/idorgham-api)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
type: Skill
subagents: [core-validator, integrity-bot]
agents: [master-guide, swarm-router]
dependencies: [core-orchestration, global-sync]
version: 1.0.0
---



# Workspace Factory API Routes

**Template:** `.antigravity/templates/TEMPLATE_API_route.md` for full scaffold (GET/POST with auth, Zod, org scope).
**Contracts:** `.antigravity/contracts/CONTRACTS.md` — invariants.

## Route Location

- `apps/client-dashboard/src/app/api/**/route.ts`
- Export `GET`, `POST`, `PUT`, `PATCH`, `DELETE` handlers

## Required Pattern (Every Protected Route)

```typescript
import { NextRequest, NextResponse } from 'next/server';
import { requireAuth } from '@/lib/require-auth';
import { prisma } from '@gate-access/db';

export async function GET(request: NextRequest) {
  const auth = await requireAuth(request);
  if (auth instanceof NextResponse) return auth;
  const { orgId, role } = auth;

  // Optional: rate limit
  // await rateLimit(request, { max: 10, window: '1m' });

  const data = await prisma.model.findMany({
    where: { organizationId: orgId, deletedAt: null },
  });

  return NextResponse.json(data);
}
```

## Auth Check

```typescript
const auth = await requireAuth(request);
if (auth instanceof NextResponse) return auth;
// auth: { sub, email, role, orgId }
```

## Role Check

```typescript
if (auth.role !== 'TENANT_ADMIN') {
  return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
```

## Input Validation (Zod)

```typescript
import { z } from 'zod';

const bodySchema = z.object({
  name: z.string().min(1).max(100),
  projectId: z.string().cuid().optional(),
});

const body = await request.json();
const parsed = bodySchema.safeParse(body);
if (!parsed.success) {
  return NextResponse.json(
    { error: 'Validation failed', details: parsed.error.flatten() },
    { status: 400 }
  );
}
const { name, projectId } = parsed.data;
```

## Rate Limiting

```typescript
import { rateLimit } from '@/lib/rate-limit';

await rateLimit(request, { max: 10, window: '1m' });
```

## CSRF (State-Changing Requests)

For POST/PUT/DELETE from web forms, include CSRF token. See `@/lib/csrf`.

## Error Responses

```typescript
return NextResponse.json(
  { success: false, message: 'Resource not found' },
  { status: 404 }
);
```

## Streaming/Export

```typescript
return new Response(csvString, {
  headers: {
    'Content-Type': 'text/csv; charset=utf-8',
    'Content-Disposition': `attachment; filename="export.csv"`,
  },
});
```

## Checklist

- [ ] requireAuth
- [ ] organizationId scope
- [ ] deletedAt: null filter
- [ ] Zod validation for body/query
- [ ] Rate limit if user-facing
- [ ] Proper status codes (400, 401, 403, 404)

**Reference:** `apps/client-dashboard/src/app/api/`, `.kiro/steering/api_development.md`

Files in this skill

  • core.py319 B
  • manifest.yaml154 B
  • skill.md2.7 KB
  • skill.md.meta.json773 B
  • tests/test_core.py263 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.