# ouhssini/installer architecture

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

- Interactive diagram: https://gitdiagram.com/ouhssini/installer
- Repository: https://github.com/ouhssini/installer

## Overview

#### Purpose and Integration
This is a Composer package that adds a pre-application Laravel 11/12 installation wizard for commercial deployments. It configures the app, validates host requirements, provisions the database, optionally verifies an Envato license, creates an administrator, then locks itself. Package bootstrapping and container registration are centered in `src/InstallerServiceProvider.php`; public package access is exposed through `src/Installer.php` and `src/Facades/Installer.php`.

#### Entrypoints and Route Boundary
Browser entry is the configurable `/install` route prefix declared in `routes/installer.php`. The wizard is split into request controllers under `src/Http/Controllers/`, including `WelcomeController.php`, `DatabaseController.php`, and `FinalizeController.php`. Views are server-rendered Blade templates in `resources/views/`, with shared shell markup at `resources/views/layouts/master.blade.php`.

Installer routes run in a custom middleware context intended to work before `.env` and `APP_KEY` exist; forms are deliberately stateless and do not depend on encrypted sessions or CSRF state.

#### Installation State and Sequencing
`src/Services/InstallerService.php` is the installation-state authority. It persists progress/settings file-first under `storage/app`, avoiding a database dependency before credentials are configured. It tracks completed stages, supports step-order validation, and creates/removes the installation lock. `src/Http/Middleware/EnsureInstalled.php` gates the host application until completion, while `src/Http/Middleware/RedirectIfInstalled.php` prevents reopening the wizard after lockout.

The recovery CLI entry point is `src/Commands/InstallerCommand.php` (`php artisan installer:unlock`), which removes the installed state when recovery is required.

#### Environment and Requirements Stage
Application configuration is handled by `src/Http/Controllers/AppConfigController.php` backed by `src/Services/EnvironmentManager.php`. This stage creates/updates `.env`, sets application values, and generates the app key. Requirements validation is isolated in `src/Services/RequirementsChecker.php` and driven by `src/Http/Controllers/RequirementsController.php`; configured PHP version, extensions, and writable paths come from `config/installer.php`.

#### Database Provisioning Stage
`src/Http/Controllers/DatabaseController.php` orchestrates connection input, connection testing, environment persistence, migrations, and settings-table initialization. The database-specific boundary is `src/Services/DatabaseManager.php`, supporting MySQL, PostgreSQL, and SQLite through Laravel’s database/schema facilities. Migrations occur before admin creation so application tables, especially users, exist when later stages execute. The package migration template is `database/migrations/create_settings_table.php.stub`.

#### License Verification Boundary
`src/Http/Controllers/LicenseController.php` delegates purchase-code validation to `src/Services/LicenseService.php`, which returns the structured `src/Services/LicenseVerificationResult.php`. This is the external-service boundary for Envato API v3. Behavior is controlled by `config/installer.php`: verification can be disabled, switched to development mode, or constrained to a configured Envato item. The design stores license metadata and a hash rather than the plaintext purchase code or personal token.

#### Admin Creation and Finalization
`src/Http/Controllers/AdminController.php` creates the initial administrator after migrations. It adapts role assignment to the host user schema and can integrate with Spatie Permission when present. `src/Http/Controllers/FinalizeController.php` completes installation: it syncs file-first installer data to the database settings store, switches relevant runtime drivers toward database-backed operation, marks installation complete, and redirects to the configured post-install route. Primary behavior and defaults are consolidated in `config/installer.php`.

