api-organization
БесплатноБез исполняемых скриптовНе проверенExplains the standardized API organization pattern for this codebase. Use when creating new API endpoints, API clients, or modifying existing API structure…
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
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
- Single Source of Truth - All API URLs defined once in
endpoints.ts - Type Safety - Full TypeScript coverage from params to responses
- Role-Based Access - Separate clients for regular vs admin endpoints
- Centralized Auth - Authentication handled automatically by clients
- 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
- User authenticates via Supabase (email/password, OAuth, etc.)
- Supabase stores session in httpOnly cookies
- Middleware refreshes session on every request
- Server components/actions use
createClient()fromserver.ts - 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:
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:
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 accessusers.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
// 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 Endpoin
Установить api-organization в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл 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.
Как установить скилл api-organization?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл api-organization запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic