# alfredo1995/erp architecture

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

- Interactive diagram: https://gitdiagram.com/alfredo1995/erp
- Repository: https://github.com/alfredo1995/erp

## Overview

#### Purpose and Entry Points
This is a Laravel 8 migration of a legacy PHP ERP-style supplier database application. It manages suppliers, products, purchasing orders, sales products, and sales orders. HTTP requests enter through `server.php`/`public`-style Laravel bootstrap conventions, initialize at `bootstrap/app.php`, and pass through `app/Http/Kernel.php`. CLI operations use `artisan` and `app/Console/Kernel.php`.

#### Routing and HTTP Boundary
Route definitions separate browser and API surfaces:
- `routes/web.php`
- `routes/api.php`
- `routes/channels.php`

The intended primary UI flow is resource-like CRUD routing, especially for suppliers (`fornecedores`). Controllers receive requests after Laravel’s middleware stack, including authentication, CSRF protection, cookie encryption, proxy handling, and maintenance mode controls in `app/Http/Middleware/`.

#### Domain Controllers
Application orchestration is concentrated in CRUD controllers:
- `app/Http/Controllers/FornecedorController.php`
- `app/Http/Controllers/ProdutoController.php`
- `app/Http/Controllers/PedidoController.php`
- `app/Http/Controllers/PedidoVendaController.php`
- `app/Http/Controllers/ProdutoVendaController.php`

These controllers are expected to list records, render create/edit views, persist request fields, redirect to named routes, and use route-model binding for updates/deletes. The README documents this pattern primarily for `FornecedorController`.

#### Persistence and Legacy Schema Mapping
Eloquent models form the persistence boundary to MySQL:
- `app/Models/Fornecedor.php`
- `app/Models/Produto.php`
- `app/Models/Pedido.php`
- `app/Models/PedidoVenda.php`
- `app/Models/ProdutoVenda.php`
- `app/Models/Banco.php`
- `app/Models/Estado.php`

The supplier model is intended to map to legacy table `sp_supplier`, use `sup_id` as its primary key, disable timestamps, and whitelist legacy fields for mass assignment. This makes the app dependent on imported legacy database structure rather than solely Laravel-created schema.

#### Primary Data Flow
A typical supplier lifecycle is: browser form → named route in `routes/web.php` → `FornecedorController` → `Fornecedor` Eloquent model → MySQL database → redirect back to a listing view. Index actions retrieve records via Eloquent; create/edit actions supply form data; store/update actions persist request input; destroy removes the bound model. Product and order controllers appear designed to follow the same CRUD control flow.

#### Runtime, Infrastructure, and External Dependencies
The material runtime is PHP/Laravel 8 with Composer (`composer.lock`) and MySQL, configured through `config/database.php`. The documented deployment expects a local MySQL database named `Fornecedores` with a manually imported legacy database. Front-end asset compilation is available through Laravel Mix in `webpack.mix.js`; the README references Bootstrap 5-oriented scaffold views, though no view files are present in the supplied tree.

#### Framework Services and Operational Boundaries
Laravel service providers wire application, auth, events, routes, and broadcasting:
- `app/Providers/AppServiceProvider.php`
- `app/Providers/AuthServiceProvider.php`
- `app/Providers/RouteServiceProvider.php`

Authentication/session behavior is configured under `config/auth.php` and `config/session.php`. Queue, cache, mail, filesystems, logging, and broadcasting have standard Laravel configuration files, but the repository tree provides no evidence that the business flows actively integrate external mail, queue workers, or broadcast services.

