Directus is a real-time API and App dashboard for managing SQL database content. The codebase is organized as a pnpm monorepo with multiple packages.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/directus/directus/llms.txt
Use this file to discover all available pages before exploring further.
Monorepo Overview
The Directus repository uses pnpm workspaces to manage multiple packages in a single repository. This allows for efficient dependency management and code sharing across packages.Workspace Structure
The monorepo includes the following workspace packages (defined inpnpm-workspace.yaml):
Main Directories
/api - Backend API
The Node.js backend powered by Express.js and Knex.js, providing REST and GraphQL APIs.
Key directories:
-
controllers/- REST API endpoint handlers (40+ controllers)- Handle HTTP requests and responses
- Route-specific logic and validation
- Examples:
items.ts,users.ts,collections.ts
-
services/- Business logic layer- Core functionality and data processing
- Database operations via Knex.js
- Examples:
ItemsService,UsersService,FieldsService
-
database/- Knex.js database utilities and migrations- Schema management and migrations
- Database abstraction layer
- Query builders and helpers
-
middleware/- Express middleware- Authentication and authorization
- Rate limiting and caching
- Request validation and error handling
-
auth/- Authentication providers- LDAP, SAML, OAuth providers
- Local authentication
- Session management
-
extensions/- Runtime extension loading- Dynamic extension registration
- Hooks, endpoints, and custom functionality
-
websocket/- Real-time WebSocket support- Live updates and subscriptions
- Event broadcasting
/app - Dashboard Application
The Vue 3 dashboard application built with Vite and Pinia for state management.
Key directories:
-
components/- 145+ Vue components- Reusable UI components
- Form elements, navigation, modals
- Example:
v-button,v-input,v-table
-
views/- Page views- Full-page components
- Route-specific views
-
composables/- 53+ Vue composables- Reusable composition API logic
- State management helpers
- Example:
useCollection,useItems,usePermissions
-
stores/- 24 Pinia stores- Global state management
- User settings, collections, permissions
- Example:
useUserStore,useCollectionsStore
-
interfaces/- 45+ field input types- Custom input components for different data types
- Examples: date picker, file upload, WYSIWYG editor
-
displays/- 21 field display renderers- Components for displaying field values
- Examples: formatted text, images, badges
-
layouts/- 8 data layout views- Different ways to visualize collections
- Examples: table, cards, calendar, map
-
operations/- 18 flow operation types- Automation workflow operations
- Examples: send email, transform data, API requests
-
panels/- 14 dashboard panel types- Insight dashboard widgets
- Examples: metrics, charts, lists
-
modules/- Feature modules- Self-contained feature sets
- Examples: content, users, settings
/sdk - TypeScript SDK
The official TypeScript/JavaScript SDK for interacting with the Directus API.
- Type-safe API client
- Support for REST and GraphQL
- Authentication helpers
- Real-time subscriptions
/packages/* - Shared Packages
Over 35 shared packages used across the monorepo:
Core packages:
@directus/types- Shared TypeScript types and interfaces@directus/utils- Shared utilities (node/browser/shared)@directus/schema- Database schema utilities@directus/extensions- Extension framework and types
@directus/storage- Abstract storage interface@directus/storage-driver-*- Storage backendsstorage-driver-s3- AWS S3storage-driver-azure- Azure Blob Storagestorage-driver-gcs- Google Cloud Storagestorage-driver-local- Local filesystem- And more…
- Extension types and templates
- Validation utilities
- Format converters
- Database drivers
/tests/* - Test Suites
tests-blackbox/- End-to-end blackbox tests- Full integration tests
- Multi-database testing
Architecture Patterns
Code Style
Directus follows these conventions:- TypeScript for all new code
- ES modules (
import/exportsyntax) - Prefer
constoverlet, avoidvar - Follow ESLint and Prettier configurations
- Test files named
*.test.ts, placed next to source files
Testing Conventions
Tests use Vitest:Database Support
Directus works with multiple SQL databases via Knex.js:- PostgreSQL
- MySQL
- MariaDB
- SQLite
- MS SQL Server
- OracleDB
- CockroachDB
Dependency Management
Directus uses a catalog-based dependency management system:Internal Dependencies
Useworkspace:* for dependencies on other packages in the monorepo:
External Dependencies
Usecatalog: for external dependencies. Versions are centrally defined in pnpm-workspace.yaml:
Adding New Dependencies
When adding a new shared dependency:- Add it to the catalog in
pnpm-workspace.yaml - Reference it using
catalog:in package.json files - Run
pnpm installto update lockfile
Build System
The monorepo uses different build tools for different packages:- API packages - Typically use
tsdownorrollupfor bundling - App - Uses Vite for development and production builds
- Libraries - Use
rolluportsdownfor creating distributable packages
Build Commands
Common Tasks
Adding a New API Endpoint
- Create controller in
/api/src/controllers/ - Add service logic in
/api/src/services/ - Register route in appropriate router
- Add tests in
*.test.tsfile - Create changeset:
pnpm changeset
Adding a New Interface (Field Type)
- Create interface directory in
/app/src/interfaces/ - Implement
index.tswith interface definition - Create Vue component for the input
- Register in interfaces registry
- Add tests and create changeset
Adding a New Storage Driver
- Create new package in
/packages/storage-driver-{name}/ - Implement storage driver interface from
@directus/storage - Add to workspace in
pnpm-workspace.yaml - Add tests and documentation
- Create changeset
Next Steps
Now that you understand the codebase structure:- Review the pull request guidelines
- Start working on an issue
- Ask questions in discussions if you need help