api-organization
Explains the standardized API organization pattern for this codebase. Use when creating new API endpoints, API clients, or modifying existing API structure. Covers the 5-file system (endpoint-types, endpoints, api-client, admin-api-client, protected-endpoints), role-based access patterns (admin vs regular users), and TypeScript type safety across the API layer. All API code lives in src/lib/api/ following this exact pattern.
What this skill does
# API Organization Pattern
This skill defines the standardized API organization pattern used throughout this codebase. All external API integrations follow the same 5-file structure for consistency, type safety, and maintainability.
## When to Use This Skill
Use this skill when:
- Creating new API endpoints or integrations
- Adding new API categories or domains
- Implementing role-based API access (admin vs regular users)
- Modifying existing API structure
- Setting up authentication for API calls
- Creating type-safe API wrappers
## Core Principles
1. **Single Source of Truth** - All API URLs defined once in `endpoints.ts`
2. **Type Safety** - Full TypeScript coverage from params to responses
3. **Role-Based Access** - Separate clients for regular vs admin endpoints
4. **Centralized Auth** - Authentication handled automatically by clients
5. **DRY Code** - Reusable client functions, no duplicate endpoint definitions
## The 5-File System
All API code lives in `src/lib/api/` with exactly these files:
```
src/lib/api/
├── endpoint-types.ts # TypeScript types for all endpoints
├── endpoints.ts # URL definitions organized by domain
├── api-client.ts # Generic authenticated API client
├── admin-api-client.ts # Admin-only API client with role checks
└── protected-endpoints.ts # Type-safe wrapper functions
```
### File Purposes
**1. endpoint-types.ts**
- Define all TypeScript interfaces for API data
- Organize types by domain (e.g., audiences, instances, membership)
- Include param types, response types, and request body DTOs
- Provide utility types for extracting types
See `references/endpoint-types-pattern.md` for detailed structure.
**2. endpoints.ts**
- Define all API endpoint URLs in one place
- Organize by feature/domain matching types
- Use functions that accept parameters and return URLs
- Support environment variable base URLs
See `references/endpoints-pattern.md` for detailed structure.
**3. api-client.ts**
- Generic API client with automatic authentication
- Error parsing and handling
- Support for GET, POST, PUT, DELETE methods
- Server-side only ('use server')
See `references/api-client-pattern.md` for implementation.
**4. admin-api-client.ts**
- Admin-specific API client
- Role validation (Admin/SuperAdmin groups)
- Permission checking functions
- Throws AdminAuthError if unauthorized
See `references/admin-api-client-pattern.md` for implementation.
**5. protected-endpoints.ts**
- Type-safe wrapper functions combining URLs + types + clients
- Organized to match endpoint-types structure
- Provides clean import: `import { api } from '@/lib/api/protected-endpoints'`
- No 'use server' directive (exports objects)
See `references/protected-endpoints-pattern.md` for detailed structure.
## Authentication System
This application uses **Supabase Auth** for authentication. All API requests require authentication via Supabase access tokens.
### Supabase Client Structure
```
src/lib/supabase/
├── client.ts # Browser-side Supabase client
├── server.ts # Server-side Supabase client (RSC, Server Actions)
└── middleware.ts # Middleware helper for auth cookie refresh
```
### Auth Flow
1. User authenticates via Supabase (email/password, OAuth, etc.)
2. Supabase stores session in httpOnly cookies
3. Middleware refreshes session on every request
4. Server components/actions use `createClient()` from `server.ts`
5. API client extracts access token from session automatically
See `references/supabase-auth-integration.md` for detailed implementation.
## Role-Based Access Pattern
### Regular User Endpoints
Use `api-client.ts` functions with automatic Supabase auth:
```typescript
import { apiGet, apiPost } from '@/lib/api/api-client';
// Access token extracted from Supabase session automatically
const data = await apiGet<ResponseType>(url);
```
### Admin-Only Endpoints
Use `admin-api-client.ts` functions with role validation:
```typescript
import { adminApiRequest, checkAdminPermission } from '@/lib/api/admin-api-client';
// Validate admin access first (checks user role from database)
await checkAdminPermission(); // Throws if not admin
// Make admin API request
const data = await adminApiRequest<ResponseType>(url, options);
```
### Admin Roles
Admin roles are stored in the `users` table:
- `users.role` = `'admin'` - Standard admin access
- `users.role` = `'member'` - Regular user access
First user in a family is automatically assigned admin role.
## Adding New API Endpoints
Follow this exact order when integrating a new API into the application:
### Step 1: Define Types in endpoint-types.ts
```typescript
// 1. Define response type(s)
export interface ResourceItem {
id: string;
name: string;
// ... other fields from your API response
}
// 2. Define request DTO(s) for mutations
export interface CreateResourceDto {
name: string;
// ... fields required to create
}
// 3. Add parameter types to EndpointParams interface
export interface EndpointParams {
// ... existing domains
resources: {
list: void; // No params needed
get: { id: string }; // Requires ID
create: void; // Body in request, not params
update: { id: string };
delete: { id: string };
};
}
// 4. Add response types to EndpointResponses interface
export interface EndpointResponses {
// ... existing domains
resources: {
list: ResourceItem[];
get: ResourceItem;
create: ResourceItem;
update: ResourceItem;
delete: void;
};
}
// 5. Add request body types to EndpointBodies interface (if needed)
export interface EndpointBodies {
// ... existing domains
resources: {
create: CreateResourceDto;
update: CreateResourceDto;
};
}
```
### Step 2: Define URLs in endpoints.ts
```typescript
export const API_ENDPOINTS = {
// ... existing categories
resources: {
list: () => `${API_BASE}/api/resources`,
get: (id: string) => `${API_BASE}/api/resources/${id}`,
create: () => `${API_BASE}/api/resources`,
update: (id: string) => `${API_BASE}/api/resources/${id}`,
delete: (id: string) => `${API_BASE}/api/resources/${id}`,
},
};
```
### Step 3: Add Wrapper in protected-endpoints.ts
```typescript
export const api = {
// ... existing domains
resources: {
async list(): Promise<ResourceItem[]> {
return apiGet<ResourceItem[]>(
API_ENDPOINTS.resources.list()
);
},
async get(id: string): Promise<ResourceItem> {
return apiGet<ResourceItem>(
API_ENDPOINTS.resources.get(id)
);
},
async create(data: CreateResourceDto): Promise<ResourceItem> {
return apiPost<ResourceItem, CreateResourceDto>(
API_ENDPOINTS.resources.create(),
data
);
},
async update(id: string, data: CreateResourceDto): Promise<ResourceItem> {
return apiPut<ResourceItem, CreateResourceDto>(
API_ENDPOINTS.resources.update(id),
data
);
},
async delete(id: string): Promise<void> {
return apiDelete<void>(
API_ENDPOINTS.resources.delete(id)
);
},
},
};
```
### Step 4: Use in Application Code
```typescript
'use server';
import { api } from '@/lib/api/protected-endpoints';
// In a server component or server action
const resources = await api.resources.list();
const resource = await api.resources.get(id);
const newResource = await api.resources.create({
name: 'New Resource'
});
```
## Naming Conventions
### Endpoint Operations
- `list` / `listAll` - GET multiple items
- `get` - GET single item
- `create` - POST new item
- `update` - PUT/PATCH existing item
- `delete` - DELETE item
### Type Naming
- Response types: PascalCase describing entity (e.g., `AudienceListItem`)
- DTOs: PascalCase with suffix (e.g., `CreateUserDto`, `UpdateSettingsDto`)
- Interfaces match plural for collections, singular for items
## Error Handling
All API clients handle errors automatically:
```typescript
try {
const data = aRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.