# phicorp/davinci architecture

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

- Interactive diagram: https://gitdiagram.com/phicorp/davinci
- Repository: https://github.com/phicorp/davinci

## Overview

##### Main Components
- Client / Browser – Represent external requests hitting your application.
- Public Entry Point – The “public” directory (with index.php, .htaccess, and robots.txt) defines the web root where user requests initially land.
- Router and Bootstrapping – Files like router.php, config.php, and the “nova” directory (with its “serve” command) are used to start the application and route incoming requests.
- Application Core (App) – This is subdivided into:
– Controllers: (App/Controllers) where incoming HTTP requests are handled.
– Models: (App/Models) representing the ORM layer and database entities.
– Middlewares: (App/Middlewares) for handling pre/post processing of HTTP requests (e.g., CORS, CSRF).
– Console: (App/Console) containing command line tools/commands.
– Helpers: (App/Helpers) and Providers: (App/Providers) which set up dependency injection, IoC, and other service configurations.
– DB: (App/DB) which could hold database connection logic or configuration.
- Routes – The “Routes” directory (with web.php, api.php, console.php) defines how HTTP, API, and console commands are mapped to their respective controllers or actions.
- Views – The “View” directory contains Blade templates (e.g., welcome.blade.php) used to render the UI.
- Assets – Static assets like CSS, JS, and fonts in the “Assets” folder (though not central to backend logic, they’re part of the external resources served when necessary).
- Storage – Holds logs, session data, cache, etc., indicating persistence and state management for the framework.
- Third-party & Dependency Management – Composer (composer.json) indicates package management, while external libraries might be loaded via autoloading.

##### Relationships and Interactions
- That the router loads Routes (from Routes/web.php or api.php) that map to specific Controller methods (from App/Controllers).
- Middleware processing (from App/Middlewares) that intercepts the request before reaching controllers.
- Once the Controller processes the request, it may interact with Models (via the ORM), and subsequently passing any data to the View rendering engine (from View).
- The Providers (in App/Providers) orchestrate dependency injection and service registration, allowing components like the ORM and session management (stored in Storage) to interact seamlessly.
- The console commands (App/Console) provide administrative or maintenance functions that might interact with the same layers (routing for console, models, DB, etc.).
- Static assets under “Assets” are served separately by the web server (usually referenced in the view templates).

##### Architectural Patterns and Principles
- MVC-like Structure: Controllers, Models, and Views are clearly separated.
- Middleware Pipeline: In App/Middlewares, showing how requests are filtered/processed.
- Service Providers & Dependency Injection: Ensuring loose coupling and extendability.
- Routing Layer: Centralized in the Routes directory to define different request types (web, api, console).
- Clear Separation of Concerns: Different directories isolate specific responsibilities (for instance, Storage for logs and sessions, App/DB for database abstractions).

##### Technology and Frameworks
- PHP as the primary language.
- Composer for dependency management.
- Blade-like templating engine (as seen in the View folder).
- Built-in routing, ORM, and console command support similar to popular frameworks like Laravel.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client/Browser"]:::client
    B["Public Entry (public/index.php)"]:::public
    C["Router & Bootstrapping (router.php, config.php, nova)"]:::router
    D["Routes (Routes/web.php,Routes/api.php,Routes/console.php)"]:::router
    E["Middlewares (App/Middlewares)"]:::middleware
    F["Controllers (App/Controllers)"]:::app
    G["Models (ORM Layer) (App/Models)"]:::app
    H["Views (Templating via Blade) (View)"]:::app
    I["Service Providers / DI (App/Providers)"]:::provider
    J["Database Layer (App/DB)"]:::database
    K["Helpers (App/Helpers)"]:::app
    L["Console Commands (App/Console)"]:::console
    M["Console Interface"]:::console
    N["Assets (Assets)"]:::assets
    O["Storage (Storage)"]:::storage
    P["Composer (composer.json)"]:::thirdparty

    A --> B
    B --> C
    C --> D
    D --> E
    E --> F
    F --> G
    F --> H
    F --> K
    G --> J
    I --> F
    I --> L
    M --> L
    H --> N
    I --> O
    I --> P

    click B "https://github.com/phicorp/davinci/tree/main/public/"
    click C "https://github.com/phicorp/davinci/blob/main/router.php"
    click D "https://github.com/phicorp/davinci/blob/main/Routes/web.php"
    click E "https://github.com/phicorp/davinci/blob/main/App/Middlewares/CorsMiddleware.php"
    click F "https://github.com/phicorp/davinci/blob/main/App/Controllers/Controller.php"
    click G "https://github.com/phicorp/davinci/blob/main/App/Models/User.php"
    click K "https://github.com/phicorp/davinci/tree/main/App/Helpers/"
    click I "https://github.com/phicorp/davinci/blob/main/App/Providers/AppServiceProvider.php"
    click J "https://github.com/phicorp/davinci/tree/main/App/DB/"
    click L "https://github.com/phicorp/davinci/tree/main/App/Console/"
    click H "https://github.com/phicorp/davinci/blob/main/View/welcome.blade.php"
    click N "https://github.com/phicorp/davinci/tree/main/Assets/"
    click O "https://github.com/phicorp/davinci/tree/main/Storage/"
    click P "https://github.com/phicorp/davinci/blob/main/composer.json"

    classDef client fill:#f9c,stroke:#333,stroke-width:2px
    classDef public fill:#cfc,stroke:#333,stroke-width:2px
    classDef router fill:#ccf,stroke:#333,stroke-width:2px
    classDef middleware fill:#fcc,stroke:#333,stroke-width:2px
    classDef app fill:#fc9,stroke:#333,stroke-width:2px
    classDef provider fill:#ffd,stroke:#333,stroke-width:2px
    classDef database fill:#cff,stroke:#333,stroke-width:2px
    classDef console fill:#ddf,stroke:#333,stroke-width:2px
    classDef assets fill:#efe,stroke:#333,stroke-width:2px
    classDef storage fill:#eee,stroke:#333,stroke-width:2px
    classDef thirdparty fill:#aaf,stroke:#333,stroke-width:2px
```