Main entry points: [`src/Services/InstallerService.php`](https://github.com/ouhssini/installer/blob/main/src/Services/InstallerService.php) (Installer state), [`routes/installer.php`](https://github.com/ouhssini/installer/blob/main/routes/installer.php) (Install routes), [`src/InstallerServiceProvider.php`](https://github.com/ouhssini/installer/blob/main/src/InstallerServiceProvider.php) (Installer service provider), [`src/Services/DatabaseManager.php`](https://github.com/ouhssini/installer/blob/main/src/Services/DatabaseManager.php) (Database manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bootstrap["Package Bootstrap"]
  node_provider["Installer service provider<br/>Laravel provider"]
  node_installer_api["Installer public API<br/>package API<br/>[Installer.php]"]
  node_installer_facade["Installer facade<br/>Laravel facade<br/>[Installer.php]"]
  node_config["Installer configuration<br/>package config<br/>[installer.php]"]
end

subgraph group_wizard["Installation Wizard"]
  node_routes["Install routes<br/>route boundary<br/>[installer.php]"]
  node_wizard_views["Blade wizard views<br/>server-rendered UI<br/>[master.blade.php]"]
  node_app_config["App configuration<br/>wizard controller"]
  node_requirements["Requirements stage<br/>wizard controller"]
  node_database["Database stage<br/>wizard controller"]
  node_license["License stage<br/>wizard controller"]
  node_admin["Admin creation<br/>wizard controller"]
  node_finalize["Finalization<br/>wizard controller"]
end

subgraph group_services["Installation Services"]
  node_installer_state[("Installer state<br/>state service")]
  node_environment["Environment manager<br/>environment service"]
  node_requirements_checker["Requirements checker<br/>validation service"]
  node_database_manager["Database manager<br/>provisioning service"]
  node_settings_migration["Settings migration template<br/>migration stub"]
  node_license_service{{"Envato license service<br/>external API adapter<br/>[LicenseService.php]"}}
  node_license_result["License verification result<br/>result value"]
end

subgraph group_host["Host Application"]
  node_ensure_installed["Installed gate<br/>host middleware"]
  node_redirect_installed["Wizard lockout<br/>wizard middleware"]
  node_unlock_command["installer:unlock<br/>recovery command"]
end

node_provider -->|"registers"| node_installer_api
node_installer_facade -->|"facade access"| node_installer_api
node_provider -->|"loads"| node_routes
node_provider -->|"registers"| node_ensure_installed
node_provider -->|"registers"| node_unlock_command
node_config -->|"configures prefix"| node_routes
node_config -->|"defines checks"| node_requirements_checker
node_config -->|"controls verification"| node_license_service
node_routes -->|"middleware"| node_redirect_installed
node_routes -->|"renders"| node_wizard_views
node_routes -->|"wizard flow"| node_app_config
node_app_config -->|"updates .env"| node_environment
node_requirements -->|"validates host"| node_requirements_checker
node_database -->|"persists credentials"| node_environment
node_database -->|"tests and provisions"| node_database_manager
node_database_manager -->|"runs migration"| node_settings_migration
node_license -->|"verifies code"| node_license_service
node_license_service -->|"returns"| node_license_result
node_app_config -->|"records stage"| node_installer_state
node_database -->|"records stage"| node_installer_state
node_license -->|"stores metadata"| node_installer_state
node_admin -.->|"requires migrated users"| node_database_manager
node_finalize -->|"locks installation"| node_installer_state
node_finalize -->|"syncs settings"| node_database_manager
node_installer_state -->|"completion state"| node_ensure_installed
node_installer_state -->|"lock state"| node_redirect_installed
node_unlock_command -->|"clears lock"| node_installer_state

click node_provider "https://github.com/ouhssini/installer/blob/main/src/InstallerServiceProvider.php"
click node_installer_api "https://github.com/ouhssini/installer/blob/main/src/Installer.php"
click node_installer_facade "https://github.com/ouhssini/installer/blob/main/src/Facades/Installer.php"
click node_config "https://github.com/ouhssini/installer/blob/main/config/installer.php"
click node_routes "https://github.com/ouhssini/installer/blob/main/routes/installer.php"
click node_wizard_views "https://github.com/ouhssini/installer/blob/main/resources/views/layouts/master.blade.php"
click node_app_config "https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/AppConfigController.php"
click node_requirements "https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/RequirementsController.php"
click node_database "https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/DatabaseController.php"
click node_license "https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/LicenseController.php"
click node_admin "https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/AdminController.php"
click node_finalize "https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/FinalizeController.php"
click node_installer_state "https://github.com/ouhssini/installer/blob/main/src/Services/InstallerService.php"
click node_environment "https://github.com/ouhssini/installer/blob/main/src/Services/EnvironmentManager.php"
click node_requirements_checker "https://github.com/ouhssini/installer/blob/main/src/Services/RequirementsChecker.php"
click node_database_manager "https://github.com/ouhssini/installer/blob/main/src/Services/DatabaseManager.php"
click node_settings_migration "https://github.com/ouhssini/installer/blob/main/database/migrations/create_settings_table.php.stub"
click node_license_service "https://github.com/ouhssini/installer/blob/main/src/Services/LicenseService.php"
click node_license_result "https://github.com/ouhssini/installer/blob/main/src/Services/LicenseVerificationResult.php"
click node_ensure_installed "https://github.com/ouhssini/installer/blob/main/src/Http/Middleware/EnsureInstalled.php"
click node_redirect_installed "https://github.com/ouhssini/installer/blob/main/src/Http/Middleware/RedirectIfInstalled.php"
click node_unlock_command "https://github.com/ouhssini/installer/blob/main/src/Commands/InstallerCommand.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_installer_api,node_installer_facade,node_config toneBlue
class node_routes,node_wizard_views,node_app_config,node_requirements,node_database,node_license,node_admin,node_finalize toneAmber
class node_installer_state,node_environment,node_requirements_checker,node_database_manager,node_settings_migration,node_license_service,node_license_result toneMint
class node_ensure_installed,node_redirect_installed,node_unlock_command toneRose
```

## Components

### Package Bootstrap

- [Installer service provider](https://github.com/ouhssini/installer/blob/main/src/InstallerServiceProvider.php): Laravel provider · Registers package services, routes, middleware, and commands. · `src/InstallerServiceProvider.php`
- [Installer public API](https://github.com/ouhssini/installer/blob/main/src/Installer.php): package API · `src/Installer.php`
- [Installer facade](https://github.com/ouhssini/installer/blob/main/src/Facades/Installer.php): Laravel facade · `src/Facades/Installer.php`
- [Installer configuration](https://github.com/ouhssini/installer/blob/main/config/installer.php): package config · Defines route, requirements, license, and post-install behavior. · `config/installer.php`

### Installation Wizard

Stateless browser flow under the install route.

- [Install routes](https://github.com/ouhssini/installer/blob/main/routes/installer.php): route boundary · Configurable /install browser entrypoint. · `routes/installer.php`
- [Blade wizard views](https://github.com/ouhssini/installer/blob/main/resources/views/layouts/master.blade.php): server-rendered UI · Shared shell and installation forms. · `resources/views/layouts/master.blade.php`
- [App configuration](https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/AppConfigController.php): wizard controller · `src/Http/Controllers/AppConfigController.php`
- [Requirements stage](https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/RequirementsController.php): wizard controller · `src/Http/Controllers/RequirementsController.php`
- [Database stage](https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/DatabaseController.php): wizard controller · Tests, persists, migrates, and initializes database settings. · `src/Http/Controllers/DatabaseController.php`
- [License stage](https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/LicenseController.php): wizard controller · `src/Http/Controllers/LicenseController.php`
- [Admin creation](https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/AdminController.php): wizard controller · Creates the initial administrator after migrations. · `src/Http/Controllers/AdminController.php`
- [Finalization](https://github.com/ouhssini/installer/blob/main/src/Http/Controllers/FinalizeController.php): wizard controller · Syncs settings, marks complete, and redirects. · `src/Http/Controllers/FinalizeController.php`

### Installation Services

- [Installer state](https://github.com/ouhssini/installer/blob/main/src/Services/InstallerService.php): state service · File-first progress, settings, sequencing, and install lock authority. · `src/Services/InstallerService.php`
- [Environment manager](https://github.com/ouhssini/installer/blob/main/src/Services/EnvironmentManager.php): environment service · Writes .env values and generates the application key. · `src/Services/EnvironmentManager.php`
- [Requirements checker](https://github.com/ouhssini/installer/blob/main/src/Services/RequirementsChecker.php): validation service · Checks configured PHP, extensions, and writable paths. · `src/Services/RequirementsChecker.php`
- [Database manager](https://github.com/ouhssini/installer/blob/main/src/Services/DatabaseManager.php): provisioning service · Uses Laravel database/schema facilities for MySQL, PostgreSQL, and SQLite. · `src/Services/DatabaseManager.php`
- [Settings migration template](https://github.com/ouhssini/installer/blob/main/database/migrations/create_settings_table.php.stub): migration stub · `database/migrations/create_settings_table.php.stub`
- [Envato license service](https://github.com/ouhssini/installer/blob/main/src/Services/LicenseService.php): external API adapter · Verifies purchase codes without retaining plaintext credentials. · `src/Services/LicenseService.php`
- [License verification result](https://github.com/ouhssini/installer/blob/main/src/Services/LicenseVerificationResult.php): result value · Structured verification outcome and metadata. · `src/Services/LicenseVerificationResult.php`

### Host Application

- [Installed gate](https://github.com/ouhssini/installer/blob/main/src/Http/Middleware/EnsureInstalled.php): host middleware · Blocks host application access until installation completes. · `src/Http/Middleware/EnsureInstalled.php`
- [Wizard lockout](https://github.com/ouhssini/installer/blob/main/src/Http/Middleware/RedirectIfInstalled.php): wizard middleware · Prevents reopening the wizard after completion. · `src/Http/Middleware/RedirectIfInstalled.php`
- [installer:unlock](https://github.com/ouhssini/installer/blob/main/src/Commands/InstallerCommand.php): recovery command · Removes installed state for recovery. · `src/Commands/InstallerCommand.php`

## Connections

- Installer service provider → Installer public API: registers
- Installer facade → Installer public API: facade access
- Installer service provider → Install routes: loads
- Installer service provider → Installed gate: registers
- Installer service provider → installer:unlock: registers
- Installer configuration → Install routes: configures prefix
- Installer configuration → Requirements checker: defines checks
- Installer configuration → Envato license service: controls verification
- Install routes → Wizard lockout: middleware
- Install routes → Blade wizard views: renders
- Install routes → App configuration: wizard flow
- App configuration → Environment manager: updates .env
- Requirements stage → Requirements checker: validates host
- Database stage → Environment manager: persists credentials
- Database stage → Database manager: tests and provisions
- Database manager → Settings migration template: runs migration
- License stage → Envato license service: verifies code
- Envato license service → License verification result: returns
- App configuration → Installer state: records stage
- Database stage → Installer state: records stage
- License stage → Installer state: stores metadata
- Admin creation → Database manager: requires migrated users
- Finalization → Installer state: locks installation
- Finalization → Database manager: syncs settings
- Installer state → Installed gate: completion state
- Installer state → Wizard lockout: lock state
- installer:unlock → Installer state: clears lock
