# api-platform/core architecture

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

- Interactive diagram: https://gitdiagram.com/api-platform/core
- Repository: https://github.com/api-platform/core

## Overview

Based on both the file tree and the README, this project is the core engine of API Platform – a library that provides a powerful, configurable platform for building hypermedia-driven REST and GraphQL APIs. It is designed to easily integrate with frameworks such as Symfony (and even Laravel via its bundle) and supports many formats (JSON-LD, HAL, JSON:API, OpenAPI, etc.) as well as advanced features such as metadata extraction, state processing, serialization, filtering, pagination, and integration with external systems (Doctrine ORM/ODM, Elasticsearch, etc.).

- API Request Entry Points: Represent the HTTP/GraphQL endpoints. Include controllers and actions (notably in the Symfony and Laravel directories) where incoming requests are received.
- Routing and IRI Conversion: Show how the routing components (e.g., IriConverter and Router in src/Symfony/Routing and src/Laravel/Routing) direct requests to the proper controllers.
- API Resource & Metadata Engine: A major portion of the project is dedicated to resource discovery and metadata extraction. This is represented through the “src/Metadata” sub-tree. Also include factories for resource metadata, property metadata, and identifiers.
- State Processors & Providers: There is a dedicated area in “src/State” that handles resource state management – persisting, updating, deleting, and even pagination. This layer applies business rules and handles state changes.
- Serialization and Deserialization: Under “src/Serializer” and related directories (Hal, JsonApi, JsonLd, etc.), show the components that convert PHP objects to the various supported API representations and vice versa.
- Data Source Integrations: There are separate modules for Doctrine (ORM/ODM), Elasticsearch, and even GraphQL resolvers (src/GraphQl) that handle complex data integration.
- External API Documentation & Format Export: Several modules (e.g., src/OpenApi, src/JsonSchema) generate API documentation and schema definitions.
- Bundles & Framework Integration: Represent the integration layers provided for specific frameworks (e.g., Symfony’s bundle located in src/Symfony/Bundle and Laravel in src/Laravel) that plug the core functionality into the hosting framework’s ecosystem.

##### Relationships & Data Flow
- How state processors (persist, update, delete) interact with data providers (Doctrine, ODM, Elasticsearch) and then feed the results into the serializers.
- How the serialization layer supports multiple output formats (JSON-LD, HAL, JSON:API, etc.) by mapping resources to various serializers.
- How the integration bundles (“src/Symfony/Bundle”, “src/Laravel”) wrap this core functionality to produce framework-specific behaviors (middleware, dependency injection configurations, routing definitions).

##### Architecture Patterns and Design Principles
- Layered Architecture: Demonstrate the separation between the API entry points (controllers), business logic (metadata, state, and processing), and infrastructure (data providers and integration layers).
- Extensibility and Inversion of Control: Show how factories, dependency injection, and compiler passes (e.g., in the Symfony bundle’s DependencyInjection/Compiler folder) allow for extensive customization.
- Separation of Concerns: Emphasize that each module (Metadata, State, Serializer, etc.) is a distinct component that can be maintained, extended, or overridden independently.

## Diagram (Mermaid)

