# neorazorx/facturascripts architecture

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

- Interactive diagram: https://gitdiagram.com/neorazorx/facturascripts
- Repository: https://github.com/neorazorx/facturascripts

## Overview

##### Main Components
- Presentation Layer:
– Represented by the assets (located in directories such as Core/Assets and Dinamic/Lib/Widget, etc.), the twig templates (Core/View and its subdirectories), and the login and layout pages.
– Include the client-side technologies (CSS, JavaScript, fonts, images) and the HTML templates rendered by the system.
- Business/Controller Layer:
– The Core/Controller and Dinamic/Lib/ExtendedController directories hold the controllers, API endpoints, and request-handling logic.
– This layer manages incoming requests (including Ajax requests seen in Core/Base/AjaxForms) and decides on the processing needed.
- Domain/Model Layer:
– All the domain objects reside in Core/Model and Dinamic/Model directories. They represent entities like Client, FacturaCliente, PedidoProveedor, and many others.
– Also include the contracts/interfaces in Core/Contract and Core/Base/Contract.
- Data Access Layer:
– Found in Core/Base/DataBase and its subdirectories, these provide abstractions for database engines (MySQLEngine, PostgresqlEngine, etc.) and query management.
– Migration tools and database update scripts (e.g., Migrations.php) are also part of this aspect.
- Infrastructure & Utilities:
– Background jobs (Core/Worker) for processing asynchronous tasks like ContaWorker, PurchaseDocumentWorker, etc.
– Utility libraries: email modules (Core/Lib/Email), PDF exports (Core/Lib/Export), logging (MiniLog, MiniLogStorage), and translation support.
– Plugin integration: Both Core and Dinamic include dynamic plugin and extension support to enhance functionality.
- Testing and Quality Assurance:
– The Test directory shows unit tests, integration tests, and related assets ensuring functionality across controllers, models, and utilities.

##### Relationships and Interactions
- User requests (HTTP requests from clients or API calls) hit the Presentation Layer, which then forwards the request to the appropriate controller in the Business Layer (via Core/Controller, API endpoints, and login controllers).
- Controllers interact with domain Models to perform business logic. For example, a Sales or Purchases request is handled by corresponding controllers that call models residing under Core/Model to retrieve or save data.
- The Data Access Layer (via databases, queries, and migrations) underpins the Models – it abstracts differences between SQL engines and manages low-level data operations.
- Infrastructure components, including background Workers and utilities (like email notifications, PDF generation, and logging), are invoked as part of the business processes.
- Plugins and external modules (visible in the “Dinamic” folder) extend the core functionality. Consider these as extension points that plug into business logic or presentation components as needed.

##### Architectural Patterns and Design Principles
- Layered (n-tier) architecture separating presentation, business logic, domain, and data access.
- Use of MVC-like patterns where Controllers manage inputs, Models manage data, and Views (twig templates) present the data.
- Modularity and extensibility via plugin structure — dynamic modules allow for expanding system functionality without modifying core files.
- Abstraction of database access to support multiple database engines (as seen in the DatabaseEngine implementations).

