Skip to content
agents.store
stackstack

stack-directus-nextjs-trigger

Directus + Next.js + Trigger.dev architecture plugin. How Directus (content, files, access), a Next.js App Router frontend and self-hosted Trigger.dev (durable and scheduled work) fit together: who holds which token, how the cache is invalidated, how a Directus change reaches a task and the result reaches the page, who owns the session, and a production checklist. Tool knowledge comes from its dependencies.

v3.0.5Updated

  • stack
  • directus-nextjs-trigger
  • architecture
  • agents-store
  • directus
  • nextjs
  • trigger.dev
  • background-jobs
  • scheduled-tasks
  • self-hosted
  • durable-execution
  • app-router

Install

Pick your agent for the steps.

Install on Claude Code

  1. 1.Add the marketplace

    /plugin marketplace add Agents-Store/claude-plugins
  2. 2.Install the plugin

    /plugin install stack-directus-nextjs-trigger@agents-store-claude-plugins

    Type it inside Claude Code.

Claude Code install docs

What is inside

Skills (8)

  • authentication

    This skill should be used when the user wants to "add authentication to Directus + Next.js", "implement Directus login in Next.js", "use NextAuth with Directus", "use Better Auth with Directus", "protect Next.js pages with Directus auth", "choose an auth approach for Directus and Next.js", "decide who owns the session", "act as the signed-in user inside a trigger.dev task", or needs to decide who owns the end-user session and the tokens across Directus and Next.js.

  • background-tasks

    This skill should be used when the user wants to "offload work to trigger.dev from next.js", "run a background job from a server action", "trigger a task from a route handler", "delegate slow work to trigger.dev", "decide what runs in a Server Action and what in a task", "show a task's progress in next.js", "give the browser a token for a trigger.dev run", "keep task environment variables apart from next.js", "fix a TRIGGER_SECRET_KEY build error", or needs the rules where a Next.js App Router app hands work to Trigger.dev and gets the result back.

  • deployment

    This skill should be used when the user wants to "run the Directus Next.js Trigger.dev stack locally", "deploy trigger.dev tasks next to a Next.js app", "set environment variables for trigger.dev tasks", "configure content-change webhooks with trigger.dev", "revalidate the site when a task changes Directus content", "CI/CD for trigger tasks", "production checklist for directus + nextjs + trigger.dev", or needs the pipelines that connect the three services and the checks before production. For platform-specific hosting (Vercel, Dokploy, etc.), see the respective deployment plugin.

  • directus-to-nextjs

    This skill should be used when the user wants to "fetch Directus data in Next.js", "display Directus content in Next.js pages", "render Directus images in Next.js", "use Directus SDK with Server Components", "create Next.js pages from Directus collections", "add TypeScript types for Directus", "cache Directus data in Next.js", "revalidate after Directus content changes", "fix 403 on Directus images", or needs the rules where Directus data meets Next.js rendering: who holds the token, what is cached, how files are served, and how types follow the schema.

  • directus-to-trigger

    This skill should be used when the user wants to "trigger a task from a directus flow", "run a background task when a directus item is created or updated", "forward directus webhooks to trigger.dev", "process directus items asynchronously", "build a directus flow to next.js to trigger pipeline", "have a task write back to directus", "stop a directus flow and task from looping", "read and write directus from a trigger.dev task", or needs the pattern for wiring Directus Flow events through Next.js into Trigger.dev tasks and back.

  • examples

    End-to-end scenario walkthroughs for the Directus + Next.js + Trigger.dev stack. This skill should be used when the user asks for "directus nextjs trigger.dev examples", "how to build a blog with directus + next.js", "ai enrichment pipeline example", "scheduled data sync example", "show me a complete example with background tasks", or needs implementation references for common application types on this stack.

  • full-feature

    This skill should be used when the user wants to "build a complete feature with directus nextjs and trigger.dev", "create an end-to-end feature with background tasks", "implement a full crud feature with async processing", "build a new section of the site that uses background jobs", "add a page backed by directus with a background task", or needs a step-by-step recipe for building features that span Directus, Next.js, and Trigger.dev.

  • init-project

    This skill should be used when the user asks to "set up Directus + Next.js + Trigger.dev project", "initialize directus nextjs trigger.dev stack", "bootstrap the 3-service stack", "configure directus next.js and trigger.dev together", "connect trigger.dev to a directus nextjs app", "scaffold stack with background tasks", "start a new project with background jobs", or needs to set up environment variables, versions and verify connections for the Directus + Next.js + Trigger.dev stack.

