web-backend
БесплатноБез исполняемых скриптовНе проверенGuidelines for building backend services, API routes, and data access layers in the /web project using TypeScript, Supabase, and service-oriented architecture.
Об этом скилле
Web Backend Development Skill
This skill provides guidance for developing backend services and API routes in the /web project for CRAN/E.
Tech Stack
- TypeScript for type safety
- React Router v7 server-side capabilities (Vite SSR)
- Supabase for database access with generated types
- Zod for runtime validation
- TTLCache (@isaacs/ttlcache) for caching
- AI SDK (@ai-sdk/google) for embeddings
- MCP (Model Context Protocol) server implementation
Architecture Principles
Service Layer Pattern
All data access is organized into service classes with static methods:
- PackageService (
app/data/package.service.ts) - CRAN package operations - AuthorService (
app/data/author.service.ts) - Author/maintainer operations - SearchService (
app/data/search.service.ts) - Universal search - PackageInsightService (
app/data/package-insight.service.server.ts) - Download stats, trends - ArticleService (
app/data/article.service.server.ts) - Press/blog content - PageInsightService (
app/data/page-insight.service.ts) - Analytics
Generated Database Types
Always use the generated Supabase types from app/data/supabase.types.generated.ts:
import { Database, Tables } from "./supabase.types.generated";
// Type a specific table
type Package = Tables<"cran_packages">;
type Author = Tables<"authors">;
// Type the database client
import { createClient } from "@supabase/supabase-js";
export const supabase = createClient<Database>(url, key);
Regenerate types when schema changes:
npm run db.types # Requires Supabase CLI + credentials
Supabase Client Pattern
Single shared client instance (app/data/supabase.server.ts):
import { createClient } from "@supabase/supabase-js";
import { Database } from "./supabase.types.generated";
export const supabase = createClient<Database>(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY,
);
Always:
- Use typed queries with
from()and typed table names - Handle errors explicitly with
.errorchecks - Use
.maybeSingle()for nullable results,.single()for required results - Use
.select("*")or specific columns for type safety
Example query:
const result = await supabase
.from("cran_packages")
.select("*")
.eq("name", packageName)
.maybeSingle();
if (result.error || !result.data) {
return null;
}
return result.data;
Validation with Zod
Define schemas in *.shape.ts files:
import { z } from "zod";
export const packageNameSchema = z.string().min(1).max(300);
export const packageIdSchema = z.number().int().positive().min(1);
export type PackageSlug = z.infer<typeof packageNameSchema>;
Validate inputs at service boundaries:
static async getPackageByName(name: string) {
packageNameSchema.parse(name); // Throws if invalid
// ... proceed with query
}
Caching Strategy
Use TTLCache for expensive operations:
import TTLCache from "@isaacs/ttlcache";
import { hoursToMilliseconds, minutesToMilliseconds } from "date-fns";
class PackageService {
private static cache = new TTLCache<CacheKey, CacheValue>({
ttl: hoursToMilliseconds(6),
max: 1000,
});
static async getData(key: string) {
const cached = this.cache.get(key);
if (cached) return cached;
const data = await fetchData();
this.cache.set(key, data);
return data;
}
}
Cache keys: Use string literals or union types for type safety.
TTL guidelines:
- Sitemap/metadata: 6 hours
- Search results: 5 minutes
- Download stats: 6 hours
- Dynamic content: 1-5 minutes
Service Class Structure
export class ExampleService {
// Private static cache
private static cache = new TTLCache<CacheKey, CacheValue>({
ttl: hoursToMilliseconds(6),
});
// Static methods only (stateless)
static async getById(id: number) {
// 1. Validate input
idSchema.parse(id);
// 2. Check cache
const cached = this.cache.get(`id:${id}`);
if (cached) return cached;
// 3. Query database
const result = await supabase
.from("table_name")
.select("*")
.eq("id", id)
.maybeSingle();
// 4. Handle errors
if (result.error) {
slog.error("Query failed", { error: result.error, id });
return null;
}
// 5. Cache and return
if (result.data) {
this.cache.set(`id:${id}`, result.data);
}
return result.data;
}
}
API Route Patterns
Action-based API (POST)
File: app/routes/api.search._index.ts
import { ActionFunction } from "react-router";
import { SearchService } from "../data/search.service";
export const action: ActionFunction = async ({ request }) => {
const formData = await request.formData();
const intent = formData.get("intent");
if (intent === "all") {
const query = String(formData.get("q")).slice(0, 100);
const r
Установить web-backend в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл web-backend?
Guidelines for building backend services, API routes, and data access layers in the /web project using TypeScript, Supabase, and service-oriented architecture.
Как установить скилл web-backend?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл web-backend запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic