convex-ddd-architecture
Use when structuring or refactoring Convex codebases with Domain-Driven Design boundaries, repository abstractions, adapters for external APIs, and transaction-safe workflows. Also use for naming—ubiquitous language, bounded context, short locals inside clear parent scope (avoid verbose identifiers).
What this skill does
# Convex DDD Architecture
Reference skill for organizing Convex projects with DDD and Hexagonal architecture. It keeps domain logic isolated from database and external API concerns so changes remain local and safer to evolve.
## When to Use
Use this skill when work includes one or more of these signals:
- New Convex sub-domain design (`schema`, `queries`, `mutations`, `domain`, `adapters`)
- Legacy Convex code migration toward DDD/Hexagonal boundaries
- Business rules drifting into handlers instead of aggregates
- Direct `ctx.db` access spreading outside repositories
- External API calls requiring retries, orchestration, or translation layers
- Team-level need for consistent file layout and naming in Convex projects
- Choosing or refactoring **identifiers** (variables, functions): domain nouns on exports/models; shorter names inside modules/functions where scope already disambiguates ([naming.md](references/naming.md))
Do not use this as a strict template for tiny prototypes where speed matters more than architectural boundaries.
## Project Shape
```
./convex/
_generated/ # Auto-generated by Convex (do not edit)
_shared/ # Cross-domain utilities
_libs/
aggregate.ts # Base aggregate interface
repository.ts # Base repository interface
_triggers.ts # Central trigger registry
customFunctions.ts # Wrapped mutation/query exports
schema.ts # Composed schema from all sub-domains
[subDomainName]/ # Each sub-domain folder (camelCase)
_libs/
stripeClient.ts # Libs or helpers
_tables.ts # Database schema tables
_triggers.ts # Sub-domain trigger handlers
_seeds.ts # Seeds for models
_workflows.ts # Convex workflows
queries/
[queryName].ts # One query per file, export default
mutations/
[mutationName].ts # One mutation per file, export default
domain/
[modelName].model.ts # Model schema, types, Aggregate
[modelName].repository.ts # Repository interface
adapters/
[actionName].action.ts # External API actions
[modelName].repository.ts # Repository implementation
```
## Naming Rules
- **Files**: Use camelCase (`contactRepository.ts`, `sendInvoice.action.ts`)
- **Underscore prefix**: For non-domain files (`_tables.ts`, `_triggers.ts`)
- **Directory vs file**: Start with a file (for example `_workflows.ts`), split into a directory after growth
- **Identifiers**: Domain vocabulary on exports, models, and APIs; inside functions prefer short nouns when the parent name/type already supplies context—do not repeat file or parent names on every local. Details: [naming.md](references/naming.md).
## Quick Reference
| Concern | Rule |
|---|---|
| Convex imports | Import `mutation`, `query`, `internalMutation` from `customFunctions.ts` |
| Function exports | One function per file with `export default` |
| Domain model shape | Include `_id`, `_creationTime`, plus `New<Model>` without system fields |
| Persistence boundary | Access DB through repositories in `adapters/` |
| External integrations | Keep translation in actions; business decisions stay in mutations/aggregates |
| Schema | Compose root schema from each sub-domain `_tables` export |
## Core Patterns
### 1) Custom Functions Boundary
Always import `mutation`, `query`, `internalMutation` from `customFunctions.ts`, not from `_generated/server`. See [custom-functions.md](references/custom-functions.md).
```typescript
// ✅ Correct
import { mutation } from "../../customFunctions";
// ❌ Wrong - bypasses trigger integration
import { mutation } from "../../_generated/server";
```
### 2) API Path Convention
One function per file with named definition and default export:
```typescript
// convex/combat/mutations/createBattle.ts
import { mutation } from "../../customFunctions";
import { v } from "convex/values";
const createBattle = mutation({
args: { heroId: v.id("heroProfiles") },
handler: async (ctx, args) => {
// ...
},
});
export default createBattle;
```
Frontend usage with `.default` suffix:
```typescript
import { api } from "@/convex/_generated/api";
useMutation(api.combat.mutations.createBattle.default);
useQuery(api.economy.queries.getHeroProfile.default);
```
**Avoid** named exports like `export const createBattle` - this creates redundant paths like `api.combat.mutations.createBattle.createBattle`.
### 3) Schema Composition
Compose schema from sub-domain tables:
```typescript
// convex/schema.ts
import { defineSchema } from "convex/server";
import { combatTables } from "./combat/_tables";
import { economyTables } from "./economy/_tables";
export default defineSchema({
...combatTables,
...economyTables,
});
```
### 4) Domain + Repository + Adapter Roles
- Domain models and aggregates define invariants ([domain-models.md](references/domain-models.md))
- Repositories isolate persistence logic ([repositories.md](references/repositories.md))
- Actions adapt external DTOs and call mutations for business transitions ([adapters.md](references/adapters.md))
- Triggers and workflows orchestrate reliable side effects ([triggers.md](references/triggers.md))
### 5) Workflow and Trigger Safety
- Prefer one-way flow: UI mutation -> scheduled action/workflow -> mutation -> reactive query
- Keep trigger handlers lightweight; schedule async work when possible
- Treat trigger code as transaction-sensitive
## Common Mistakes
- Overly verbose locals that restate file or function context instead of narrowing scope or extracting a smaller unit ([naming.md](references/naming.md))
- Importing handlers directly from `_generated/server` and bypassing shared wrappers
- Writing business rules in actions or handlers instead of aggregates
- Updating records with ad-hoc field mutations rather than aggregate transitions
- Returning raw records where aggregate behavior is expected
- Introducing required schema fields without staged migration strategy ([migrations.md](references/migrations.md))
## Supporting References
Supporting documents live in the `references/` directory.
- [custom-functions.md](references/custom-functions.md)
- [domain-models.md](references/domain-models.md)
- [value-objects.md](references/value-objects.md)
- [repositories.md](references/repositories.md)
- [adapters.md](references/adapters.md)
- [triggers.md](references/triggers.md)
- [migrations.md](references/migrations.md)
- [naming.md](references/naming.md)
- [learnings.md](references/learnings.md)
- [eslint-rules.md](references/eslint-rules.md)
- [examples.md](references/examples.md)
Related in Design
contribute
IncludedLocal-only OSS contribution command center. Auto-refreshes the user's in-flight PR and issue state on invoke so conversations start with full context — no need to brief Claude on what's in flight. Helps the user find issues to contribute to on GitHub, builds per-repo dossiers of what each upstream expects (CLA, DCO, branch convention, AI policy, draft-first, review bots, issue templates), runs deterministic gates before any external action so AI-assisted contributions don't reach maintainers as slop. State is markdown-only: candidate files at ~/.contribute-system/candidates/, repo dossiers at ~/.contribute-system/research/, append-only event log at ~/.contribute-system/log.jsonl. No database, no cloud calls. Use when the user asks about their PRs / issues / contributions, wants to find new work to take on, claim an issue, build/refresh a repo's dossier, or draft a Design Issue or PR. Trigger with "/contribute", "what's my PR status", "find a contribution", "claim issue X", "draft a Design Issue for Y", "refresh dossier for Z".
architectural-analysis
IncludedUser-triggered deep architectural analysis of a codebase or scoped subtree across eight modes — information architecture, data flow, integration points, UI surfaces, interaction patterns, data model, control flow, and failure modes. This skill should be used when the user asks to "diagram this codebase," "map the architecture," "show the data flow," "give me an ERD," "trace control flow," "find the integration points," "verify the layout pattern," "audit the UX architecture," or any similar request whose primary deliverable is mermaid diagrams plus cited reports under docs/architecture/. Dispatches haiku/sonnet sub-agents in parallel for per-mode exploration, then verifies every citation mechanically before any node lands in a diagram. Not for one-off prose explanations of code (use code-explanation) or for high-level system design from scratch (use system-design).
mcp
IncludedModel Context Protocol (MCP) server development and tool management. Languages: Python, TypeScript. Capabilities: build MCP servers, integrate external APIs, discover/execute MCP tools, manage multi-server configs, design agent-centric tools. Actions: create, build, integrate, discover, execute, configure MCP servers/tools. Keywords: MCP, Model Context Protocol, MCP server, MCP tool, stdio transport, SSE transport, tool discovery, resource provider, prompt template, external API integration, Gemini CLI MCP, Claude MCP, agent tools, tool execution, server config. Use when: building MCP servers, integrating external APIs as MCP tools, discovering available MCP tools, executing MCP capabilities, configuring multi-server setups, designing tools for AI agents.
react-native-skia
IncludedDesign, build, debug, and optimise high-polish animated graphics in React Native or Expo using @shopify/react-native-skia, Reanimated, and Gesture Handler. Use when the user wants canvas-driven UI, shaders, paths, rich text, image filters, sprite fields, Skottie, video frames, snapshots, web CanvasKit setup, or performance tuning for custom motion-heavy elements such as loaders, hero art, cards, charts, progress indicators, particle systems, or gesture-driven surfaces. Also use when the user asks for fluid, glow, glass, blob, parallax, 60fps/120fps, or GPU-friendly animated effects in React Native, even if they do not explicitly say "Skia". Do not use for ordinary form/layout work with standard views.
plaid
IncludedProduct Led AI Development — guides founders from idea to launched product. Six capabilities: Idea (discover a product idea), Validate (pressure-test the idea against fatal flaws, problem reality, competition, and 2-week MVP feasibility), Plan (vision intake + document generation), Design (translate image references into a design.md spec), Launch (go-to-market strategy), and Build (roadmap execution). Use when someone says "PLAID", "plaid idea", "help me find an idea", "product idea", "idea from my business", "idea from my expertise", "plaid validate", "validate my idea", "pressure-test", "is this idea good", "find fatal flaws", "validate the problem", "plan a product", "define my vision", "generate a PRD", "product strategy", "plaid design", "design from image", "translate image to design", "create design.md", "extract design tokens", "plaid launch", "go-to-market", "launch plan", "GTM strategy", "launch playbook", "plaid build", "build the app", "start building", or "execute the roadmap".
nextjs-framer-motion-animations
IncludedAdds production-safe Motion for React or Framer Motion animations to Next.js apps, including reveal, hover and tap micro-interactions, whileInView, stagger, AnimatePresence, layout and layoutId transitions, reorder, scroll-linked UI, and lightweight route-content transitions. Use when the user asks to add, refactor, or debug Motion or Framer Motion in App Router or Pages Router codebases, especially around server/client boundaries, reduced motion, LazyMotion, bundle size, hydration, or route transitions. Avoid for GSAP-style timelines, WebGL or 3D scenes, heavy scroll storytelling, or CSS-only effects unless Motion is explicitly requested.