Skip to main content
Application Architecture

Application Architecture

Every CodeIgniter request enters through a single front controller, is matched to a route, passes through filters, and ends in a controller that builds a response. Understanding that path makes the folder layout much easier to remember.

Illustration of a request moving from a browser through routing and application logic to a page
The request lifecycle: boot, route, filter, controller, response.

The request lifecycle

  1. public/index.php loads the framework and starts the request.
  2. Configuration and services are initialised for the current environment.
  3. The router matches the URL to a controller method.
  4. Global and route filters run, for example authentication or CSRF checks.
  5. The controller coordinates models, services, and validation.
  6. A view or JSON response is returned to the browser.

Top-level folders

app/        Controllers, models, views, config, filters, helpers
public/     The web root: index.php and public assets
writable/   Logs, cache, sessions, uploads
vendor/     Composer dependencies
tests/      Automated tests
.env        Environment-specific settings

Only public should be exposed by the web server. Everything else stays outside the document root.

Inside the app folder

  • Controllers handle requests and responses.
  • Models represent tables and data rules.
  • Views contain templates and partials.
  • Config holds routes, filters, database settings, and application options.
  • Filters run logic before or after controllers.
  • Helpers contain small reusable functions.
  • Libraries contain reusable classes that are not models.
  • Database stores migrations and seeds.

Namespaces

Application classes use the App namespace. A file at app/Controllers/Admin/Reports.php declares namespace App\Controllers\Admin;. The folder path and namespace must match, or the autoloader will not find the class.