Entry Point Overview
Understanding public/index.php - the front door of your application
The Front Door of Your Application
When you visit a website, your browser sends a request: "Hello server, please give me /posts".
public/index.php is the front door of the app. Every single request comes here first.
What Happens Here
This file is responsible for:
- Setting up the environment - Sessions, autoloading, constants
- Loading the framework - Bootstrap, helpers, configuration
- Routing the request - Finding the right controller to handle it
- Handling errors - Catching validation errors and exceptions
- Cleaning up - Removing flash data after the response
Think of it like a restaurant host:
- Greets every customer (request)
- Checks reservations (sessions)
- Guides them to the right table (routing)
- Handles complaints (error handling)
The Complete Flow
Browser Request
↓
public/index.php (YOU ARE HERE)
↓
1. Define BASE_PATH
2. Load Composer autoloader
3. Start session
4. Load helper functions
5. Bootstrap framework (container, database)
6. Load .dalt platform (if exists)
7. Create router
8. Load routes
9. Capture request
10. Route to controller
11. Handle errors
12. Clean up flash data
↓
Response to BrowserWhy This Matters
Understanding this file teaches you:
- How web frameworks bootstrap themselves
- Why sessions must start before output
- How dependency injection containers work
- How error handling flows through an application
- The difference between framework code and platform code
Let's dive into the details, starting with imports and constants.
Importing Classes
use Core\App;
use Core\Request;
use Core\Session;
use Core\ValidationException;What is use?
In PHP, use is like giving a nickname to a long class name.
Without use:
$request = new \Core\Request();With use:
use Core\Request;
$request = new Request();The Classes We Import
Core\App- Global access to the dependency containerCore\Request- Wraps$_GET,$_POST,$_SERVERinto an objectCore\Session- Helper methods for$_SESSIONmanagementCore\ValidationException- Special exception for form validation errors
These classes live in framework/Core/ and are the foundation of the framework.
Defining BASE_PATH
const BASE_PATH = __DIR__ . '/../';
require BASE_PATH . 'vendor/autoload.php';What is BASE_PATH?
BASE_PATH is the absolute path to your project root folder.
__DIR__means "the folder this file is in" →public/__DIR__ . '/../'means "go one folder up" → project root
Example on your computer:
/home/user/myproject/public/index.php
__DIR__ = /home/user/myproject/public
BASE_PATH = /home/user/myproject/Why Do We Need It?
Throughout the framework, we need to reference files:
routes/routes.phpconfig/database.phpresources/views/welcome.view.php
Using BASE_PATH ensures these paths work regardless of:
- Where PHP is installed
- What the current working directory is
- How the web server is configured
Loading Composer's Autoloader
require BASE_PATH . 'vendor/autoload.php';What is Composer?
- PHP's dependency manager (like npm for JavaScript)
- Generates
vendor/autoload.phpwhich teaches PHP how to load classes automatically
Why is this important?
- Without this, you'd need to manually
requireevery single class file - Composer maps namespaces to directories automatically
- Example:
Core\Database→framework/Core/Database.php
The Old Manual Autoloader (Commented Out)
//spl_autoload_register(function ($class) {
// $class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
// require base_path("{$class}.php");
//});This is commented out because Composer's autoloader is the standard approach. Before Composer, developers wrote custom autoloaders like this.
What it does:
- Converts
Core\Database→Core/Database.php - Requires the file automatically when the class is used
Why it's not used:
- Composer's autoloader is more powerful and standard
- It handles PSR-4 autoloading, optimizations, and vendor packages
Key Takeaways
- Every request starts here -
public/index.phpis the single entry point - BASE_PATH is crucial - It's the anchor for all file paths
- Composer autoloading is standard - No manual
requirestatements needed - Imports make code cleaner -
usestatements avoid long class names - Session security matters - Unique names and secure cookies prevent attacks
What's Good Here
✅ Single entry point makes the request flow predictable
✅ BASE_PATH is defined early and used consistently
✅ Composer autoloading is the industry standard
✅ Clean imports at the top make dependencies visible
✅ Secure session configuration with HttpOnly and SameSite
✅ Unique session names prevent cross-project conflicts
Design Note
DALT keeps the entry point intentionally “plain PHP”:
- one file handles the full bootstrap so you can follow the request top-to-bottom
- no hidden kernel, no event system, no magic
Next, we'll look at session management and why it must happen before any output.