AI Native Architecture

Built for the Age of AI Agents

This boilerplate is organized for humans and autonomous coding agents. Repository-level guidance in AGENTS.md combines with modular SKILL.md packages so tools can discover intent quickly, load deeper instructions only when needed, and execute project conventions consistently across Claude Code, Codex, OpenCode, and GitHub Copilot.

Claude CodeCodexOpenCodeGitHub Copilot

AGENTS.md Specification

Project-level operating manual: architecture, workflows, constraints, and quality bars shared by every agent.

AGENTS.md

AGENTS.md

This document provides comprehensive instructions for AI coding agents to work effectively on the AI SaaS Boilerplate project. It covers the architecture, setup, development workflow, and coding conventions.

1. Project Overview

AI SaaS Boilerplate is an AI-powered SaaS platform built as a monorepo. It provides intelligent web search, deep research capabilities, document creation, audio-to-text processing, and document comparison features.

1.1. Architecture

The repository is managed by Turborepo and Bun.

  • Applications (apps/):

    • app: The core Next.js application (Dashboard, Chat, Projects, Tools). Handles AI streaming, user data, and search workflows.
    • admin: Internal admin dashboard for moderation, user management, and analytics. Includes chat/message flagging system.
    • web: The public marketing site.
  • Packages (packages/):

    • @ai/db: PostgreSQL schema and queries (Drizzle ORM).
    • @ai/auth: Authentication logic (Better Auth).
    • @ai/ui: Shared UI components (Shadcn UI + Tailwind v4).
    • @ai/i18n: Internationalization (next-intl). Supports English and Russian.
    • @ai/tracing: Distributed tracing infrastructure for workflow observability.
    • @ai/email: Transactional emails (React Email).
    • @ai/kv: Redis client and Rate Limiting.
    • @ai/storage: S3/MinIO client for file management.
    • @ai/analytics: OpenPanel integration for user analytics.
    • @ai/jobs: Background jobs (BullMQ + Redis). Worker system for scheduled and async tasks.
    • @ai/logger: Structured logging (Pino) + OpenTelemetry metrics export.
    • @ai/billing: Usage tracking, cost calculation, limit checking, and subscription management.
    • @ai/stripe: Stripe payment gateway integration.
    • @ai/memory: Memory and context management (Qdrant + Mem0AI). Vector storage for conversation memory.
    • @ai/converter: Document conversion utilities (JSZip). File format transformations.

1.2. Technology Stack

  • Runtime: Bun 1.1.26
  • Framework: Next.js 16+ (App Router)
  • Styling: Tailwind CSS v4 (Configuration in CSS variables, not JS config)
  • Database: PostgreSQL 17 + Drizzle ORM 0.44
  • Auth: Better Auth 1.3 (Magic Links, Phone OTP)
  • AI: Vercel AI SDK v6 (Core + React), Groq, OpenAI, DeepSeek
  • Search/Scraping: SearXNG (Self-hosted), BrowserUse (Scraping API)
  • Payment Processing: Stripe
  • Background Jobs: BullMQ + Redis
  • Memory/RAG: Qdrant (Vector DB) + Neo4j (Graph DB) + Mem0AI
  • Observability: OpenTelemetry + SigNoz (metrics export)
  • Internationalization: next-intl (English default, Russian supported)
  • Infrastructure: Docker Compose (PostgreSQL, Redis, MinIO, SearXNG, MailDev, unstructured-api, Qdrant, Neo4j, converter, optional worker service)

2. Development Workflow

2.1. Package Management

Always use Bun. Do not use npm or yarn.

bun install

Adding dependencies to packages:

The root package.json is private and should only have devDependencies. Always declare dependencies in the specific package that needs them.

IMPORTANT: The --filter flag does NOT work for adding dependencies to specific packages. You must cd into the package directory:

# CORRECT: Navigate to package and add dependency
cd packages/billing
bun add js-tiktoken

# Add dev dependency
cd apps/app
bun add -D @types/node

Then run:

bun install