Main entry points: [`routes/web.php`](https://github.com/alfredo1995/erp/blob/main/routes/web.php) (Browser routes), [`app/Models/Fornecedor.php`](https://github.com/alfredo1995/erp/blob/main/app/Models/Fornecedor.php) (Legacy Eloquent models), [`bootstrap/app.php`](https://github.com/alfredo1995/erp/blob/main/bootstrap/app.php) (Application bootstrap), [`app/Providers/AppServiceProvider.php`](https://github.com/alfredo1995/erp/blob/main/app/Providers/AppServiceProvider.php) (Service providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Runtime Entry"]
  node_server(("PHP web entry<br/>entrypoint<br/>[server.php]"))
  node_bootstrap["Application bootstrap<br/>Laravel bootstrap<br/>[app.php]"]
  node_artisan(("Artisan CLI<br/>CLI entrypoint"))
  node_console_kernel["Console kernel<br/>Laravel kernel<br/>[Kernel.php]"]
end

subgraph group_http["HTTP Boundary"]
  node_http_kernel["HTTP kernel<br/>Laravel kernel<br/>[Kernel.php]"]
  node_middleware["HTTP middleware<br/>request middleware"]
  node_web_routes["Browser routes<br/>web routes<br/>[web.php]"]
  node_api_routes["API routes<br/>[api.php]"]
  node_channel_routes["Channel routes<br/>broadcast routes<br/>[channels.php]"]
end

subgraph group_domain["CRUD Domain"]
  node_supplier_controller["Supplier CRUD<br/>controller"]
  node_product_controller["Product CRUD<br/>controller"]
  node_purchase_controller["Purchase order CRUD<br/>controller"]
  node_sales_order_controller["Sales order CRUD<br/>controller"]
  node_sales_product_controller["Sales product CRUD<br/>controller"]
end

subgraph group_data["Persistence &amp; Infrastructure"]
  node_eloquent_models["Legacy Eloquent models<br/>persistence models<br/>[Fornecedor.php]"]
  node_mysql[("Legacy MySQL database<br/>[database.php]")]
  node_service_providers["Service providers<br/>Laravel providers"]
  node_auth_session["Auth &amp; sessions<br/>framework configuration<br/>[auth.php]"]
  node_asset_build["Laravel Mix assets<br/>asset pipeline<br/>[webpack.mix.js]"]
end

node_server -->|"bootstraps"| node_bootstrap
node_artisan -->|"bootstraps"| node_bootstrap
node_artisan -->|"runs commands through"| node_console_kernel
node_bootstrap -->|"creates HTTP app"| node_http_kernel
node_bootstrap -->|"loads"| node_service_providers
node_http_kernel -->|"executes"| node_middleware
node_middleware -->|"dispatches browser requests"| node_web_routes
node_middleware -->|"dispatches API requests"| node_api_routes
node_web_routes -->|"supplier CRUD"| node_supplier_controller
node_web_routes -->|"product CRUD"| node_product_controller
node_web_routes -->|"purchase CRUD"| node_purchase_controller
node_web_routes -->|"sales-order CRUD"| node_sales_order_controller
node_web_routes -->|"sales-product CRUD"| node_sales_product_controller
node_supplier_controller -->|"CRUD and route binding"| node_eloquent_models
node_product_controller -->|"CRUD"| node_eloquent_models
node_purchase_controller -->|"CRUD"| node_eloquent_models
node_sales_order_controller -->|"CRUD"| node_eloquent_models
node_sales_product_controller -->|"CRUD"| node_eloquent_models
node_eloquent_models -->|"reads and persists"| node_mysql
node_service_providers -->|"registers routes"| node_web_routes
node_service_providers -->|"configures auth services"| node_auth_session
node_auth_session -->|"supports sessions and auth"| node_middleware

click node_server "https://github.com/alfredo1995/erp/blob/main/server.php"
click node_bootstrap "https://github.com/alfredo1995/erp/blob/main/bootstrap/app.php"
click node_artisan "https://github.com/alfredo1995/erp/blob/main/artisan"
click node_console_kernel "https://github.com/alfredo1995/erp/blob/main/app/Console/Kernel.php"
click node_http_kernel "https://github.com/alfredo1995/erp/blob/main/app/Http/Kernel.php"
click node_web_routes "https://github.com/alfredo1995/erp/blob/main/routes/web.php"
click node_api_routes "https://github.com/alfredo1995/erp/blob/main/routes/api.php"
click node_channel_routes "https://github.com/alfredo1995/erp/blob/main/routes/channels.php"
click node_supplier_controller "https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/FornecedorController.php"
click node_product_controller "https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/ProdutoController.php"
click node_purchase_controller "https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/PedidoController.php"
click node_sales_order_controller "https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/PedidoVendaController.php"
click node_sales_product_controller "https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/ProdutoVendaController.php"
click node_eloquent_models "https://github.com/alfredo1995/erp/blob/main/app/Models/Fornecedor.php"
click node_mysql "https://github.com/alfredo1995/erp/blob/main/config/database.php"
click node_service_providers "https://github.com/alfredo1995/erp/blob/main/app/Providers/AppServiceProvider.php"
click node_auth_session "https://github.com/alfredo1995/erp/blob/main/config/auth.php"
click node_asset_build "https://github.com/alfredo1995/erp/blob/main/webpack.mix.js"

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_server,node_bootstrap,node_artisan,node_console_kernel toneBlue
class node_http_kernel,node_middleware,node_web_routes,node_api_routes,node_channel_routes toneAmber
class node_supplier_controller,node_product_controller,node_purchase_controller,node_sales_order_controller,node_sales_product_controller toneMint
class node_eloquent_models,node_mysql,node_service_providers,node_auth_session,node_asset_build toneRose
```

## Components

### Runtime Entry

- [PHP web entry](https://github.com/alfredo1995/erp/blob/main/server.php): entrypoint · `server.php`
- [Application bootstrap](https://github.com/alfredo1995/erp/blob/main/bootstrap/app.php): Laravel bootstrap · `bootstrap/app.php`
- [Artisan CLI](https://github.com/alfredo1995/erp/blob/main/artisan): CLI entrypoint · `artisan`
- [Console kernel](https://github.com/alfredo1995/erp/blob/main/app/Console/Kernel.php): Laravel kernel · `app/Console/Kernel.php`

### HTTP Boundary

- [HTTP kernel](https://github.com/alfredo1995/erp/blob/main/app/Http/Kernel.php): Laravel kernel · Applies authentication, CSRF, cookies, proxies, and maintenance middleware. · `app/Http/Kernel.php`
- **HTTP middleware**: request middleware
- [Browser routes](https://github.com/alfredo1995/erp/blob/main/routes/web.php): web routes · Primary named CRUD routes, including suppliers. · `routes/web.php`
- [API routes](https://github.com/alfredo1995/erp/blob/main/routes/api.php): API routes · `routes/api.php`
- [Channel routes](https://github.com/alfredo1995/erp/blob/main/routes/channels.php): broadcast routes · `routes/channels.php`

### CRUD Domain

- [Supplier CRUD](https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/FornecedorController.php): controller · `app/Http/Controllers/FornecedorController.php`
- [Product CRUD](https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/ProdutoController.php): controller · `app/Http/Controllers/ProdutoController.php`
- [Purchase order CRUD](https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/PedidoController.php): controller · `app/Http/Controllers/PedidoController.php`
- [Sales order CRUD](https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/PedidoVendaController.php): controller · `app/Http/Controllers/PedidoVendaController.php`
- [Sales product CRUD](https://github.com/alfredo1995/erp/blob/main/app/Http/Controllers/ProdutoVendaController.php): controller · `app/Http/Controllers/ProdutoVendaController.php`

### Persistence & Infrastructure

- [Legacy Eloquent models](https://github.com/alfredo1995/erp/blob/main/app/Models/Fornecedor.php): persistence models · Models map suppliers, products, orders, banks, and states to the legacy schema. · `app/Models/Fornecedor.php`
- [Legacy MySQL database](https://github.com/alfredo1995/erp/blob/main/config/database.php): database · Manually imported Fornecedores database; supplier table uses sp_supplier and sup_id. · `config/database.php`
- [Service providers](https://github.com/alfredo1995/erp/blob/main/app/Providers/AppServiceProvider.php): Laravel providers · Wires application, authentication, events, routes, and broadcasting. · `app/Providers/AppServiceProvider.php`
- [Auth & sessions](https://github.com/alfredo1995/erp/blob/main/config/auth.php): framework configuration · `config/auth.php`
- [Laravel Mix assets](https://github.com/alfredo1995/erp/blob/main/webpack.mix.js): asset pipeline · `webpack.mix.js`

## Connections

- PHP web entry → Application bootstrap: bootstraps
- Artisan CLI → Application bootstrap: bootstraps
- Artisan CLI → Console kernel: runs commands through
- Application bootstrap → HTTP kernel: creates HTTP app
- Application bootstrap → Service providers: loads
- HTTP kernel → HTTP middleware: executes
- HTTP middleware → Browser routes: dispatches browser requests
- HTTP middleware → API routes: dispatches API requests
- Browser routes → Supplier CRUD: supplier CRUD
- Browser routes → Product CRUD: product CRUD
- Browser routes → Purchase order CRUD: purchase CRUD
- Browser routes → Sales order CRUD: sales-order CRUD
- Browser routes → Sales product CRUD: sales-product CRUD
- Supplier CRUD → Legacy Eloquent models: CRUD and route binding
- Product CRUD → Legacy Eloquent models: CRUD
- Purchase order CRUD → Legacy Eloquent models: CRUD
- Sales order CRUD → Legacy Eloquent models: CRUD
- Sales product CRUD → Legacy Eloquent models: CRUD
- Legacy Eloquent models → Legacy MySQL database: reads and persists
- Service providers → Browser routes: registers routes
- Service providers → Auth & sessions: configures auth services
- Auth & sessions → HTTP middleware: supports sessions and auth
