# craftcms/cms architecture

> Architecture diagram of the GitHub repository craftcms/cms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/craftcms/cms
- Repository: https://github.com/craftcms/cms

## Overview

Craft is a self-hosted PHP CMS for managing modeled content and delivering custom digital experiences. The principal workflow is a user creating or administering content in the control panel, with elements queried and persisted in a relational database, then rendered through Twig or exposed through GraphQL. The graph also preserves asset handling, authentication, plugins, and console administration. README statements support the product capabilities; where sampled source does not establish internal wiring, relationships are omitted or marked unverified.

Main entry points: [`src/controllers/ElementsController.php`](https://github.com/craftcms/cms/blob/5.x/src/controllers/ElementsController.php) (Control Panel), [`src/base/Element.php`](https://github.com/craftcms/cms/blob/5.x/src/base/Element.php) (Content Elements), [`src/db/Connection.php`](https://github.com/craftcms/cms/blob/5.x/src/db/Connection.php) (Database Connection), [`src/elements/db/ElementQuery.php`](https://github.com/craftcms/cms/blob/5.x/src/elements/db/ElementQuery.php) (Element Queries)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User Experience"]
  node_cp["Control Panel"]
  node_webcontroller["Web Controller<br/>[Controller.php]"]
end

subgraph group_content["Content Modeling"]
  node_elements["Content Elements<br/>[Element.php]"]
  node_elementinterface["Element Contract"]
  node_users["User Elements<br/>[User.php]"]
  node_elementcollection["Element Collections"]
  node_elementquery["Element Queries<br/>[ElementQuery.php]"]
  node_queryinterface["Query Contract"]
  node_fieldlayout["Field Layouts<br/>[FieldLayout.php]"]
end

subgraph group_data["Data and Storage"]
  node_dbquery["Database Queries<br/>[Query.php]"]
  node_connection["Database Connection<br/>[Connection.php]"]
  node_database[("Relational Database")]
end

subgraph group_delivery["Content Delivery"]
  node_twig["Twig Templates<br/>[Routes.php]"]
  node_graphql["GraphQL API<br/>[Query.php]"]
  node_response["HTTP Responses<br/>[Response.php]"]
  node_assets["Asset Previews"]
end

subgraph group_platform["Platform Services"]
  node_auth["Authentication<br/>[TOTP.php]"]
  node_sso["Single Sign-On<br/>[BaseProvider.php]"]
  node_plugins["Plugin Framework<br/>[Plugin.php]"]
  node_console["Console Administration<br/>[Controller.php]"]
  node_apphelper["Application Helpers<br/>[App.php]"]
  node_arrayhelper["Array Utilities<br/>[ArrayHelper.php]"]
  node_dbhelper["Database Utilities<br/>[Db.php]"]
  node_elementhelper["Element Utilities<br/>[ElementHelper.php]"]
  node_filehelper["File Utilities<br/>[FileHelper.php]"]
  node_stringhelper["String Utilities<br/>[StringHelper.php]"]
  node_urlhelper["URL Utilities<br/>[UrlHelper.php]"]
end

node_editor(("CMS User"))

node_editor -->|"administers content"| node_cp
node_editor -->|"views experience"| node_twig
node_cp -.->|"manages content"| node_elements
node_elements -.->|"implements contract"| node_elementinterface
node_users -.->|"implements contract"| node_elementinterface
node_elementquery -.->|"implements contract"| node_queryinterface
node_elementquery -.->|"queries through"| node_dbquery
node_dbquery -.->|"executes through"| node_connection
node_connection -->|"connects to"| node_database
node_elements -.->|"returns collections"| node_elementcollection
node_fieldlayout -.->|"models fields for"| node_elements
node_cp -.->|"handles requests"| node_webcontroller
node_webcontroller -.->|"sends responses"| node_response
node_editor -->|"queries content"| node_graphql
node_graphql -.->|"queries elements"| node_elementquery
node_editor -.->|"manages assets"| node_assets
node_editor -.->|"authenticates"| node_auth
node_auth -.->|"supports providers"| node_sso
node_plugins -->|"extends capabilities"| node_cp
node_editor -.->|"administers by CLI"| node_console
node_apphelper -.->|"configures database"| node_connection
node_dbhelper -.->|"executes database operations"| node_connection

click node_cp "https://github.com/craftcms/cms/blob/5.x/src/controllers/ElementsController.php"
click node_webcontroller "https://github.com/craftcms/cms/blob/5.x/src/web/Controller.php"
click node_elements "https://github.com/craftcms/cms/blob/5.x/src/base/Element.php"
click node_elementinterface "https://github.com/craftcms/cms/blob/5.x/src/base/ElementInterface.php"
click node_users "https://github.com/craftcms/cms/blob/5.x/src/elements/User.php"
click node_elementcollection "https://github.com/craftcms/cms/blob/5.x/src/elements/ElementCollection.php"
click node_elementquery "https://github.com/craftcms/cms/blob/5.x/src/elements/db/ElementQuery.php"
click node_queryinterface "https://github.com/craftcms/cms/blob/5.x/src/elements/db/ElementQueryInterface.php"
click node_fieldlayout "https://github.com/craftcms/cms/blob/5.x/src/models/FieldLayout.php"
click node_dbquery "https://github.com/craftcms/cms/blob/5.x/src/db/Query.php"
click node_connection "https://github.com/craftcms/cms/blob/5.x/src/db/Connection.php"
click node_twig "https://github.com/craftcms/cms/blob/5.x/src/web/twig/variables/Routes.php"
click node_graphql "https://github.com/craftcms/cms/blob/5.x/src/gql/types/Query.php"
click node_response "https://github.com/craftcms/cms/blob/5.x/src/web/Response.php"
click node_assets "https://github.com/craftcms/cms/blob/5.x/src/base/AssetPreviewHandler.php"
click node_auth "https://github.com/craftcms/cms/blob/5.x/src/auth/methods/TOTP.php"
click node_sso "https://github.com/craftcms/cms/blob/5.x/src/auth/sso/BaseProvider.php"
click node_plugins "https://github.com/craftcms/cms/blob/5.x/src/base/Plugin.php"
click node_console "https://github.com/craftcms/cms/blob/5.x/src/console/Controller.php"
click node_apphelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/App.php"
click node_arrayhelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/ArrayHelper.php"
click node_dbhelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/Db.php"
click node_elementhelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/ElementHelper.php"
click node_filehelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/FileHelper.php"
click node_stringhelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/StringHelper.php"
click node_urlhelper "https://github.com/craftcms/cms/blob/5.x/src/helpers/UrlHelper.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cp,node_webcontroller,node_editor toneBlue
class node_elements,node_elementinterface,node_users,node_elementcollection,node_elementquery,node_queryinterface,node_fieldlayout toneAmber
class node_dbquery,node_connection,node_database toneMint
class node_twig,node_graphql,node_response,node_assets toneRose
class node_auth,node_sso,node_plugins,node_console,node_apphelper,node_arrayhelper,node_dbhelper,node_elementhelper,node_filehelper,node_stringhelper,node_urlhelper toneIndigo
```

## Components

### User Experience

- [Control Panel](https://github.com/craftcms/cms/blob/5.x/src/controllers/ElementsController.php): `src/controllers/ElementsController.php`
- [Web Controller](https://github.com/craftcms/cms/blob/5.x/src/web/Controller.php): `src/web/Controller.php`

### Content Modeling

- [Content Elements](https://github.com/craftcms/cms/blob/5.x/src/base/Element.php): `src/base/Element.php`
- [Element Contract](https://github.com/craftcms/cms/blob/5.x/src/base/ElementInterface.php): `src/base/ElementInterface.php`
- [User Elements](https://github.com/craftcms/cms/blob/5.x/src/elements/User.php): `src/elements/User.php`
- [Element Collections](https://github.com/craftcms/cms/blob/5.x/src/elements/ElementCollection.php): `src/elements/ElementCollection.php`
- [Element Queries](https://github.com/craftcms/cms/blob/5.x/src/elements/db/ElementQuery.php): `src/elements/db/ElementQuery.php`
- [Query Contract](https://github.com/craftcms/cms/blob/5.x/src/elements/db/ElementQueryInterface.php): `src/elements/db/ElementQueryInterface.php`
- [Field Layouts](https://github.com/craftcms/cms/blob/5.x/src/models/FieldLayout.php): `src/models/FieldLayout.php`

### Data and Storage

- [Database Queries](https://github.com/craftcms/cms/blob/5.x/src/db/Query.php): `src/db/Query.php`
- [Database Connection](https://github.com/craftcms/cms/blob/5.x/src/db/Connection.php): `src/db/Connection.php`
- **Relational Database**

### Content Delivery

- [Twig Templates](https://github.com/craftcms/cms/blob/5.x/src/web/twig/variables/Routes.php): `src/web/twig/variables/Routes.php`
- [GraphQL API](https://github.com/craftcms/cms/blob/5.x/src/gql/types/Query.php): `src/gql/types/Query.php`
- [HTTP Responses](https://github.com/craftcms/cms/blob/5.x/src/web/Response.php): `src/web/Response.php`
- [Asset Previews](https://github.com/craftcms/cms/blob/5.x/src/base/AssetPreviewHandler.php): `src/base/AssetPreviewHandler.php`

### Platform Services

- [Authentication](https://github.com/craftcms/cms/blob/5.x/src/auth/methods/TOTP.php): `src/auth/methods/TOTP.php`
- [Single Sign-On](https://github.com/craftcms/cms/blob/5.x/src/auth/sso/BaseProvider.php): `src/auth/sso/BaseProvider.php`
- [Plugin Framework](https://github.com/craftcms/cms/blob/5.x/src/base/Plugin.php): `src/base/Plugin.php`
- [Console Administration](https://github.com/craftcms/cms/blob/5.x/src/console/Controller.php): `src/console/Controller.php`
- [Application Helpers](https://github.com/craftcms/cms/blob/5.x/src/helpers/App.php): `src/helpers/App.php`
- [Array Utilities](https://github.com/craftcms/cms/blob/5.x/src/helpers/ArrayHelper.php): `src/helpers/ArrayHelper.php`
- [Database Utilities](https://github.com/craftcms/cms/blob/5.x/src/helpers/Db.php): `src/helpers/Db.php`
- [Element Utilities](https://github.com/craftcms/cms/blob/5.x/src/helpers/ElementHelper.php): `src/helpers/ElementHelper.php`
- [File Utilities](https://github.com/craftcms/cms/blob/5.x/src/helpers/FileHelper.php): `src/helpers/FileHelper.php`
- [String Utilities](https://github.com/craftcms/cms/blob/5.x/src/helpers/StringHelper.php): `src/helpers/StringHelper.php`
- [URL Utilities](https://github.com/craftcms/cms/blob/5.x/src/helpers/UrlHelper.php): `src/helpers/UrlHelper.php`

### Other components

- **CMS User**

## Connections

- CMS User → Control Panel: administers content
- CMS User → Twig Templates: views experience
- Control Panel → Content Elements: manages content (evidence: `src/base/Element.php`)
- Content Elements → Element Contract: implements contract
- User Elements → Element Contract: implements contract (evidence: `src/elements/User.php`)
- Element Queries → Query Contract: implements contract (evidence: `src/elements/db/ElementQuery.php`)
- Element Queries → Database Queries: queries through (evidence: `src/elements/db/ElementQuery.php`)
- Database Queries → Database Connection: executes through (evidence: `src/db/Query.php`)
- Database Connection → Relational Database: connects to
- Content Elements → Element Collections: returns collections (evidence: `src/base/Element.php`)
- Field Layouts → Content Elements: models fields for
- Control Panel → Web Controller: handles requests
- Web Controller → HTTP Responses: sends responses (evidence: `src/web/Controller.php`)
- CMS User → GraphQL API: queries content
- GraphQL API → Element Queries: queries elements
- CMS User → Asset Previews: manages assets
- CMS User → Authentication: authenticates
- Authentication → Single Sign-On: supports providers
- Plugin Framework → Control Panel: extends capabilities
- CMS User → Console Administration: administers by CLI
- Application Helpers → Database Connection: configures database (evidence: `src/helpers/App.php`)
- Database Utilities → Database Connection: executes database operations (evidence: `src/helpers/Db.php`)