DO NOT add dependencies to root package.json — it should only contain devDependencies for tooling (biome, husky, turbo, typescript).

2.2. Running the Project

Start the development environment:

# 1. Start backing services
docker compose up -d

# 2. Run migrations (if needed)
bun db:migrate

# 3. Start dev server
bun dev

2.3. Database Management

Schema changes must be made in packages/db/src/schema.ts.

# Push changes for prototyping (destructive)
bun db:push

# Generate migration files (production)
bun db:generate

# Apply migrations
bun db:migrate

2.4. Background Jobs

Technology: BullMQ + Redis (NOT Trigger.dev)

Location: packages/jobs/

Architecture:

  • worker.ts: Main worker entry point
  • src/workers/: Individual worker implementations
  • src/schedulers/: Scheduled job registration
  • Dockerfile for containerized worker deployment

Available Workers:

  1. hello-world: Test/example worker
  2. audio-processing: Audio-to-text processing
  3. file-indexing: File indexing for search/RAG
  4. log-cleanup: Database log cleanup and maintenance

Running Workers:

# Development (local)
bun run dev:worker

# Development (watch mode)
bun --watch run worker.ts

# Production (Docker)
docker compose --profile worker up -d

Adding a New Job:

  1. Create worker in packages/jobs/src/workers/my-worker.ts
  2. Register in worker.ts
  3. Define job types and queue configuration
  4. Queue from app: await myQueue.add("job-name", { data })

3. Architectural Patterns & Conventions

3.1. Server Actions (Mutations & Data)

We use next-safe-action located in apps/app/src/actions/.

Pattern:

  1. Define Schema: In schema.ts (Zod).
  2. Define Logic: In actions.ts.
  3. Use Raw Helpers: Complex DB logic goes into raw.ts to be reusable.
  4. Clients:
    • authActionClient: For authenticated user actions.
    • actionClient: For public actions.

Example:

// apps/app/src/actions/project/actions.ts
export const createProjectAction = authActionClient
  .inputSchema(createProjectSchema)
  .outputSchema(getUserProjectOutputSchema)
  .metadata({ name: "create-project" })
  .action(async ({ parsedInput, ctx: { user } }) => {
    // Logic here
  });

3.2. AI & Chat Architecture

The chat implementation (apps/app/src/app/api/chat/route.ts) is complex and sophisticated. This section breaks down its modular architecture.

3.2.1. Overview

Key Components:

  1. Resumable Streams: We use resumable-stream to handle network interruptions
  2. Handler-Based Architecture: Modular handlers for different execution paths
  3. Memory System: Conversation memory with Qdrant + Neo4j integration
  4. Tracing: Distributed tracing via @ai/tracing for observability
  5. Usage Tracking: Automatic token tracking for billing and metrics

Complexity Note: The AI system has multiple execution paths with conditional routing based on user settings and workflow classification.

3.2.2. Handler-Based Architecture

The AI system uses a modular handler architecture in apps/app/src/lib/ai/handlers/:

Handlers:

  1. search-classifier.ts: Classifies search requests and determines execution path
  2. search-plan-handler.ts: Generates search execution plans
  3. search-agent-handler.ts: Executes search workflows (search → scrape → process)
  4. clarification-handler.ts: Manages clarification questions for ambiguous intent
  5. deep-search-handler.ts: Manages deep research with extreme_search integration
  6. final-reasoning-handler.ts: Generates final responses from gathered context
  7. rerank-handler.ts: Reranks search results for relevance
  8. document-creation-handler.ts: Handles document/artifact creation and editing
  9. complexity-detector.ts: Auto-routes complex questions to deep search based on heuristics
  10. deep-search-document-handler.ts: Creates documents from deep research results
  11. document-processing-handler.ts: Prepares messages with file processing progress

