A CodeIgniter 4 project has a few main folders.
| Folder / file | What goes there |
|---|---|
app/Config |
Configuration files, including Routes.php |
app/Controllers |
Controllers (Home.php, BaseController.php) |
app/Models |
Models |
app/Views |
View files (HTML + PHP) |
app/Database/Migrations |
Table definitions |
app/Database/Seeds |
Seeders for sample data |
app/Filters |
Filters (like middleware) |
app/Helpers, app/Libraries |
Your own helpers and classes |
public |
index.php, CSS, JS, images — the web root |
writable |
Cache, logs, sessions, uploads |
tests |
Automated tests |
vendor |
Composer packages, including the framework itself |
spark |
The command-line tool |
.env |
Environment settings and passwords |
Request flow
Every request enters public/index.php → routes in app/Config/Routes.php → a controller → models and views → response.
Important
Only public should be reachable from the web. The writable folder must be writable by the web server.
Example
Example — Where each part lives
PHP
<?php
// app/Config/Routes.php -> the URL
$routes->get('about', 'Pages::about');
// app/Controllers/Pages.php -> the logic
namespace App\Controllers;
class Pages extends BaseController
{
public function about()
{
return view('pages/about'); // loads app/Views/pages/about.php
}
}
// app/Views/pages/about.php -> the HTML
// <h1>About us</h1>
view('pages/about') loads app/Views/pages/about.php. View files are plain .php files.