惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LangChain Blog
WordPress大学
WordPress大学
MyScale Blog
MyScale Blog
The Cloudflare Blog
J
Java Code Geeks
Google DeepMind News
Google DeepMind News
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Martin Fowler
Martin Fowler
小众软件
小众软件
量子位
月光博客
月光博客
P
Proofpoint News Feed
IT之家
IT之家
腾讯CDC
博客园 - 三生石上(FineUI控件)
博客园 - 司徒正美
雷峰网
雷峰网
V
Visual Studio Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Project-as-code for a Directus v9 backend
Louis Dussar · 2026-05-21 · via DEV Community

Louis Dussarps

In practice, turning Directus into the backbone of a production backend takes a fair amount of setup before a project becomes productive. Projen, a project scaffolding and automation framework, can automate that plumbing, so the time the tech teams 'd otherwise need to spend wiring Dockerfiles and build pipelines together goes into writing product and business logic instead.

@wbce/projen-d9 is the projen template we built to automate that plumbing around directus. By default it targets d9 (directus version 9), but you can adapt it to whichever Directus version you actually run. You can also customize it further to fit whatever your team needs. This post walks through what it generates and why.

d9 is a GPL fork of Directus v9 we maintain on GitHub. It does what Directus 9 did: an open-source (GPL-3 license) CMS that, with the right discipline, can stand in for a full custom backend (API, admin UI, permissions, schema), with business logic added as extensions (hooks, endpoints, operations, custom UI panels).

Bootstrap a new project

npx projen new --from @wbce/projen-d9

Enter fullscreen mode Exit fullscreen mode

This creates a .projenrc.js and synthesizes the project.

What you get

The user-facing surface of the template is .projenrc.js:

import { D9Project } from '@wbce/projen-d9';
import { D9ExtensionType } from '@wbce/projen-d9-extension';

const project = new D9Project({
  name: 'my-backend',
  defaultReleaseBranch: 'main',
});

project.addExtension('audit-log', [D9ExtensionType.HOOK]);

project.synth();

Enter fullscreen mode Exit fullscreen mode

npx projen synthesizes everything else (Dockerfile, docker-compose, extension folder, build pipeline, GitHub workflows). projen calls this "project-as-code": project files are outputs synthesized from a config you commit, you re-synth whenever the config changes, and the generated files keep tracking the config over time.

Generated tasks

Task Description
first-run Bootstrap a complete local dev environment in one cli command
run Start d9 (docker compose up directus)
build-extensions Install and build all extensions
create-an-admin Create the default admin user

What gets generated

  • docker-compose.yml: d9, Postgres (PostGIS), Redis
  • Dockerfile: Node 22 + pnpm, builds extensions
  • .env.local: sample for local environment overrides
  • extensions as a pnpm workspace
  • GitHub PR and issue templates via @wbce/projen-shared (set githubConfig: false to disable)

A standardized compose stack

With a single CLI command, you can spin up a fully working local Directus environment (database, cache, and API) ready for development. It mirrors a production setup, including caching and geospatial capabilities.

The compose file is built with projen's DockerCompose construct:

  • database: postgis/postgis:13-master in order to enable geospatial functionality
  • cache: redis:6
  • directus: built from the local Dockerfile. EXTENSIONS_AUTO_RELOAD=true is set, so re-running npx projen build-extensions is enough to pick up edits with no container restart.

Bind mounts:

  • ./uploads -> /app/uploads
  • ./extensions -> /app/extensions (the extension tree that build-extensions writes into)
  • ./.env.local -> /app/.env.local (so secrets stay out of the image and git versioning)

Extensions as a pnpm workspace

addExtension(name, types, options?)adds an ExtensionFolder to the parent project. Each addExtension creates a D9ExtensionProject with three quirks:

  1. Its package.json gets the directus:extension field correctly configured.
  2. Its build task is rewritten to compile and then deposit the output in the right subfolder of extensions/
  3. If any of the types are UI extensions (INTERFACE, DISPLAY, LAYOUT, MODULE, PANEL), vue is added as a devDep automatically.

Because every extension is its own package in a real pnpm workspace, we can share packages between extensions :

// A shared library, no extension types
project.addExtension('shared', []);

// Other extensions depend on it via workspace:
const myHook = project.addExtension('audit-log', [D9ExtensionType.HOOK]);
myHook.addDeps('shared@workspace:');

Enter fullscreen mode Exit fullscreen mode

And pnpm catalogs in pnpm-workspace.yaml let you pin shared dependency versions in one place and consume them as catalog: from each extension's package.json.

Deploying

The generated Dockerfile is meant for deployment. Build and push it to your
registry, then run it against your target database and cache.
Simple and efficient, the Docker setup ensures extensions are built inside the image during the build step.

FROM node:22-bookworm-slim
RUN npm install -g npm@11.8.0
RUN npm install -g pnpm@10.33.0
COPY package*.json /app/
WORKDIR /app
RUN NODE_ENV=production npm install
COPY . .
RUN npx projen build-extensions
CMD ["npx", "directus", "start"]

Enter fullscreen mode Exit fullscreen mode

Integrate into an existing project

Follow this section of the documentation

Links

Issues and PRs welcome.