Request Flow:

  1. Request arrives at /api/chat/route.ts
  2. Check usage limits (@ai/billing)
  3. Optimize messages for context window (summarization if needed)
  4. Build memory context (if enabled)
  5. Complexity detection: Auto-route to deep search if complex patterns detected
  6. Evaluate deep search decision: Determine if deep research is needed
  7. If deepResearch enabled or auto-triggered:
    • Ask clarification if needed
    • handleDeepSearch() → Optional: executeDeepSearchDocumentCreation() → RETURN
  8. If standard mode:
    • classifySearchRequest() → determine path
    • If document creation → Optional: executeSearchForContext()executeDocumentCreation() → RETURN
    • Else → executeSearchAgent()executeFinalReasoning()
  9. Clarification questions can interrupt at any decision point
  10. Memory extraction runs post-response (fire-and-forget)

3.2.3. Memory System

Location: apps/app/src/lib/ai/memory/

Purpose: Manages conversation memory and context for personalized responses.

Components:

  • context-builder.ts: Builds memory context from previous conversations
  • extraction-handler.ts: Extracts and stores memories from conversations
  • summarization-handler.ts: Handles message summarization for context windows

Memory Scopes (via @ai/memory):

  • Chat-scoped: Memories tied to specific conversations
  • Project-scoped: Memories shared across all chats in a project
  • File content: Indexed file contents for RAG

Integration:

  • Uses @ai/memory package (Qdrant + Mem0AI)
  • Memory context injected into system prompts
  • Memories extracted after response generation (fire-and-forget)
  • High-importance facts auto-promoted to project scope
  • Enhanced search with relevance filtering

3.2.4. Usage Tracking & Billing Integration

Location: apps/app/src/lib/ai/middleware/usage-tracking.ts

Automatic Token Tracking: Middleware intercepts all AI SDK calls for billing and metrics:

  1. Middleware: usageTrackingMiddleware on all model clients
  2. Helper: withUsageTracking(userId, operation, opts) in providerOptions
  3. Dual Recording:
    • @ai/billing: Usage limits and cost calculation
    • OpenTelemetry: Metrics export to SigNoz

Tracked Operations:

  • chat: Standard messages
  • deep_search: Deep research
  • classifier: Workflow classification
  • workflow_execution: Tool execution
  • deep_search_synthesis: Final synthesis
  • prompt_enhancement: AI-powered prompt improvement

Example:

const { object } = await generateObject({
  model: getGenerateObjectModel(),
  schema: MySchema,
  providerOptions: {
    groq: getDefaultGroqOptions(),
    ...withUsageTracking(userId, "classifier", { chatId }),
  },
});

Pre-request Limits: /api/chat/route.ts calls checkUsageLimits() before processing.

3.2.5. Tools & Prompts

Core Tools (apps/app/src/lib/ai/tools.ts):

  1. search: Multi-query web search via SearXNG with site filtering
  2. scrape: Website content extraction via BrowserUse API with iterative chunking
  3. reasoning: Final answer/analysis tool (marks completion)

Domain-Specific Tools (apps/app/src/lib/ai/tools/):

  • artifact-tools.ts: Document creation and editing

    • createArtifactTool(): Creates new documents
    • createUpdateArtifactTool(): Updates existing documents
  • document-tools.ts: File attachment handling

    • extractFileAttachmentsFromMessages(): Extracts file content from messages

Tool Factories:

  • createSearchTool(contexts): Creates search with context filtering
  • createScrapeWebsiteTool(usedUrls, query, writer, tracking): Creates scraping with deduplication

Prompts:

  • Main: apps/app/src/lib/ai/prompts.ts (systemPrompt, titlePrompt, classifierPrompt)
  • Additional prompts: codePrompt, sheetPrompt, updateDocumentPrompt, searchClassifierPrompt

Model Configuration (apps/app/src/lib/ai/clients.ts):

  • Primary: groq("openai/gpt-oss-120b") with usage tracking middleware
  • Fallback: openai("gpt-5-nano") with usage tracking middleware
  • Unwrapped: openai("gpt-5-nano") without tracking (for tool repair)

Extreme Search: Location: apps/app/src/lib/ai/extreme-search.ts

Multi-step autonomous research workflow with planning, execution, and synthesis phases.