Agents (1)

  • stack-orchestrator

    Use this agent when the user needs help coordinating work across Directus, Next.js, and Trigger.dev: building pages that display Directus content, deciding who owns the user session, offloading slow work to background tasks, wiring a Directus change to a task, defining scheduled jobs, or implementing features that span all three services. <example> Context: User wants to build a page that displays Directus content user: "Build a blog listing page that fetches posts from Directus and displays them with images" assistant: "I'll use the stack-orchestrator agent to build the blog page with tagged Directus reads and image handling." <commentary> The feature needs Directus SDK reads in a Next.js Server Component with the cache tags and image rules of the stack: it spans the Data and Interface layers. </commentary> </example> <example> Context: User wants to add a background enrichment pipeline user: "When an article is created in Directus, automatically enrich it with AI-generated tags and a summary" assistant: "I'll use the stack-orchestrator agent to wire the Directus Flow, the Next.js receiver, the Trigger.dev task and the write-back." <commentary> The feature spans all three services: a Flow with a loop guard, a receiver that starts a debounced task, a task with its own Directus token, and the page refresh. This is what the orchestrator exists for. </commentary> </example> <example> Context: User wants a scheduled data sync user: "Pull currency rates from an external API every day at 2am and store them in Directus" assistant: "I'll use the stack-orchestrator agent to define a scheduled Trigger.dev task that upserts into Directus and refreshes the dashboard." <commentary> Needs a declarative schedule, the task-side Directus client, an idempotent upsert and the revalidation path; the schedule rules come from the trigger-dev plugin. </commentary> </example> <example> Context: User hits a build failure with Trigger.dev user: "My CI build is failing with 'You need to set the TRIGGER_SECRET_KEY environment variable' on a route that calls tasks.trigger()" assistant: "I'll use the stack-orchestrator agent to find where the trigger runs at build time." <commentary> The SDK reads the environment on the first call, not on import: a trigger at module level or during prerendering is the cause. The background-tasks skill has the rule. </commentary> </example> <example> Context: User wants to add authentication user: "Set up user login using Directus authentication and NextAuth" assistant: "I'll use the stack-orchestrator agent to decide who owns the session and wire the matching authentication path." <commentary> Authentication spans Directus (user store, token management) and Next.js (session library, proxy); the orchestrator decides who owns the session and coordinates both sides, and keeps user tokens out of tasks. </commentary> </example> <example> Context: User wants to deploy the full stack user: "Deploy my Next.js app and set up auto-rebuild when Directus content changes, and deploy my Trigger.dev tasks" assistant: "I'll use the stack-orchestrator agent to configure the pipelines and the environment variables across all three services." <commentary> Deployment involves the Next.js host variables, the Directus Flows and their secrets, the Trigger.dev environment, and a separate task deploy with a pinned CLI. </commentary> </example> <example> Context: User encounters a cross-service issue user: "My Directus images aren't loading in production" assistant: "I'll use the stack-orchestrator agent to diagnose the image loading issue across Directus permissions, Next.js image config, and hosting settings." <commentary> Cross-service debugging requires understanding Directus file permissions, the images block of next.config.ts, and environment variables. </commentary> </example>

MCP servers (2)

  • directus http
  • trigger-dev stdio

README

Directus + Next.js + Trigger.dev architecture plugin for Agents Store. It describes how Directus (content, files, access), a Next.js App Router frontend and self-hosted Trigger.dev (durable and scheduled work) fit together: who holds which token, how the cache is invalidated when content or a task changes it, how a Directus change reaches a task and the result reaches the page, who owns the user session, and what to check before production. It names its parts in dependencies; what one tool does and how to drive it is taught by that tool's own plugin.

Architecture

LayerServiceRole
DataDirectusContent, REST API, file storage, users and policies, Flows
Interface + LogicNext.jsApp Router, Server Components, Server Actions, Route Handlers
WorkTrigger.dev (self-hosted)Durable tasks: retries, schedules, AI calls, long-running and bulk work, on its own workers

