¡Esta es una revisión vieja del documento!
Tabla de Contenidos
BASIS core
This project, BASIS Core, is a modular, multi-tenant enterprise platform built with PHP. It implements a robust PSR-7/PSR-15 compliant architecture with advanced security features and modern frontend integration via Hotwire Turbo.
Based on the provided UML sequence diagram and codebase, here is a structured introduction to the project:
1. HTTP Request Pipeline & Middleware Stack
The application uses a layered middleware pipeline to process requests securely before they reach the business logic:
- Entry Point & Kernel: Requests enter via
public/index.phpand are dispatched by theHttp\Kernel(core/Http/Kernel.php). - Tenant Resolution:
TenantResolutionMiddleware(src/Http/Middleware/TenantResolutionMiddleware.php) resolves the current tenant from the request host and switches the database connection context accordingly. - RLS Session Context:
DbSessionMiddleware(core/Http/Middleware/DbSessionMiddleware.php) sets PostgreSQL session variables (likeapp.current_user_id) to enforce Row-Level Security (RLS) policies at the database level. - Security Middlewares:
CsrfMiddlewarevalidates CSRF tokens, andRateLimiterMiddlewareprevents brute-force attacks. - Turbo Detection:
TurboStreamDetector(core/Http/TurboStreamDetector.php) identifies if the request originates from Hotwire Turbo, allowing the controller to returnTurboStreamResponseinstead of full HTML.
2. Advanced Authentication & Security Flow
The platform implements a sophisticated, multi-layered authentication system:
- Core Authentication:
AuthService(core/Auth/AuthService.php) handles credential verification and session creation viaSessionManager. - Multi-Factor Authentication (MFA): If enabled,
MfaService(core/Auth/MfaService.php) enforces a TOTP challenge. Users can verify via authenticator apps or backup codes. - WebAuthn/Biometrics: As an alternative MFA factor,
WebAuthnService(core/Auth/WebAuthn/WebAuthnService.php) handles biometric authentication (FaceID, fingerprint) and hardware security keys. - User Context: Upon successful login,
UserProfileAgent(core/Agents/UserProfileAgent.php) initializes the user's profile, permissions, and runtime context.
3. Modern Frontend Integration (Hotwire Turbo)
Instead of building a heavy SPA, the project uses Hotwire Turbo for a fast, modern UX:
- The
TurboStreamDetectorintercepts responses from theApp Controller. - If the client expects a Turbo Stream, the system formats a
TurboStreamResponse(core/Http/Response/TurboStreamResponse.php), sending only the modified DOM fragments to the browser. - This allows seamless, SPA-like navigation without writing custom JavaScript, while keeping the server as the source of truth.
4. Modular & Multi-Tenant Architecture
The project is structured as a monorepo containing distinct “apps” and “modules”:
- Multi-App Support: It hosts multiple business applications like Operand (ERP), Nexus (BI/Strategy), Axis (Field Operations), and Vector (Engineering). Each app has its own controllers, views, and routing (
apps/operand,apps/nexus, etc.). - Core Modules: Shared functionalities are abstracted into modules like
core-auth(Authentication),core-admin(Administration),audit, andfiles(modules/). - Database Isolation: The
db_authschema centralizes user identities, whileTenantResolutionMiddlewareensures data isolation per company using database-level RLS.