3.3. Artifact System

Location: apps/app/src/lib/ai/artifacts/

Purpose: Manages document creation, editing, and patching.

Components:

  • text-handler.ts: Handles text document creation
  • patch-handler.ts: Handles document updates via patches
  • index.ts: Exports and utilities

Integration:

  • Used by document-creation-handler.ts
  • Tools in tools/artifact-tools.ts
  • API route at /api/artifact/*

3.4. UI & Styling (Tailwind v4)

Crucial: This project uses Tailwind CSS v4.

  • Configuration: Theme variables are defined in packages/ui/src/globals.css using the @theme directive.
  • Do not look for tailwind.config.js for theme extension.
  • Dark Mode: Handled via oklch color variables and the .dark class.

Example globals.css:

@theme inline {
  --color-background: var(--background);
  --color-sidebar: var(--sidebar);
  /* ... */
}

3.5. State Management (SWR)

Client-side data fetching uses SWR.

  • Global app state is managed in apps/app/src/components/use-app-state.ts.
  • Use useDashboardApp() hook to access global state (chats, projects, modals).

3.6. File Storage

  • Uploads: Use the API route /api/files/upload-url to get a presigned URL.
  • Storage: Files are stored in MinIO (S3 compatible).
  • Database: File metadata is stored in the file table in Postgres.

3.7. Billing & Subscription System

Location: packages/billing/

Core Modules:

  1. cost-calculator.ts: Calculates LLM usage costs in microcents
  2. limit-checker.ts: Checks if user is within plan limits
  3. usage-tracker.ts: Records and aggregates usage data
  4. types.ts: Plan definitions and limit structures

