Laravel 12/13 + AI Features (LLM Orchestration, Embeddings & RAG)
Production-ready enterprise Laravel kit for building generative AI applications. Features structured LLM outputs, function/tool calling, PostgreSQL pgvector embeddings, semantic search, prompt injection defense, and asynchronous queue workers.
docker compose up -d
# Laravel 12/13 + AI Features (LLM Orchestration, Embeddings & RAG) — Claude Code Guidelines (CLAUDE.md)
# Auto-generated from rules/source/*.md by tools/transpiler.py. Do NOT edit directly.
## Quick Reference & Non-Negotiable Standards
### Framework and AI Architecture Conventions
> Architecture standards for Laravel 12/13 AI integrations.
# Framework and AI Architecture Conventions
## 1. Strict Typing and Contracts
- Always declare `declare(strict_types=1);` at the top of every PHP file.
- Code against abstract contracts (`AiServiceInterface`, `EmbeddingServiceInterface`) to enable swapping providers and mock testing.
- Return explicit types and typed DTOs from all service methods.
## 2. Directory Layout
- **AI Services**: `app/Services/Ai/` (LLM communication, prompt builders, tool executors).
- **Embeddings**: `app/Services/Embeddings/` (text chunking, vector generation).
- **DTOs**: `app/DTOs/` (typed request and response structures).
- **Jobs**: `app/Jobs/` (asynchronous embedding generation and index updates).
## 3. Never-List
- Never make synchronous LLM API calls during user-facing write mutations; dispatch to Redis queues.
| Design Token | Specification | Standard Enforcement |
|---|---|---|
| color.brand | #e85d26 (Orange status accent) | Status lights, active tabs, focus rings, primary CTA |
| color.surface.dark | #0A0A0B (Base) • #131316 (Raised) • #26262C (Hairline) | Dark-first showcase theme, hairline borders, no shadows |
| font.family.ui | Instrument Sans (14px base, tight scale) | Small and dense dashboard typography, zero AI slop |
| focus.ring | 2px #e85d26 outline, 2px offset | Universal high-visibility focus ring, WCAG 2.2 AA compliant |
Clone and Inspect
Clone repository, navigate to kits/laravel-ai-features, and start container services via docker compose.
Anchor AI Agent
Feed the Agent Bootstrap Prompt into Claude Code, Cursor, Codex, or Copilot. Agent consumes native rules and skills.
Verify Security Gates
Run automated CI evaluation. Security scanners assert zero vulnerabilities before merging features to production.
7-Part Installation & Setup Standard
1. Prerequisites Table
| Tool | Minimum Version | Check Command | Where to Get |
|---|---|---|---|
| Docker Engine | 24.0+ | docker --version | docker.com |
| Docker Compose | v2.20+ | docker compose version | Bundled with Docker |
| Git | 2.40+ | git --version | git-scm.com |
2. Quickstart Execution
git clone https://github.com/Umar-444/Techtalks-stack-kits.git cd Techtalks-stack-kits/kits/laravel-ai-features/starter cp .env.example .env docker compose up --build -d
3. Multi-Agent Rule Placement
4. Post-Install Verification Probes
Kit FAQ & Operational Details
How does PostgreSQL pgvector integrate with Eloquent in this Laravel kit? ↓
The kit defines an Eloquent model Document using a custom VectorCast attribute and a dedicated scopeCosineSimilarity() query builder method using the <=> operator, enabling native vector distance calculations in Eloquent without raw string concatenation.
How are structured outputs guaranteed from LLMs? ↓
The AiService utilizes JSON Schema definitions passed to the model's response_format parameter. The returned payload is then validated against typed PHP DTOs using Laravel's Validator before returning to the caller.
What defenses are in place against Prompt Injection and Jailbreaks? ↓
Input prompts are scanned against known adversarial patterns (instruction overrides, system prompt leak attempts, character smuggling), enclosed in explicit XML delimiters (
Can this kit run fully offline without third-party LLM APIs? ↓
Yes. The kit provides a MockAiProvider for offline development and testing, and includes configuration bridges to connect directly to local Ollama or vLLM instances via standard OpenAI-compatible endpoints.
What embedding dimensions and vector index types are supported? ↓
The default migration configures vector(1536) for OpenAI text-embedding-3-small, indexed with an HNSW (Hierarchical Navigable Small World) index for sub-millisecond nearest neighbor retrieval.
How does asynchronous document ingestion and embedding work? ↓
Large text documents are chunked and dispatched to Redis-backed Laravel Queues via ProcessDocumentEmbedding jobs, preventing HTTP request timeouts during embedding generation.
How is multi-tenant isolation enforced in semantic vector searches? ↓
Every vector query incorporates an explicit WHERE tenant_id = ? constraint within the Eloquent query scope, ensuring users can never retrieve vector embeddings belonging to other organizations.
Does the kit support Server-Sent Events (SSE) for streaming AI responses? ↓
Yes. The AiChatController exposes a streaming route using response()->stream() that flushes token chunks to the client with text/event-stream headers in real time.
What is the token consumption benchmark tier for this kit? ↓
The kit is benchmarked at Tier A (16,400 median build tokens) due to clean separation of AI service interfaces and reusable Eloquent pgvector scopes.
How are API rate limits and token budgets enforced? ↓
Laravel Redis rate limiters enforce sliding-window quotas per user ID, restricting both total requests per minute and cumulative daily completion token usage.
What PHP extensions are required for pgvector and AI workloads? ↓
The Dockerfile packages pdo_pgsql, mbstring, intl, bcmath, opcache, and phpredis, running strictly as non-root UID 10001:10001.
How are Pest architectural tests configured for AI services? ↓
Pest ArchTest asserts that all AI services declare strict types, implement dedicated contracts, and avoid any hardcoded API credentials or raw debug calls.
How does function/tool calling work in this kit? ↓
Tools are defined as standard PHP classes implementing an AiToolInterface with name, description, and jsonSchema() methods. The AiService automatically formats these into OpenAI tools declarations and dispatches matching calls.
What automated security scans run in CI for this kit? ↓
GitHub Actions executes Gitleaks for secret detection, Semgrep with OWASP Top 10 rules, and manifest schema validation before any production deployment.
Paste this exact prompt into Claude Code, Cursor, Copilot, or Antigravity to anchor the agent in the kit's rules and invariants:
You are building with the Laravel 12/13 + AI Features (LLM Orchestration, Embeddings & RAG) kit. Adhere strictly to rules in CLAUDE.md / .cursor/rules, design tokens in DESIGN.md, and steps/agent-build-steps.md.