What Directus Does
Directus provides a complete backend toolkit:
- Instant APIs: REST and GraphQL APIs auto-generated from your database schema
- Admin App: No-code admin panel for content management, built with Vue.js
- Authentication: Email/password, SSO (OAuth 2.0, OpenID, LDAP, SAML), and API tokens
- Access Control: Granular role-based permissions at collection, field, and record level
- File Storage: Asset management with transforms (resize, crop) and CDN support
- Flows (Automation): Visual workflow builder for triggers, conditions, and actions
- Webhooks: Real-time notifications on data changes
- Insights: Built-in analytics dashboard builder with charts and metrics
Architecture
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Admin App │────▶│ Directus │────▶│ Your SQL DB │
│ (Vue.js) │ │ Server │ │ (Postgres / │
│ │ │ (Node.js) │ │ MySQL / etc)│
└──────────────┘ └──────┬───────┘ └──────────────┘
│
│ Your Frontend │───▶ REST / GraphQL API
│ (Any framework)│Self-Hosting
Docker Compose
services:
directus:
image: directus/directus:latest
ports:
- "8055:8055"
environment:
SECRET: your-random-secret-key
DB_CLIENT: pg
DB_HOST: postgres
DB_PORT: 5432
DB_DATABASE: directus
DB_USER: directus
DB_PASSWORD: directus
ADMIN_EMAIL: admin@example.com
ADMIN_PASSWORD: your-admin-password
depends_on:
- postgres
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: directus
POSTGRES_PASSWORD: directus
POSTGRES_DB: directus
volumes:
- pg-data:/var/lib/postgresql/data
volumes:
pg-data:Key Features
Database-First Approach
Directus never modifies your database schema:
-- Your existing database tables work as-is
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(255),
price DECIMAL(10,2),
category_id INTEGER REFERENCES categories(id),
created_at TIMESTAMP DEFAULT NOW()
);
-- Directus automatically provides:
-- REST: GET /items/products
-- GraphQL: query { products { id name price } }
-- Admin UI with forms, filters, and relationsSupported Databases
| Database | Status |
|---|---|
| PostgreSQL | Full support |
| MySQL / MariaDB | Full support |
| SQLite | Full support |
| MS SQL Server | Full support |
| CockroachDB | Community |
| OracleDB | Community |
Flows (Visual Automation)
Build automations without code:
Trigger: Item Created in "orders"
→ Condition: order.total > 1000
→ Action: Send Email to sales team
→ Action: Create record in "high_value_orders"
→ Action: Call webhook to fulfillment APIExtensions System
Directus is fully extensible:
// Custom endpoint extension
export default {
id: 'custom-reports',
handler: (router, context) => {
router.get('/sales-report', async (req, res) => {
const { ItemsService } = context.services;
const orders = new ItemsService('orders', { schema: req.schema });
const data = await orders.readByQuery({ aggregate: { sum: ['total'] } });
res.json(data);
});
},
};Extension types:
- Interfaces: Custom input components
- Displays: Custom value renderers
- Layouts: Custom collection views
- Modules: Full custom pages
- Endpoints: Custom API routes
- Hooks: Event-driven logic
Directus vs Alternatives
| Feature | Directus | Strapi | Payload | Hasura |
|---|---|---|---|---|
| Open Source | Yes | Yes | Yes (MIT) | Yes (Apache) |
| Approach | Database-first | CMS-first | Code-first | Database-first |
| Existing DB | Connect any SQL | Own schema | Own schema | Connect PostgreSQL |
| APIs | REST + GraphQL | REST + GraphQL | REST + GraphQL | GraphQL only |
| Admin UI | Built-in (Vue) | Built-in (React) | Built-in (React) | Console |
| Automation | Visual Flows | Webhooks | Hooks | Event triggers |
| No-code | Extensive | Moderate | Minimal | Moderate |
常见问题
Q: Directus 会修改我现有的数据库吗? A: 不会修改你的业务表。Directus 只会在你的数据库中创建自己的系统表(以 directus_ 前缀),用于存储配置、权限和元数据。你的业务数据表保持原样。
Q: 适合做传统 CMS 网站吗? A: 非常适合。Directus 可以作为 headless CMS,配合 Next.js、Nuxt.js、Gatsby 等前端框架构建网站。内置的资产管理、多语言和版本控制都是 CMS 必备功能。
Q: 和 Strapi 相比选哪个? A: 如果你有已有数据库需要连接,选 Directus(database-first)。如果从零开始建内容模型,两者都可以。Directus 的 no-code 能力更强,Strapi 的开发者生态更大。
来源与致谢
- GitHub: directus/directus — 34.7K+ ⭐
- 官网: directus.io