Integration Points:

  • /api/billing/*: Plans, subscriptions, usage, payments, webhooks
  • /api/chat/route.ts: Pre-request limit checking via checkUsageLimits()
  • middleware/usage-tracking.ts: Automatic token recording
  • @ai/stripe: Payment processing

Plan Limits: Plans define limits for:

  • Messages per period
  • Deep searches per period
  • Max file size uploads
  • Token usage quotas

Usage Flow:

  1. User sends chat request
  2. checkUsageLimits() validates against plan
  3. Request processes if allowed
  4. usageTrackingMiddleware records tokens
  5. recordUsage() saves to database
  6. recordLLMUsage() exports to SigNoz

3.8. Internationalization (i18n)

Location: packages/i18n/

Technology: next-intl v4.8

Supported Locales:

  • en (English) - Default
  • ru (Russian)

Structure:

  • packages/i18n/src/config.ts: Locale configuration
  • packages/i18n/src/messages/: Package-level message definitions
  • apps/app/messages/: App-specific JSON translations
  • apps/admin/messages/: Admin-specific JSON translations

Usage:

import { useTranslations } from "next-intl";

function MyComponent() {
  const t = useTranslations("common");
  return <div>{t("greeting")}</div>;
}

3.9. Tracing System

Location: packages/tracing/

Purpose: Distributed tracing for AI workflow observability.

Key Components:

  • span-manager.ts: Span creation and lifecycle management
  • context.ts: Tracing context propagation
  • streaming.ts: Real-time span/trace updates via SSE

Wrappers:

  • traceHandler(): Wrap AI handlers
  • traceAction(): Wrap server actions
  • withRouteTracing(): Wrap API routes

Integration: Traces are stored in PostgreSQL and can be viewed in the admin dashboard at /traces.

4. Infrastructure & Services

4.1. Docker Services

docker-compose.yml services:

  • postgres: PostgreSQL 17 (main database)
  • redis: Redis 7.4 (cache, rate limiting, BullMQ)
  • minio: S3-compatible object storage
  • createbuckets: MinIO bucket initialization
  • maildev: Email testing (captures outgoing emails)
  • searxng: Self-hosted search engine
  • unstructured-api: Document parsing API
  • qdrant: Vector database for memory/RAG system
  • neo4j: Graph database for memory relationships (Neo4j 5.26)
  • converter: Document converter service
  • worker: BullMQ background job processor (optional profile)

Commands:

# Start all services
docker compose up -d

# Start with worker
docker compose --profile worker up -d

# View logs
docker compose logs -f [service-name]

# Restart service
docker compose restart [service-name]

4.2. Observability & Monitoring

OpenTelemetry Integration: Location: packages/logger/src/

Logger Components:

  • pino-logger.ts: Structured logging setup
  • metrics-exporter.ts: OTLP metrics export to SigNoz
  • db-exporter.ts: Database log export for persistence
  • telegram-exporter.ts: Telegram notification export for alerts

Metrics Exported:

  • LLM usage (tokens, provider, model, operation, user, chat)
  • Token counts (input/output)
  • Per-user, per-operation aggregations

Functions:

  • initializeMetricsExporter(): Sets up OTLP export to SigNoz
  • recordLLMUsage(attributes, usage): Records LLM metrics
  • shutdownMetricsExporter(): Graceful shutdown
  • exportLogToDb(): Exports logs to database
  • sendTelegramAlert(): Sends critical alerts to Telegram

5. Coding Rules for Agents

  1. "Use Server": Always add "use server" at the top of Server Actions.
  2. Type Safety:
    • No any. Use Zod schemas for runtime validation.
    • Share types via apps/app/src/lib/types.ts.
  3. Imports:
    • Use @/ alias for app-local imports.
    • Use @ai/* for package imports.
  4. Error Handling:
    • Server Actions should return errors, not throw them (handled by next-safe-action).
    • UI should use sonner for toast notifications.
  5. Components:
    • Place page-specific components in apps/app/src/components/pages/.
    • Place shared/atomic components in packages/ui/src/components/.
  6. Internationalization:
    • The app defaults to English with Russian as secondary.
    • Use useTranslations() hook for UI text.
    • Add new strings to apps/app/messages/en.json and apps/app/messages/ru.json.
  7. Server Actions Pattern (Important):
    • The documented pattern (schema.ts, actions.ts, raw.ts) is IDEAL
    • Reality: Only project/ and chat/ actions fully follow this pattern
    • user/ actions: Direct action files (no raw.ts)
    • Guideline: Prefer full pattern for NEW actions, but adapt to existing conventions in each domain
  8. AI Usage Tracking (Critical):
    • Always wrap AI SDK calls with withUsageTracking() in providerOptions
    • Include: userId and operation type (required)
    • Optional: chatId, provider, model
    • Ensures proper billing and metrics export
  9. Background Jobs:
    • Use BullMQ for async/scheduled tasks (NOT Trigger.dev)
    • Define jobs in packages/jobs/src/workers/
    • Register in worker.ts
    • Jobs run in separate worker process (not Next.js)
  10. Payment Integration:
    • Use @ai/stripe for payment processing
    • Handle webhooks in /api/billing/webhook
    • Always verify webhook signatures (Stripe signature verification)
    • Stripe handles subscription renewals automatically
    • Use Stripe Customer Portal for self-service subscription management
  11. Memory System:
    • Use @ai/memory for storing/retrieving conversation memories
    • Memory context is built via context-builder.ts
    • Extraction happens post-response via extraction-handler.ts
  12. Tracing:
    • Use @ai/tracing wrappers for observability
    • Wrap handlers with traceHandler()
    • Wrap actions with traceAction()

6. Directory Structure Reference

Application Structure

apps/app/src/
├── actions/                # Server Actions
│   ├── chat/              # Chat actions (full pattern)
│   │   ├── schema.ts
│   │   ├── actions.ts
│   │   └── raw.ts
│   ├── project/           # Project management (full pattern)
│   │   ├── schema.ts
│   │   ├── actions.ts
│   │   └── raw.ts
│   ├── audio-processing/     # Audio Processing actions
│   │   ├── schema.ts
│   │   ├── actions.ts
│   │   └── raw.ts
│   └── user/              # User actions
│       ├── schema.ts
│       └── usage-action.ts
├── app/                   # Next.js App Router
│   ├── (dashboard)/       # Authenticated pages
│   ├── (public)/          # Public pages
│   └── api/               # API routes
│       ├── artifact/      # Artifact management
│       ├── auth/          # Better Auth endpoints
│       ├── billing/       # Plans, subscriptions, payments, webhooks
│       ├── chat/          # Chat streaming + resumable
│       ├── files/         # Upload/download
│       ├── tools/   # Audio Processing, comparison
│       └── share/         # Sharing functionality
├── components/            # React components
│   ├── message/           # Chat UI components
│   ├── pages/             # Page-specific components
│   ├── providers/         # Context providers
│   └── use-app-state.ts   # Global SWR state (useDashboardApp hook)
├── i18n/                  # App i18n configuration
│   ├── navigation.ts
│   ├── request.ts
│   └── routing.ts
├── messages/              # Translation files
│   ├── en.json
│   ├── ar.json
│   ├── de.json
│   ├── es.json
│   ├── fr.json
│   ├── pt.json
│   └── ru.json
└── lib/                   # Core utilities
    ├── ai/                # AI system (COMPLEX)
    │   ├── artifacts/     # Document creation/editing
    │   ├── config/        # Provider options
    │   ├── evaluation/    # Content evaluation
    │   ├── handlers/      # Handler architecture (11 handlers)
    │   ├── memory/        # Memory system
    │   ├── middleware/    # Usage tracking middleware
    │   ├── tools/         # Domain-specific tools
    │   ├── types/         # AI type definitions
    │   ├── utils/         # AI utilities
    │   ├── clients.ts     # Model clients (groq, openai)
    │   ├── extreme-search.ts  # Deep research engine
    │   ├── prompts.ts     # System prompts
    │   └── tools.ts       # Core tool definitions
    ├── auth.ts            # Better Auth setup
    ├── mappers.ts         # DB to UI type mappers
    └── types.ts           # Shared types

Admin Application Structure

apps/admin/src/
├── actions/              # Admin Server Actions
│   └── moderation/       # Chat/message moderation
├── app/                  # Next.js App Router
│   ├── (auth)/           # Admin authentication
│   ├── (dashboard)/      # Admin dashboard pages
│   │   ├── chats/        # Chat browsing & moderation
│   │   ├── traces/       # Trace viewing
│   │   ├── users/        # User management
│   │   ├── subscriptions/# Subscription tracking
│   │   ├── payments/     # Payment history
│   │   ├── usage/        # Usage analytics
│   │   └── logs/         # System logs
│   └── api/              # Admin API routes
├── components/           # Admin UI components
├── i18n/                 # Admin i18n configuration
├── messages/             # Admin translations
└── lib/                  # Admin utilities

Package Structure

packages/
├── analytics/         # OpenPanel integration
├── auth/              # Better Auth
├── billing/           # Usage tracking, limits, costs
├── converter/         # Document conversion (JSZip)
├── db/                # Drizzle ORM + PostgreSQL
├── email/             # React Email templates
├── i18n/              # Centralized internationalization
│   └── src/
│       ├── config.ts      # Locale configuration
│       ├── request.ts     # Server-side utilities
│       ├── navigation.ts  # Client-side navigation
│       └── messages/      # Package-level messages
├── jobs/              # BullMQ background jobs
│   ├── src/workers/   # Worker implementations
│   ├── worker.ts      # Main worker entry
│   └── Dockerfile     # Worker container
├── kv/                # Redis + rate limiting
├── logger/            # Pino + OpenTelemetry
├── memory/            # Memory/RAG system (Qdrant + Mem0AI)
├── storage/           # S3/MinIO client
├── tracing/           # Distributed tracing
│   └── src/
│       ├── span-manager.ts    # Span lifecycle
│       ├── context.ts         # Context propagation
│       ├── streaming.ts       # Real-time updates
│       └── wrappers/          # Handler/action wrappers
├── ui/                # Shared components (60+ components)
│   └── src/
│       ├── components/    # Shadcn components
│       └── globals.css    # Tailwind v4 config
└── stripe/            # Stripe payment gateway

7. Common Tasks

Working with UI Components

Adding a new UI Component:

  1. Create in packages/ui/src/components/my-component.tsx
  2. Export in packages/ui/package.json exports field
  3. Run bun build (or rely on Turbo)
  4. Import in app: import { MyComponent } from "@ai/ui/my-component"

Database Operations

Adding a Database Table:

  1. Edit packages/db/src/schema.ts
  2. Run bun db:generate (creates migration)
  3. Run bun db:migrate (applies migration)
  4. Add queries to packages/db/src/queries.ts if needed

Quick prototyping (destructive):

bun db:push  # Skip migrations, push schema directly

AI Logic Modifications

Modifying AI Logic:

  1. Tools: Edit apps/app/src/lib/ai/tools.ts or add to tools/ subdirectory
  2. Prompts: Edit apps/app/src/lib/ai/prompts.ts
  3. Chat flow: Edit apps/app/src/app/api/chat/route.ts
  4. Handlers: Edit apps/app/src/lib/ai/handlers/*
  5. Memory: Edit apps/app/src/lib/ai/memory/*

Adding a new AI Handler:

  1. Create apps/app/src/lib/ai/handlers/my-handler.ts
  2. Follow existing patterns (accept writer, log, tracking context)
  3. Use withUsageTracking() for all AI calls
  4. Integrate into /api/chat/route.ts main flow

Background Jobs

Creating a Background Job:

  1. Create worker: packages/jobs/src/workers/my-worker.ts
  2. Register in packages/jobs/worker.ts
  3. Export queue from package if needed
  4. Queue from app code:
    import { myQueue } from "@ai/jobs";
    await myQueue.add("job-name", { data });
    
  5. Run worker: bun run dev:worker

Adding Translations

Adding new translated strings:

  1. Add to apps/app/messages/en.json:
    {
      "myFeature": {
        "title": "My Feature",
        "description": "Description here"
      }
    }
    
  2. Add Russian translation to apps/app/messages/ru.json
  3. Use in component:
    const t = useTranslations("myFeature");
    return <h1>{t("title")}</h1>;
    

Infrastructure Management

Docker Services:

# Start all services
docker compose up -d

# Start with worker
docker compose --profile worker up -d

# View logs
docker compose logs -f postgres
docker compose logs -f redis
docker compose logs -f worker
docker compose logs -f qdrant
docker compose logs -f neo4j

# Restart service
docker compose restart searxng

# Stop all
docker compose down

Available services:

  • postgres, redis, minio, createbuckets, maildev, searxng, unstructured-api, qdrant, neo4j, converter, worker (optional)

API Routes Structure

apps/app/src/app/api/
├── artifact/          # Artifact management
│   ├── route.ts       # Create artifact (POST), Get artifact (GET)
│   ├── export/        # Export artifact to file (POST)
│   └── [id]/
│       ├── route.ts   # Get/update artifact (GET/PATCH)
│       └── patch/     # Apply patches to artifact (PATCH)
├── auth/              # Better Auth endpoints (auto-generated)
│   └── [...all]/
├── billing/           # Billing & subscription management
│   ├── plans/         # GET available plans
│   ├── subscription/  # GET/DELETE user subscription
│   ├── usage/         # GET usage stats
│   ├── checkout/      # POST create Stripe Checkout session
│   ├── portal/        # POST create Stripe Customer Portal session
│   └── webhook/       # POST Stripe webhooks
├── chat/              # AI chat streaming
│   ├── route.ts       # Main chat endpoint (POST)
│   └── [id]/
│       └── stream/    # Resumable stream endpoint (GET)
├── enhance-prompt/    # AI-powered prompt enhancement (POST)
├── files/             # File upload/download
│   ├── upload/        # Direct upload (POST)
│   ├── upload-url/    # Presigned URL generation (POST)
│   └── [id]/          # Get file by ID (GET)
├── tools/       # Domain tools
│   ├── compare/       # Document comparison (POST)
│   └── audio-processing/ # Audio processing
│       ├── route.ts   # Submit audio processing (POST)
│       ├── [id]/      # Get audio-processing status (GET)
│       └── export/    # Export processed output (POST)
└── share/             # Sharing functionality
    └── [token]/       # Share by token
        └── artifact/  # Get shared artifact (GET)

Key Endpoints:

Chat:

  • POST /api/chat - Send message, get streamed response
  • GET /api/chat/[id]/stream - Resume interrupted stream

Prompt Enhancement:

  • POST /api/enhance-prompt - AI-powered prompt improvement

Files:

  • POST /api/files/upload - Direct file upload
  • POST /api/files/upload-url - Get presigned S3 URL
  • GET /api/files/[id] - Download file by ID

Billing:

  • GET /api/billing/plans - Fetch subscription plans
  • GET /api/billing/subscription - Get user's subscription
  • DELETE /api/billing/subscription - Cancel subscription (via Stripe)
  • GET /api/billing/usage - Get usage statistics
  • POST /api/billing/checkout - Create Stripe Checkout session
  • POST /api/billing/portal - Create Stripe Customer Portal session
  • POST /api/billing/webhook - Handle Stripe webhooks

Artifacts:

  • POST /api/artifact - Create new artifact
  • GET /api/artifact/[id] - Get artifact by ID
  • PATCH /api/artifact/[id] - Update artifact
  • PATCH /api/artifact/[id]/patch - Apply patches to artifact
  • POST /api/artifact/export - Export artifact to file format

Tools:

  • POST /api/tools/compare - Document comparison (PDF, DOCX, DOC, TXT, MD)
  • POST /api/tools/audio-processing - Submit audio for processing
  • GET /api/tools/audio-processing/[id] - Get audio-processing status
  • POST /api/tools/audio-processing/export - Export audio-processing

Sharing:

  • GET /api/share/[token]/artifact - Get shared artifact by token (public, no auth)

Agent Skills Standard

Real skill packages with executable workflows, and optional agent metadata aligned with the agentskills.io specification.

Agent Skills
next-api-endpoint
SKILL.md
agents
openai.yaml
references
repo-paths.md
test-matrix.md
scripts
safe-action-mutations
SKILL.md
agents
openai.yaml
references
scripts
search-workflow-handlers
SKILL.md
agents
openai.yaml
references
assets
SKILLS-PATTERNS.md
SKILL.md
---
name: next-api-endpoint
description: Implement or update Next.js App Router API endpoints with typed request parsing, service boundaries, and tests.
---

# Next API Endpoint

## Overview
Use this skill when adding or changing HTTP handlers in `src/app/api/**/route.ts`.

## Inputs To Collect
- route path and HTTP method
- auth mode (public, optional, required)
- request schema (query, params, body)
- response shape and status codes
- validation and error mapping rules

## Workflow
1. Read `AGENTS.md` for project constraints and coding standards.
2. Define request and response contracts before writing handler logic.
3. Parse and validate with explicit schemas at API boundary.
4. Keep orchestration in route handler and business logic in service modules.
5. Add API tests for success, validation failure, auth failure, and upstream errors.

## Guardrails
- Keep route handlers thin and deterministic.
- Do not leak infrastructure concerns into domain logic.
- Avoid hidden defaults in request parsing.

## References
- `references/repo-paths.md`
- `references/test-matrix.md`
- `scripts/scaffold-endpoint.sh`
Progressive disclosure ready

Core Design Principles

Agentskills Spec

Precise Skill Triggers

Each skill description is written for reliable implicit activation and clear scope boundaries.

Progressive Disclosure

Keep SKILL.md concise, then load references, scripts, and assets only when tasks need them.

Deterministic Tooling

Bundle repeatable scripts for fragile steps and keep most workflows instruction-first.

Portable Skill Layout

Use a standards-aligned folder shape that works across Codex, Claude, and other skill-aware agents.