Caderno Digital has been refactored from a monolithic procedural structure to a clean, layered architecture following design patterns and best practices.
app/
├── Core/ # Base classes and foundations
│ ├── BaseController.php
│ ├── BaseModel.php
│ ├── Database.php
│ └── Request.php
├── Http/
│ └── Controllers/ # Request handlers
│ ├── AuthController.php
│ ├── EquipmentController.php
│ ├── HealthController.php
│ ├── MovementController.php
│ └── ReferenceController.php
├── Models/ # Data models and database interactions
│ ├── Equipamento.php
│ ├── Localidade.php
│ ├── Movimentacao.php
│ ├── MovimentacaoItem.php
│ └── Usuario.php
├── Services/ # Business logic
│ ├── AuthService.php
│ ├── EquipmentService.php
│ ├── MovementService.php
│ └── ReferenceService.php
└── SRE/ # Site Reliability Engineering layer
├── ErrorHandler.php
├── HealthCheck.php
├── Logger.php
└── Middleware.php
config/ # Configuration files
├── app.php
├── bootstrap.php
├── database.php
└── logging.php
public/ # Web root
├── .htaccess
└── index.php (Router)
resources/
└── views/ # Template files
├── auth/
├── includes/
└── movements/
database/
└── migrations/ # Database migration files
tests/
└── Unit/ # Unit tests
vendor/
└── autoload.php # PSR-4 autoloader
Foundation classes providing common functionality:
Models handle data access and persistence:
Business logic and application rules:
HTTP request handlers:
Operational and reliability features:
HTTP Request
↓
public/index.php (Router)
↓
Controller (parse request)
↓
Service (business logic)
↓
Model (data access)
↓
Database (PDO)
↓
Response (JSON/HTML/Redirect)
POST /salvar
↓
MovementController::store()
↓
MovementService::create()
↓
Movimentacao::create() (header)
MovimentacaoItem::createWithMovimentacao() (items)
↓
Database queries
↓
Redirect to index.php
e() function for XSS preventionDB_HOST=db
DB_NAME=caderno
DB_USER=root
DB_PASS=password
APP_ENV=production
APP_DEBUG=false
TIMEZONE=America/Sao_Paulo
LOG_LEVEL=INFO
LOG_PATH=/var/log/caderno/app.log
Models provide a consistent interface:
$user = new Usuario();
$userData = $user->findByCpf('12345678900');
$movement = new Movimentacao();
$items = $movement->getAll($limit, $offset, $filters);
$count = $movement->getTotalCount($filters);
Services are instantiated in controllers:
$authService = new AuthService();
$authenticated = $authService->authenticate($cpf, $password);
class AuthServiceTest {
public function testAuthenticate() {
$service = new AuthService();
$user = $service->authenticate('123', 'password');
$this->assertNotNull($user);
}
}
namespace App\Models;
class Feature extends BaseModel {
protected string $table = 'features';
}
namespace App\Services;
class FeatureService {
private Feature $model;
public function __construct() {
$this->model = new Feature();
}
}
namespace App\Http\Controllers;
class FeatureController extends BaseController {
private FeatureService $service;
}
The refactored application maintains full backward compatibility:
Old direct file access (login.php, cadastro.php, etc.) is routed through public/index.php.