# barryvdh/laravel-cors architecture

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

- Interactive diagram: https://gitdiagram.com/barryvdh/laravel-cors
- Repository: https://github.com/barryvdh/laravel-cors

## Overview

This is Laravel middleware for applying CORS policy to matching requests. A browser request enters the middleware, which checks configured paths; preflight requests receive a dedicated response, while other matching requests continue through Laravel and then receive CORS headers. The provider loads configuration and registers the CORS service. The tree does not include that service’s implementation, so its internal policy steps are not expanded; configuration options and Lumen support are documented in the README and source.

Main entry points: [`src/HandleCors.php`](https://github.com/barryvdh/laravel-cors/blob/master/src/HandleCors.php) (Request middleware), [`src/CorsServiceProvider.php`](https://github.com/barryvdh/laravel-cors/blob/master/src/CorsServiceProvider.php) (Service provider), [`config/cors.php`](https://github.com/barryvdh/laravel-cors/blob/master/config/cors.php) (CORS configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_setup["Service setup"]
  node_provider["Service provider"]
end

subgraph group_request["Request handling"]
  node_middleware["Request middleware<br/>[HandleCors.php]"]
  node_laravel_pipeline["Laravel pipeline"]
  node_response["HTTP response"]
end

subgraph group_policy["CORS policy"]
  node_config["CORS configuration<br/>[cors.php]"]
  node_cors_engine["PHP CORS service"]
end

node_browser(("Browser client"))

node_browser -->|"sends request"| node_middleware
node_provider -->|"loads defaults"| node_config
node_provider -->|"constructs with config"| node_cors_engine
node_provider -->|"provides service"| node_middleware
node_middleware -->|"reads paths"| node_config
node_middleware -->|"checks and adds headers"| node_cors_engine
node_middleware -->|"continues request"| node_laravel_pipeline
node_laravel_pipeline -->|"returns response"| node_middleware
node_middleware -->|"returns response"| node_response
node_browser -->|"receives response"| node_response

click node_provider "https://github.com/barryvdh/laravel-cors/blob/master/src/CorsServiceProvider.php"
click node_config "https://github.com/barryvdh/laravel-cors/blob/master/config/cors.php"
click node_middleware "https://github.com/barryvdh/laravel-cors/blob/master/src/HandleCors.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_provider,node_browser toneBlue
class node_middleware,node_laravel_pipeline,node_response toneAmber
class node_config,node_cors_engine toneMint
```

## Components

### Service setup

- [Service provider](https://github.com/barryvdh/laravel-cors/blob/master/src/CorsServiceProvider.php): `src/CorsServiceProvider.php`

### Request handling

- [Request middleware](https://github.com/barryvdh/laravel-cors/blob/master/src/HandleCors.php): `src/HandleCors.php`
- **Laravel pipeline**
- **HTTP response**

### CORS policy

- [CORS configuration](https://github.com/barryvdh/laravel-cors/blob/master/config/cors.php): `config/cors.php`
- **PHP CORS service**

### Other components

- **Browser client**

## Connections

- Browser client → Request middleware: sends request
- Service provider → CORS configuration: loads defaults
- Service provider → PHP CORS service: constructs with config
- Service provider → Request middleware: provides service
- Request middleware → CORS configuration: reads paths
- Request middleware → PHP CORS service: checks and adds headers
- Request middleware → Laravel pipeline: continues request
- Laravel pipeline → Request middleware: returns response
- Request middleware → HTTP response: returns response
- Browser client → HTTP response: receives response
