# grimzy/laravel-mysql-spatial architecture

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

- Interactive diagram: https://gitdiagram.com/grimzy/laravel-mysql-spatial
- Repository: https://github.com/grimzy/laravel-mysql-spatial

## Overview

This package extends Laravel’s database and Eloquent layers so applications can define MySQL spatial columns, persist typed geometries, retrieve them as objects, and query by spatial relationships or distance. The main path runs from Laravel application code through the registered MySQL connection and spatial schema/query extensions to MySQL. Geometry value types provide WKT/WKB and GeoJSON representations. README capabilities include SRID-aware fields and geometries, spatial indexes, and distance ordering. The graph follows documented behavior and sampled source; unsampled subsystem wiring is left out.

Main entry points: [`src/Types/Geometry.php`](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/Geometry.php) (Geometry types), [`src/Eloquent/SpatialTrait.php`](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/SpatialTrait.php) (Spatial trait), [`src/MysqlConnection.php`](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/MysqlConnection.php) (MySQL connection), [`src/SpatialServiceProvider.php`](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/SpatialServiceProvider.php) (Service provider)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_integration["Laravel integration"]
  node_provider["Service provider"]
  node_factory["Connection factory"]
  node_connection["MySQL connection"]
end

subgraph group_schema["Spatial schema"]
  node_schema_builder["Schema builder<br/>[Builder.php]"]
  node_blueprint["Spatial blueprint<br/>[Blueprint.php]"]
  node_grammar["MySQL grammar<br/>[MySqlGrammar.php]"]
end

subgraph group_eloquent["Eloquent spatial data"]
  node_trait["Spatial trait<br/>[SpatialTrait.php]"]
  node_builder["Spatial query builder<br/>[Builder.php]"]
  node_base_builder["Base query builder<br/>[BaseBuilder.php]"]
  node_expression["Spatial expression"]
end

subgraph group_geometry["Geometry values"]
  node_geometry["Geometry types<br/>[Geometry.php]"]
  node_factory_types["Type factory<br/>[Factory.php]"]
  node_collections["Geometry collections"]
end

node_app(("Laravel application"))
node_mysql[("MySQL")]
node_doctrine["Doctrine DBAL"]
node_model["Eloquent model"]
node_geojson["GeoJSON library"]

node_app -->|"registers"| node_provider
node_provider -->|"binds"| node_factory
node_factory -->|"creates"| node_connection
node_connection -->|"provides"| node_schema_builder
node_connection -->|"connects"| node_mysql
node_connection -.->|"registers mappings"| node_doctrine
node_provider -.->|"registers types"| node_doctrine
node_app -->|"defines schema"| node_schema_builder
node_schema_builder -->|"creates"| node_blueprint
node_blueprint -->|"compiles spatial SQL"| node_grammar
node_grammar -->|"emits SQL"| node_mysql
node_app -->|"uses"| node_model
node_model -->|"uses"| node_trait
node_trait -->|"creates"| node_builder
node_trait -->|"creates"| node_base_builder
node_trait -->|"wraps geometry"| node_expression
node_base_builder -->|"binds value"| node_expression
node_trait -->|"parses WKB"| node_geometry
node_trait -->|"queries spatial functions"| node_mysql
node_app -->|"creates geometry"| node_geometry
node_factory_types -->|"constructs types"| node_geometry
node_collections -->|"contains geometries"| node_geometry
node_collections -->|"converts GeoJSON"| node_geojson
node_geometry -->|"converts GeoJSON"| node_geojson
node_geometry -->|"encodes spatial values"| node_mysql
node_mysql -->|"returns spatial values"| node_geometry

click node_provider "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/SpatialServiceProvider.php"
click node_factory "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Connectors/ConnectionFactory.php"
click node_connection "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/MysqlConnection.php"
click node_schema_builder "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Schema/Builder.php"
click node_blueprint "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Schema/Blueprint.php"
click node_grammar "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Schema/Grammars/MySqlGrammar.php"
click node_trait "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/SpatialTrait.php"
click node_builder "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/Builder.php"
click node_base_builder "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/BaseBuilder.php"
click node_expression "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/SpatialExpression.php"
click node_geometry "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/Geometry.php"
click node_factory_types "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/Factory.php"
click node_collections "https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/GeometryCollection.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_factory,node_connection toneBlue
class node_schema_builder,node_blueprint,node_grammar,node_mysql toneAmber
class node_trait,node_builder,node_base_builder,node_expression toneMint
class node_geometry,node_factory_types,node_collections toneRose
class node_app,node_doctrine,node_model,node_geojson toneIndigo
```

## Components

### Laravel integration

- [Service provider](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/SpatialServiceProvider.php): `src/SpatialServiceProvider.php`
- [Connection factory](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Connectors/ConnectionFactory.php): `src/Connectors/ConnectionFactory.php`
- [MySQL connection](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/MysqlConnection.php): `src/MysqlConnection.php`

### Spatial schema

- [Schema builder](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Schema/Builder.php): `src/Schema/Builder.php`
- [Spatial blueprint](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Schema/Blueprint.php): `src/Schema/Blueprint.php`
- [MySQL grammar](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Schema/Grammars/MySqlGrammar.php): `src/Schema/Grammars/MySqlGrammar.php`

### Eloquent spatial data

- [Spatial trait](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/SpatialTrait.php): `src/Eloquent/SpatialTrait.php`
- [Spatial query builder](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/Builder.php): `src/Eloquent/Builder.php`
- [Base query builder](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/BaseBuilder.php): `src/Eloquent/BaseBuilder.php`
- [Spatial expression](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Eloquent/SpatialExpression.php): `src/Eloquent/SpatialExpression.php`

### Geometry values

- [Geometry types](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/Geometry.php): `src/Types/Geometry.php`
- [Type factory](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/Factory.php): `src/Types/Factory.php`
- [Geometry collections](https://github.com/grimzy/laravel-mysql-spatial/blob/master/src/Types/GeometryCollection.php): `src/Types/GeometryCollection.php`

### Other components

- **Laravel application**
- **MySQL**
- **Doctrine DBAL**
- **Eloquent model**
- **GeoJSON library**

## Connections

- Laravel application → Service provider: registers
- Service provider → Connection factory: binds
- Connection factory → MySQL connection: creates
- MySQL connection → Schema builder: provides
- MySQL connection → MySQL: connects
- MySQL connection → Doctrine DBAL: registers mappings
- Service provider → Doctrine DBAL: registers types
- Laravel application → Schema builder: defines schema
- Schema builder → Spatial blueprint: creates
- Spatial blueprint → MySQL grammar: compiles spatial SQL
- MySQL grammar → MySQL: emits SQL
- Laravel application → Eloquent model: uses
- Eloquent model → Spatial trait: uses
- Spatial trait → Spatial query builder: creates
- Spatial trait → Base query builder: creates
- Spatial trait → Spatial expression: wraps geometry
- Base query builder → Spatial expression: binds value
- Spatial trait → Geometry types: parses WKB
- Spatial trait → MySQL: queries spatial functions
- Laravel application → Geometry types: creates geometry
- Type factory → Geometry types: constructs types
- Geometry collections → Geometry types: contains geometries
- Geometry collections → GeoJSON library: converts GeoJSON
- Geometry types → GeoJSON library: converts GeoJSON
- Geometry types → MySQL: encodes spatial values
- MySQL → Geometry types: returns spatial values