Next.js keeps the synchronous work (rendering, actions, webhook receivers). Anything slow, flaky or scheduled leaves it as a task that retries, can be observed, and writes its result back to Directus.

The boundaries between them are what this plugin owns:

BoundaryRule
TokenThe Next.js server holds a service token of a dedicated Directus user; a task holds the token of its own Directus user; the browser holds nothing of Directus
CacheEvery Directus read is tagged with its collection; a Directus Flow (or a task) expires the tag through a Route Handler
AssetsA file URL never carries a token: public files, or a server route that adds the token
Typestypes/directus.ts follows the Directus schema, the tasks import it too, and tsc is the drift check
SessionOne owner of the end-user session, chosen once (see authentication)
Task payloadIds and requestedBy, never a token and never a copy of the item
Task environmentA task sees only the variables of its Trigger.dev project, never the Next.js host's
Browser to taskOnly the run-scoped public token and the server address; never TRIGGER_SECRET_KEY

Deployment of the Next.js app is handled by a separate plugin (for example dokploy-dev, vercel-dev); tasks deploy separately with the Trigger.dev CLI.

Dependencies

Declared in plugin.json and installed together with the stack. They hold the tool-level knowledge:

PluginTeaches
directus-devDirectus MCP tools, REST API, @directus/sdk (sdk-patterns, including server-side use), local Docker Compose (docker-local-dev), Flows (flow-automation, including the Flow that sends item keys to a worker), schema design
nextjs-devApp Router, data fetching and caching (data-fetching), authentication (auth-patterns), proxy.ts, images, Cache Components
trigger-devTasks, retries, queues, debounce and idempotency (task-development), schedules (scheduled-tasks), tokens and hooks for the browser (realtime), deploys and CI (deployment), CLI, MCP tools, self-hosted infrastructure

nextjs-provision (shadcn/ui setup) is optional: install it separately if you want it. Pick the plugin that matches your hosting for deployment (dokploy-dev, vercel-dev).

More from trigger-dev that fits this stack once the basics work: a human approval step in a pipeline (wait.createToken plus a status field in Directus, completed from the browser with useWaitToken; realtime), AI chat agents as tasks (ai-chat-agents), and run and cost analysis with TRQL (observability).

Prerequisites

  • Directus 12 (MCP needs 11.12 or later and is switched on in Settings → AI)
  • Next.js 16, next@^16.3.8
  • Node.js 22 or later (@directus/sdk 26 requires it)
  • A self-hosted Trigger.dev 4.x server (webapp and supervisor running); @trigger.dev/sdk, @trigger.dev/react-hooks and the trigger.dev CLI at the version of the server
  • Docker, for a local Directus

Installation

claude plugin install stack-directus-nextjs-trigger@agents-store-claude-plugins

The three technology plugins above come with it. Copies installed under the plugin's former name move to this one through the marketplace renames map; update enabledPlugins entries and any skill reference that still uses the old name (see LEARNINGS.md).

MCP Servers

This plugin's .mcp.json connects Claude to Directus and to Trigger.dev. Tools are named mcp__plugin_stack-directus-nextjs-trigger_directus__<tool> and mcp__plugin_stack-directus-nextjs-trigger_trigger-dev__<tool>.

ServerTransportAddress
directusHTTP${NEXT_PUBLIC_DIRECTUS_URL}/mcp with Bearer ${DIRECTUS_ADMIN_TOKEN}
trigger-devstdionpx trigger.dev@${TRIGGER_CLI_VERSION:-latest} mcp --dev-only --project-ref ${TRIGGER_PROJECT_REF}, with TRIGGER_ACCESS_TOKEN and TRIGGER_API_URL
  • Directus MCP acts with the permissions of the token's user, so a token of a dedicated user with a narrow policy also narrows what the model can change.
  • Trigger.dev MCP runs with --dev-only: every tool that takes an environment answers only for dev, and deploy and the deploy and preview-branch listings are refused. It keeps trigger_task, so the agent can start a test run. Drop the flag to reach production, or add --readonly to hide the write tools (trigger_task included).
  • Set TRIGGER_CLI_VERSION to the version of your server so the MCP server runs the matching CLI; the default is latest.
  • ${VAR} in .mcp.json is expanded from the environment Claude Code runs in (your shell, or the env block of .claude/settings.local.json), not from .env.local.

