# schery19/gravity-core architecture

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

- Interactive diagram: https://gitdiagram.com/schery19/gravity-core
- Repository: https://github.com/schery19/gravity-core

## Overview

GRAVITY-CORE is a PHP framework core for routing requests, invoking controller actions, rendering views or JSON, and optionally managing database-backed entities through repositories. The main documented workflow is route registration followed by Router::run(), Route dispatch, controller work, and a rendered response. Separate branches cover resource routes and resource serialization, plus persistence. The README documents template conventions, but templates belong to the consuming application, not this repository. Some resource and exception relationships are based on the source index; unsampled implementation details are not expanded.

Main entry points: [`src/routes/Router.php`](https://github.com/schery19/gravity-core/blob/main/src/routes/Router.php) (Router), [`src/app/Controllers/Controller.php`](https://github.com/schery19/gravity-core/blob/main/src/app/Controllers/Controller.php) (Controller), [`src/app/Repository/Repository.php`](https://github.com/schery19/gravity-core/blob/main/src/app/Repository/Repository.php) (Repository operations), [`src/app/Resources/AbstractResource.php`](https://github.com/schery19/gravity-core/blob/main/src/app/Resources/AbstractResource.php) (Resource serialization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_routing["Routing"]
  node_router["Router<br/>[Router.php]"]
  node_route["Route matcher<br/>[Route.php]"]
  node_resource_routes["Resource routes"]
end

subgraph group_application["Controllers and resources"]
  node_controller["Controller<br/>[Controller.php]"]
  node_resources["Resource serialization"]
  node_resource_array["Resource contract<br/>[ResourceArray.php]"]
end

subgraph group_persistence["Persistence"]
  node_entity["Entity model<br/>[Entity.php]"]
  node_repository["Repository operations<br/>[Repository.php]"]
  node_database["Database adapter<br/>[Database.php]"]
end

subgraph group_errors["Exceptions"]
  node_exceptions["Exception types"]
end

node_request(("HTTP request"))
node_templates["Application views"]
node_sql_store[("SQL database")]

node_request -->|"provides request"| node_router
node_router -->|"registers and matches"| node_route
node_router -->|"loads routes"| node_resource_routes
node_router -->|"raises routing errors"| node_exceptions
node_router -->|"dispatches"| node_route
node_route -->|"invokes action"| node_controller
node_controller -->|"reads route state"| node_router
node_controller -->|"serializes JSON"| node_resources
node_controller -->|"renders view"| node_templates
node_controller -->|"raises render errors"| node_exceptions
node_resources -->|"implements contract"| node_resource_array
node_entity -->|"extends"| node_resources
node_resources -->|"loads entity columns"| node_repository
node_repository -->|"creates entities"| node_entity
node_repository -->|"queries through"| node_database
node_database -->|"executes SQL"| node_sql_store
node_repository -->|"raises data errors"| node_exceptions

click node_router "https://github.com/schery19/gravity-core/blob/main/src/routes/Router.php"
click node_route "https://github.com/schery19/gravity-core/blob/main/src/routes/Route.php"
click node_resource_routes "https://github.com/schery19/gravity-core/tree/main/src/routes"
click node_controller "https://github.com/schery19/gravity-core/blob/main/src/app/Controllers/Controller.php"
click node_resources "https://github.com/schery19/gravity-core/blob/main/src/app/Resources/AbstractResource.php"
click node_resource_array "https://github.com/schery19/gravity-core/blob/main/src/app/ResourceArray.php"
click node_entity "https://github.com/schery19/gravity-core/blob/main/src/app/Entity/Entity.php"
click node_repository "https://github.com/schery19/gravity-core/blob/main/src/app/Repository/Repository.php"
click node_database "https://github.com/schery19/gravity-core/blob/main/src/database/Database.php"
click node_exceptions "https://github.com/schery19/gravity-core/tree/main/src/Exceptions"

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_router,node_route,node_resource_routes,node_templates toneBlue
class node_controller,node_resources,node_resource_array,node_sql_store toneAmber
class node_entity,node_repository,node_database,node_request toneMint
class node_exceptions toneRose
```

## Components

### Routing

- [Router](https://github.com/schery19/gravity-core/blob/main/src/routes/Router.php): `src/routes/Router.php`
- [Route matcher](https://github.com/schery19/gravity-core/blob/main/src/routes/Route.php): `src/routes/Route.php`
- [Resource routes](https://github.com/schery19/gravity-core/tree/main/src/routes): `src/routes`

### Controllers and resources

- [Controller](https://github.com/schery19/gravity-core/blob/main/src/app/Controllers/Controller.php): `src/app/Controllers/Controller.php`
- [Resource serialization](https://github.com/schery19/gravity-core/blob/main/src/app/Resources/AbstractResource.php): `src/app/Resources/AbstractResource.php`
- [Resource contract](https://github.com/schery19/gravity-core/blob/main/src/app/ResourceArray.php): `src/app/ResourceArray.php`

### Persistence

- [Entity model](https://github.com/schery19/gravity-core/blob/main/src/app/Entity/Entity.php): `src/app/Entity/Entity.php`
- [Repository operations](https://github.com/schery19/gravity-core/blob/main/src/app/Repository/Repository.php): `src/app/Repository/Repository.php`
- [Database adapter](https://github.com/schery19/gravity-core/blob/main/src/database/Database.php): `src/database/Database.php`

### Exceptions

- [Exception types](https://github.com/schery19/gravity-core/tree/main/src/Exceptions): `src/Exceptions`

### Other components

- **HTTP request**
- **Application views**
- **SQL database**

## Connections

- HTTP request → Router: provides request (evidence: `README.md`)
- Router → Route matcher: registers and matches (evidence: `src/routes/Router.php`)
- Router → Resource routes: loads routes (evidence: `src/routes/Router.php`)
- Router → Exception types: raises routing errors (evidence: `src/routes/Router.php`)
- Router → Route matcher: dispatches (evidence: `src/routes/Router.php`)
- Route matcher → Controller: invokes action (evidence: `src/routes/Route.php`)
- Controller → Router: reads route state (evidence: `src/app/Controllers/Controller.php`)
- Controller → Resource serialization: serializes JSON (evidence: `src/app/Controllers/Controller.php`)
- Controller → Application views: renders view (evidence: `README.md`)
- Controller → Exception types: raises render errors (evidence: `src/app/Controllers/Controller.php`)
- Resource serialization → Resource contract: implements contract (evidence: `src/app/Resources/AbstractResource.php`)
- Entity model → Resource serialization: extends (evidence: `src/app/Entity/Entity.php`)
- Resource serialization → Repository operations: loads entity columns (evidence: `src/app/Resources/AbstractResource.php`)
- Repository operations → Entity model: creates entities (evidence: `src/app/Repository/Repository.php`)
- Repository operations → Database adapter: queries through (evidence: `src/app/Repository/Repository.php`)
- Database adapter → SQL database: executes SQL (evidence: `src/database/Database.php`)
- Repository operations → Exception types: raises data errors (evidence: `src/app/Repository/Repository.php`)