##### Relevant Technologies
- PHP (modern PHP, utilizing composer for dependency management)
- Twig templating engine (as indicated by the templates under Core/View)
- Bootstrap 4 (as mentioned in the README, indicating UI framework usage)
- JavaScript libraries for user interface enhancements (assets in Core/Assets/JS)
- Various utilities for PDF exports, email, translations, and background processing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client / Browser"
        A("Client: Browser/API"):::client
    end

    subgraph "Presentation Layer"
        P1("Assets & Client Resources"):::presentation
        P2("Twig Templates (Views)"):::presentation
    end

    subgraph "Business/Controller Layer"
        BC1("Controllers & Request Handling"):::controller
        BC2("Extended Controllers"):::controller
        BC3("Ajax Request Handling"):::controller
    end

    subgraph "Domain/Model Layer"
        DM1("Domain Entities & Models"):::domain
        DM2("Plugin/Extension Models"):::domain
        DM3a("Contracts"):::domain
        DM3b("Base Contracts"):::domain
    end

    subgraph "Data Access Layer"
        DA1("Database Abstraction & Query Management"):::data
        DA2("Migration Scripts"):::data
    end

    subgraph "Infrastructure & Utilities"
        IU1("Background Workers"):::infra
        IU2a("Email Library"):::infra
        IU2b("PDF Export Library"):::infra
        IU2c("Logging Utility"):::infra
        IU2d("Widget Library"):::infra
        IU3("Plugin Integration"):::infra
    end

    subgraph "Testing & Quality Assurance"
        T1("Automated Tests & Test Cases"):::test
    end

    A -->|"HTTP_Request"| P1
    A -->|"HTTP_Request"| P2

    P1 -->|"uses"| BC1
    P2 -->|"uses"| BC1

    BC1 -->|"invokes_logic"| DM1
    BC1 -->|"uses_contract"| DM3a
    BC1 -->|"uses_contract"| DM3b
    BC2 -->|"extends"| BC1
    BC3 -->|"handles_Ajax"| BC1

    DM1 -->|"persists_data_via"| DA1
    DM2 -->|"extends_domain"| DM1

    DA1 -->|"executes_queries"| DA2

    BC1 -->|"triggers_worker"| IU1
    BC1 -->|"calls_email"| IU2a
    BC1 -->|"calls_pdf"| IU2b
    BC1 -->|"calls_logging"| IU2c
    BC1 -->|"calls_widget"| IU2d

    DM1 -->|"invokes_plugins"| IU3

    T1 -->|"tests"| P1
    T1 -->|"tests"| BC1
    T1 -->|"tests"| DM1
    T1 -->|"tests"| DA1

    click P1 "https://github.com/neorazorx/facturascripts/tree/master/Core/Assets"
    click P2 "https://github.com/neorazorx/facturascripts/tree/master/Core/View"
    click BC1 "https://github.com/neorazorx/facturascripts/tree/master/Core/Controller"
    click BC2 "https://github.com/neorazorx/facturascripts/tree/master/Core/Lib/ExtendedController"
    click BC3 "https://github.com/neorazorx/facturascripts/tree/master/Core/Base/AjaxForms"
    click DM1 "https://github.com/neorazorx/facturascripts/tree/master/Core/Model"
    click DM2 "https://github.com/neorazorx/facturascripts/tree/master/Dinamic/Model"
    click DM3a "https://github.com/neorazorx/facturascripts/tree/master/Core/Contract"
    click DM3b "https://github.com/neorazorx/facturascripts/tree/master/Core/Base/Contract"
    click DA1 "https://github.com/neorazorx/facturascripts/tree/master/Core/Base/DataBase"
    click DA2 "https://github.com/neorazorx/facturascripts/blob/master/Core/Base/Migrations.php"
    click IU1 "https://github.com/neorazorx/facturascripts/tree/master/Core/Worker"
    click IU2a "https://github.com/neorazorx/facturascripts/tree/master/Core/Lib/Email"
    click IU2b "https://github.com/neorazorx/facturascripts/tree/master/Core/Lib/Export"
    click IU2c "https://github.com/neorazorx/facturascripts/blob/master/Core/Base/MiniLog.php"
    click IU2d "https://github.com/neorazorx/facturascripts/tree/master/Core/Lib/Widget"
    click IU3 "https://github.com/neorazorx/facturascripts/tree/master/Dinamic/Lib"
    click T1 "https://github.com/neorazorx/facturascripts/tree/master/Test"

    classDef client fill:#c0c0f0,stroke:#333,stroke-width:2px;
    classDef presentation fill:#aee1f9,stroke:#333,stroke-width:2px;
    classDef controller fill:#caffbf,stroke:#333,stroke-width:2px;
    classDef domain fill:#ffdfba,stroke:#333,stroke-width:2px;
    classDef data fill:#ffffba,stroke:#333,stroke-width:2px;
    classDef infra fill:#d0f0c0,stroke:#333,stroke-width:2px;
    classDef test fill:#ffb3ba,stroke:#333,stroke-width:2px;
```
