agyanadda@gmail.com

CodeIgniter 4 Folder Structure

CodeIgniter 4 Basics 1 min read Updated Dec 3, 2026 Topic 3 of 30

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.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which folder is the web root in CodeIgniter 4?

Exercise 2 True / False

The writable folder stores logs, cache and sessions.

Exercise 3 Fill in the Blank

Routes are defined in app/Config/___.php

Frequently Asked Questions

In a Composer install it is in vendor/codeigniter4/framework/system. Do not edit it: Composer will overwrite your changes. Extend or replace classes from your app folder instead.