Architecture Overview
Zoo Arcadia follows a screaming architecture pattern (also known as domain-driven design), where the codebase structure immediately reveals what the application does rather than which framework it uses.Core Architectural Principles
The application is built around three fundamental concepts:- Domain-Driven Structure: Each business domain (animals, habitats, users, etc.) is a self-contained module
- MVC Within Domains: Each domain implements its own Model-View-Controller pattern
- Centralized Routing with Domain Delegation: A central router handles security, then delegates to domain-specific routers
Unlike traditional PHP frameworks that organize code by technical layers (controllers/, models/, views/), Zoo Arcadia organizes by business domains. This makes the codebase “scream” its purpose: “I’m a zoo management system!”
Project Structure
Here’s the high-level directory organization:Request Flow Diagram
Every HTTP request follows this path:Detailed Request Flow Explanation
Detailed Request Flow Explanation
- Front Controller (
public/index.php) receives all requests - Static File Check: If it’s a CSS/JS/image file, serve it directly
- URL Parsing: Extract domain, controller, and action from the URL
- Central Router (
App/router.php) validates session and permissions - Domain Router: Loads the appropriate domain router (e.g.,
animalsRouter.php) - Controller Instantiation: Creates the controller instance
- Action Execution: Calls the requested method on the controller
- View Rendering: Includes the appropriate view file
- Layout Application: Wraps the view in the appropriate layout (public or back-office)
Domain Organization
Each domain is a self-contained module with its own MVC structure:Key Architectural Decisions
1. Singleton Database Connection
The application uses a singleton pattern for database connections to prevent multiple connections and ensure efficient resource usage.database/connection.php
2. Session Management
Sessions are configured with security-first settings:- Secure cookies: HTTPS-only in production
- HttpOnly flag: Prevents XSS attacks from stealing session cookies
- SameSite=Lax: CSRF protection while allowing external links
- Session timeout: 11-hour automatic expiration
3. CSRF Protection
All forms that modify data include CSRF tokens validated on the server.4. Permission-Based Access Control
The application implements role-based permissions stored in the session:URL Structure
Zoo Arcadia uses clean URLs following this pattern:/animals/pages/allanimals- Public animals listing/animals/gest/create- Create animal (back-office)/animals/pages/animalpicked?id=5- View specific animal/habitats/pages/habitats- Public habitats page/auth/pages/login- Login page
Layout System
The application uses two main layouts:- FC_main_layout.php: Front-office (public) layout with visitor navigation
- BO_main_layout.php: Back-office layout with admin navigation and permissions
handleDomainRouting() function automatically selects the appropriate layout based on the domain and action.
Next Steps
Explore the specific architectural components:Front Controller
Learn how requests enter the application
Routing System
Understand authentication and routing logic
Domain Structure
Dive into domain-driven MVC organization