Architectural Overview
FacturaScripts follows a Model-View-Controller (MVC) pattern with a plugin-based architecture. The framework is designed for extensibility, allowing developers to add functionality without modifying core code.High-Level Architecture
The Kernel: Heart of FacturaScripts
TheKernel class (Core/Kernel.php) is the central component that manages the application lifecycle.
Kernel Responsibilities
Initialization
Sets up constants, language settings, and system configuration during
Kernel::init().Routing
Manages URL-to-controller mapping with
addRoute(), rebuildRoutes(), and route matching.Request Handling
Executes the appropriate controller via
Kernel::run() and handles exceptions.Performance Monitoring
Tracks execution time with
startTimer() and stopTimer() for performance analysis.Kernel Initialization
Location:Core/Kernel.php:95-135
Routing System
The Kernel maintains a route registry that maps URLs to controllers.Route Types
| Pattern | Example | Description |
|---|---|---|
| Exact | /login | Matches exact URL |
| Wildcard | /Core/Assets/* | Matches URL prefix |
| Dynamic | /EditCliente | Auto-generated from controllers |
| API | /api/3/productos | RESTful API endpoints |
Route Registration
Location:Core/Kernel.php:43-60
Route Rebuilding
Location:Core/Kernel.php:152-188
When plugins are enabled/disabled, routes are rebuilt:
Request Execution
Location:Core/Kernel.php:190-208
MVC Pattern Implementation
Controllers: Request Handlers
Location:Core/Base/Controller.php
All controllers inherit from the base Controller class.
Controller Structure
Controller Lifecycle
Location:Core/Base/Controller.php:282-323
Authentication Flow
Location:Core/Base/Controller.php:348-394
Models: Data Layer
Location:Core/Model/Base/ModelClass.php
Models represent database tables and business entities.
Model Structure
CRUD Operations
Create/Update: Location:Core/Model/Base/ModelClass.php:275-297
Core/Model/Base/ModelClass.php:134-162
Database Layer
Location:Core/Base/DataBase.php
The DataBase class provides abstraction for MySQL and PostgreSQL.
Database Features
Connection Management
Singleton pattern with
connect(), close(), and connection state tracking.Query Execution
exec() for INSERT/UPDATE/DELETE, select() and selectLimit() for queries.Transactions
beginTransaction(), commit(), and rollback() for ACID operations.Schema Management
getColumns(), getIndexes(), getConstraints() for structure introspection.Connection
Location:Core/Base/DataBase.php:76-92
Query Execution
Location:Core/Base/DataBase.php:226-263
Views: Presentation Layer
FacturaScripts uses Twig template engine for views.Template Location
Templates are located in:Core/View/- Core templatesPlugins/{PluginName}/View/- Plugin templatesDinamic/View/- Merged templates
Template Variables
Controllers pass variables to templates:Plugin System
Location:Core/Plugins.php
Plugins extend FacturaScripts without modifying core files.
Plugin Lifecycle
Plugin Structure
Plugin Metadata
facturascripts.ini example:
Request Lifecycle (Detailed)
Performance Features
Caching
- Model count caching: Reduces database queries
- Route caching: Stores routes in
MyFiles/routes.json - Template caching: Twig compiles templates
Work Queue
Asynchronous task processing:FastCGI Support
Location:Core/Kernel.php:269-292
Next Steps
Development Setup
Set up your local development environment.
Creating Plugins
Build your first plugin step-by-step.
Controllers
Learn to create custom controllers.
Models
Master the data layer and ORM.