```mermaid
graph TD
    %% API Interface Layer
    subgraph "API Interface Layer"
        A1["Incoming HTTP/GraphQL Request"]:::interfaceLayer
        A2["Symfony Routing/IRI Conversion"]:::interfaceLayer
        A3["Laravel Routing/IRI Conversion"]:::interfaceLayer
        A4["Symfony Controller"]:::interfaceLayer
        A5["Laravel Controller"]:::interfaceLayer
    end

    %% Core Engine
    subgraph "Core Engine"
        B1["API Resource & Metadata Engine"]:::coreEngine
        B2["State Processors & Providers"]:::coreEngine
    end

    %% Data & Serialization Layer
    subgraph "Data & Serialization"
        subgraph "Data Source Integrations"
            C1["Doctrine Integration"]:::dataIntegration
            C2["Elasticsearch Integration"]:::dataIntegration
            C3["GraphQL Resolvers"]:::dataIntegration
        end
        C4["Serialization Modules (HAL,JSON:API,JSON-LD)"]:::serialization
    end

    %% External Documentation & Format Export
    subgraph "External Documentation & Format Export"
        D1["OpenAPI Documentation"]:::documentation
        D2["JSON Schema Generator"]:::documentation
        D3["Hydra Support"]:::documentation
        D4["JSON-LD Support"]:::documentation
        D5["JSON:API Support"]:::documentation
    end

    %% Bundles & Framework Integration
    subgraph "Integration Bundles"
        E1["Symfony Bundle Integration"]:::bundles
        E2["Laravel Integration"]:::bundles
    end

    %% Connections - API Interface Layer
    A1 --> A2
    A1 --> A3
    A2 --> A4
    A3 --> A5
    E1 --> A4
    E2 --> A5

    %% Connections - Core Engine
    A4 --> B1
    A5 --> B1
    B1 --> B2

    %% Connections - Data & Serialization
    B2 --> C1
    B2 --> C2
    B2 --> C3
    C1 --> C4
    C2 --> C4
    C3 --> C4

    %% Connections - External Documentation
    C4 --> D1
    C4 --> D2
    C4 --> D3
    C4 --> D4
    C4 --> D5

    %% Click Events
    click A2 "https://github.com/api-platform/core/tree/main/src/Symfony/Routing/" "Open Symfony routing & IRI conversion"
    click A3 "https://github.com/api-platform/core/tree/main/src/Laravel/Routing/" "Open Laravel routing & IRI conversion"
    click A4 "https://github.com/api-platform/core/tree/main/src/Symfony/Controller/" "Open Symfony controllers"
    click A5 "https://github.com/api-platform/core/blob/main/src/Laravel/Controller/ApiPlatformController.php" "Open Laravel controller"
    click B1 "https://github.com/api-platform/core/tree/main/src/Metadata/" "Open Metadata Engine"
    click B2 "https://github.com/api-platform/core/tree/main/src/State/" "Open State Processors"
    click C1 "https://github.com/api-platform/core/tree/main/src/Doctrine/" "Open Doctrine integration"
    click C2 "https://github.com/api-platform/core/tree/main/src/Elasticsearch/" "Open Elasticsearch integration"
    click C3 "https://github.com/api-platform/core/tree/main/src/GraphQl/" "Open GraphQL resolvers"
    click C4 "https://github.com/api-platform/core/tree/main/src/Serializer/" "Open Serialization modules"
    click D1 "https://github.com/api-platform/core/tree/main/src/OpenApi/" "Open OpenAPI documentation"
    click D2 "https://github.com/api-platform/core/tree/main/src/JsonSchema/" "Open JSON Schema generator"
    click D3 "https://github.com/api-platform/core/tree/main/src/Hydra/" "Open Hydra support"
    click D4 "https://github.com/api-platform/core/tree/main/src/JsonLd/" "Open JSON-LD support"
    click D5 "https://github.com/api-platform/core/tree/main/src/JsonApi/" "Open JSON:API support"
    click E1 "https://github.com/api-platform/core/tree/main/src/Symfony/Bundle/" "Open Symfony bundle integration"
    click E2 "https://github.com/api-platform/core/tree/main/src/Laravel/" "Open Laravel integration"

    %% Styles
    classDef interfaceLayer fill:#b3cde0,stroke:#000,stroke-width:1px;
    classDef coreEngine fill:#ccebc5,stroke:#000,stroke-width:1px;
    classDef dataIntegration fill:#decbe4,stroke:#000,stroke-width:1px;
    classDef serialization fill:#fed9a6,stroke:#000,stroke-width:1px;
    classDef documentation fill:#fbb4ae,stroke:#000,stroke-width:1px;
    classDef bundles fill:#ffffcc,stroke:#000,stroke-width:1px;
```