Environment Variables

Copy templates/.env.example to your project root as .env.local (Next.js), and templates/.env.trigger.example to .env.trigger.local (the tasks, for trigger dev):

VariablePurposeClient-side
NEXT_PUBLIC_DIRECTUS_URLDirectus addressYes
DIRECTUS_ADMIN_TOKENStatic token of a dedicated Directus user (the name is historical; an administrator token is for local development only)No
DIRECTUS_URL, DIRECTUS_TOKEN, NEXT_PUBLIC_CMS_URLThe names the directus-dev and nextjs-dev recipes read. In .env.local they expand to the two variables above (DIRECTUS_URL=${NEXT_PUBLIC_DIRECTUS_URL}, DIRECTUS_TOKEN=${DIRECTUS_ADMIN_TOKEN}, NEXT_PUBLIC_CMS_URL=${NEXT_PUBLIC_DIRECTUS_URL}); without them the NextAuth login calls undefined/auth/login and the images config failsNEXT_PUBLIC_CMS_URL: yes
NEXT_PUBLIC_SITE_URLAddress of this site (RSS, metadata, the call a task makes to /api/revalidate)Yes
NEXTAUTH_URL, NEXTAUTH_SECRETNextAuth (NextAuth path only)No
REVALIDATION_SECRETShared secret for /api/revalidate, sent in a header by a Directus Flow and by tasks that call the routeNo
DIRECTUS_WEBHOOK_SECRETShared secret for /api/directus-webhook/*, sent in a header by the Flow that starts a task. A different value from REVALIDATION_SECRETNo
PUBLIC_ASSET_FOLDER_IDDirectus folder whose files the asset proxy may serve (proxy path only)No
TRIGGER_API_URLAddress of the self-hosted server. Set wherever tasks.trigger() runs: without it the SDK falls back to Trigger.dev CloudNo
TRIGGER_SECRET_KEYEnvironment secret key (tr_dev_... for dev). The SDK in the Next.js server triggers tasks with itNo
TRIGGER_ACCESS_TOKENPersonal Access Token (tr_pat_...) for the MCP server and trigger deployNo
TRIGGER_PROJECT_REFProject ref (proj_...)No
NEXT_PUBLIC_TRIGGER_API_URLThe server address for browser hooks (baseURL); expands to ${TRIGGER_API_URL} in .env.localYes
TRIGGER_CLI_VERSIONOptional: the version of your server, for the MCP server's CLINo

Two Trigger.dev credentials. TRIGGER_SECRET_KEY is the environment secret key the SDK uses to trigger tasks. TRIGGER_ACCESS_TOKEN is a Personal Access Token (dashboard → Account → Personal Access Tokens) for the MCP server and the CLI: the MCP server's account-level tools reject environment keys. The PAT's user must be a member of the organization that owns TRIGGER_PROJECT_REF.

Tasks have their own variables. .env.trigger.local (for trigger dev) and the Trigger.dev project environment (deployed) hold DIRECTUS_URL, DIRECTUS_TOKEN (the task user's token), and any third-party key. The Trigger.dev CLI loads dotenv files but does not expand ${VAR}, so the .env.local aliases would reach a task as literal text.

Skills

SkillDescription
init-projectVersions, environment, dependencies, client and types, the Trigger.dev project, verification of the three connections
directus-to-nextjsThe Directus to Next.js boundary: token, cache, assets, types
authenticationWho owns the user session and the tokens; three paths; why a user's token never goes into a task
deploymentLocal run, the four pipelines, environment variables per service, task deploys, production checklist
background-tasksThe Next.js to Trigger.dev boundary: what to offload, what crosses, starting a task from an action, handing the run to the browser, closing the loop
directus-to-triggerDirectus Flow to receiver to task to write-back: the Flow's values, the receiver, the task-side client, loop guards
full-featureStep-by-step recipe for building a feature across the three layers
examplesScenario walkthroughs (blog, product catalog, AI enrichment pipeline, scheduled data sync)

Agent

stack-orchestrator: Coordinates work across Directus, Next.js and Trigger.dev: content pages, the session, revalidation, tasks started by users, Directus changes or the clock, and cross-service debugging.