# spawnrider/directus architecture

> Architecture diagram of the GitHub repository spawnrider/directus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spawnrider/directus
- Repository: https://github.com/spawnrider/directus

## Overview

##### High-Level Architecture Components

a) Frontend Layer:
- Vue.js Admin App (under /app directory)
- Modules system
- Interface components
- Layout components
- Components

b) API Layer:
- REST API endpoints
- GraphQL API
- Authentication/Authorization system
- File storage system
- Cache system
- Event emitter system

c) Database Layer:
- SQL database support (PostgreSQL, MySQL, SQLite, OracleDB, MariaDB, MS-SQL)
- Migration system
- Query builder

##### Key Relationships

- API routes to controllers
- Controller to service layer communication
- Service layer to database interactions
- Authentication flow
- File storage operations
- Cache interactions

##### Specific Implementation Details

Specialized subsystems:
- Extensions system (displays, interfaces, layouts, modules)
- Authentication providers
- File storage providers (local, S3, GCS, Azure)
- Activity tracking
- Webhook system
- Email system

**[Client Layer]**
- ↓ ↑
**[API Gateway Layer]**
- ↓ ↑
**[Service Layer]**
- ↓ ↑
**[Data Access Layer]**
- ↓ ↑
**[Database Layer]**

##### Important Subsystems to Detail

a) API Structure:
- Routing system (/api/src/controllers)
- Middleware chain
- Authentication flow
- Permission system

b) Extension System:
- Extension points
- Interface hooks
- Layout integration
- Module system

c) Storage Abstraction:
- Local file system
- Cloud storage providers
- File transformations

##### Key Flows to Illustrate

- Authentication flow
- CRUD operations path
- File upload/download process
- Cache interaction
- Extension loading
- Webhook execution

##### Additional Elements

Include:
- Version information
- Database support matrix
- External service integration points

##### Implementation Notes

- Use standardized UML notation where applicable
- Clear labels for all components
- Both synchronous and asynchronous communication paths
- Scalability points
- Security boundaries

##### Optimization Points

Highlight:
- Cache layers
- Database connection pooling
- File storage optimization
- API rate limiting
- Query optimization

Remember to include notes about:
- Supported databases
- Authentication methods
- File storage options
- Extension capabilities
- API endpoints (REST/GraphQL)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        VueAdmin["Vue.js Admin App"]
        Modules["Modules System"]
        Interfaces["Interface Components"]
        Layouts["Layout Components"]
        Displays["Display Components"]
    end

    subgraph API
        REST["REST API Controllers"]
        GraphQL["GraphQL API"]
        Auth["Authentication"]
        FileStorage["File Storage"]
        Cache["Cache System"]
        EventEmitter["Event Emitter"]
    end

    subgraph Services
        AuthService["Authentication Service"]
        AuthzService["Authorization Service"]
        PermService["Permissions Service"]
        FilesService["Files Service"]
        AssetsService["Assets Service"]
        ItemsService["Items Service"]
        CollectionsService["Collections Service"]
        FieldsService["Fields Service"]
        RelationsService["Relations Service"]
    end

    subgraph Database
        DBCore["Database Core"]
        Migrations["Migration System"]
        QueryBuilder["Query Builder"]
        DB[(SQL Databases)]
    end

    subgraph Extensions
        ExtSDK["Extension SDK"]
        ExtTypes["Extension Types"]
        StorageDrivers["Storage Drivers"]
    end

    %% Relationships
    VueAdmin --> REST & GraphQL
    Modules & Interfaces & Layouts & Displays --> VueAdmin
    REST & GraphQL --> AuthService
    Auth --> AuthService
    AuthService --> AuthzService
    AuthzService --> PermService
    FileStorage --> FilesService
    FilesService --> StorageDrivers
    FilesService --> AssetsService
    Cache --> ItemsService
    EventEmitter --> Services
    ItemsService & CollectionsService --> DBCore
    FieldsService & RelationsService --> DBCore
    DBCore --> QueryBuilder
    QueryBuilder --> DB
    DBCore --> Migrations
    ExtSDK --> ExtTypes

    %% Styling
    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef api fill:#e8f5e9,stroke:#1b5e20
    classDef service fill:#fff3e0,stroke:#e65100
    classDef database fill:#f3e5f5,stroke:#4a148c
    classDef extension fill:#fce4ec,stroke:#880e4f

    class VueAdmin,Modules,Interfaces,Layouts,Displays frontend
    class REST,GraphQL,Auth,FileStorage,Cache,EventEmitter api
    class AuthService,AuthzService,PermService,FilesService,AssetsService,ItemsService,CollectionsService,FieldsService,RelationsService service
    class DBCore,Migrations,QueryBuilder,DB database
    class ExtSDK,ExtTypes,StorageDrivers extension

    %% Click events
    click VueAdmin "https://github.com/spawnrider/directus/tree/main/app/src/"
    click Modules "https://github.com/spawnrider/directus/tree/main/app/src/modules/"
    click Interfaces "https://github.com/spawnrider/directus/tree/main/app/src/interfaces/"
    click Layouts "https://github.com/spawnrider/directus/tree/main/app/src/layouts/"
    click Displays "https://github.com/spawnrider/directus/tree/main/app/src/displays/"
    click REST "https://github.com/spawnrider/directus/tree/main/api/src/controllers/"
    click GraphQL "https://github.com/spawnrider/directus/blob/main/api/src/controllers/graphql.ts"
    click Auth "https://github.com/spawnrider/directus/blob/main/api/src/controllers/auth.ts"
    click FileStorage "https://github.com/spawnrider/directus/blob/main/api/src/storage.ts"
    click Cache "https://github.com/spawnrider/directus/blob/main/api/src/cache.ts"
    click EventEmitter "https://github.com/spawnrider/directus/blob/main/api/src/emitter.ts"
    click DBCore "https://github.com/spawnrider/directus/tree/main/api/src/database/"
    click Migrations "https://github.com/spawnrider/directus/tree/main/api/src/database/migrations/"
    click QueryBuilder "https://github.com/spawnrider/directus/blob/main/api/src/database/index.ts"
    click AuthService "https://github.com/spawnrider/directus/blob/main/api/src/services/authentication.ts"
    click AuthzService "https://github.com/spawnrider/directus/blob/main/api/src/services/authorization.ts"
    click PermService "https://github.com/spawnrider/directus/blob/main/api/src/services/permissions.ts"
    click FilesService "https://github.com/spawnrider/directus/blob/main/api/src/services/files.ts"
    click AssetsService "https://github.com/spawnrider/directus/blob/main/api/src/services/assets.ts"
    click StorageDrivers "https://github.com/spawnrider/directus/tree/main/packages/drive/"
    click ExtSDK "https://github.com/spawnrider/directus/tree/main/packages/extension-sdk/"
    click ExtTypes "https://github.com/spawnrider/directus/blob/main/packages/shared/src/types/extensions.ts"
    click ItemsService "https://github.com/spawnrider/directus/blob/main/api/src/services/items.ts"
    click CollectionsService "https://github.com/spawnrider/directus/blob/main/api/src/services/collections.ts"
    click FieldsService "https://github.com/spawnrider/directus/blob/main/api/src/services/fields.ts"
    click RelationsService "https://github.com/spawnrider/directus/blob/main/api/src/services/relations.ts"
```
