CodeIgniter Folder, File & Directory Structure

โšก Smart Summary

CodeIgniter organizes a PHP project into predictable folders for application logic, framework system files, composer vendor packages, and a single entry script, so beginners can locate code quickly and intermediate developers can scale a clean MVC structure.

  • ๐Ÿ“ Application folder: Holds your controllers, models, views, config, cache, helpers, hooks, language, libraries, logs, and third_party packages.
  • ๐Ÿงฉ System folder: Stores the framework core, database drivers, fonts, helpers, language, and built-in libraries; do not edit these files directly.
  • โš™๏ธ Entry point: The root index.php boots the framework, sets paths, and routes every HTTP request through the front controller.
  • โœ… Version differences: CodeIgniter 3 uses application/ and system/, while CodeIgniter 4 introduces app/, public/, and writable/ folders for stricter separation.
  • ๐Ÿงช Vendor and user_guide: Vendor stores composer packages you deploy, while user_guide is local documentation you should exclude from production servers.

CodeIgniter Folder

Understanding the file structure in CodeIgniter is essential before you build any real application. A predictable layout helps you locate controllers, models, and views quickly, debug routing issues, and onboard new team members faster. This tutorial covers the classic CodeIgniter 3 structure that is still widely deployed, and also clarifies the key differences you will encounter in CodeIgniter 4.x, which introduces app/, public/, and writable/ as separate top-level folders.

What Is the CodeIgniter File and Directory Structure?

The CodeIgniter file structure is the default arrangement of folders and PHP files that the framework ships with after you download or install it. It separates your application logic from the framework core, keeps composer dependencies isolated, and exposes a single entry point through index.php. The following image shows the file structure in CodeIgniter:

CodeIgniter File/Folder/Directory Structure
CodeIgniter File/Folder/Directory Structure

Here is a simplified directory tree for a fresh CodeIgniter 3 installation:

// CodeIgniter 3 root layout
project-root/
โ”œโ”€โ”€ application/
โ”œโ”€โ”€ system/
โ”œโ”€โ”€ user_guide/
โ”œโ”€โ”€ vendor/
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ composer.lock
โ””โ”€โ”€ index.php

Top-Level Folders Explained

Let us now look at the above files in CodeIgniter Structure:

  • application โ€“ this is the directory that will contain your application logic. All of your application code will be contained in this directory.
  • system โ€“ this folder contains the framework core files. It is not advised to make changes in this directory or put your own application code into this directory.
  • user_guide โ€“ this directory contains the user manual for CodeIgniter.
  • vendor โ€“ this directory contains composer packages source code. The other files related to this directory are composer.json and composer.lock.
  • index.php โ€“ this is the entry point into the application.

CodeIgniter Application Subdirectories

Let us now look at the directories in more detail. As mentioned, the application directory contains your project code. In this section, we will look at the internal subdirectories in the CodeIgniter directory structure:

  • cache โ€“ stores cached files generated by the output and database caching libraries.
  • config โ€“ keeps configuration files such as database.php, routes.php, and autoload.php.
  • controllers โ€“ all application controllers are defined here and map URL segments to actions.
  • core โ€“ contains custom core classes that extend system files. For example, if you create a base controller that other controllers should extend, you would place it in this directory.
  • helpers โ€“ this directory of the CodeIgniter folder structure is used for user-defined helper functions.
  • hooks โ€“ used for custom hooks in the CI folder structure that fire during the framework execution cycle.
  • language โ€“ used to store language files for applications that use more than one language.
  • libraries โ€“ used to store custom created libraries.
  • logs โ€“ application log files are kept in this directory.
  • models โ€“ all application models should be defined in this directory.
  • third_party โ€“ this is used for custom packages that you or other developers have created.
  • views โ€“ application views go into this directory.

Here is an example of the application subdirectory tree:

// application/ subdirectories
application/
โ”œโ”€โ”€ cache/
โ”œโ”€โ”€ config/
โ”œโ”€โ”€ controllers/
โ”œโ”€โ”€ core/
โ”œโ”€โ”€ helpers/
โ”œโ”€โ”€ hooks/
โ”œโ”€โ”€ language/
โ”œโ”€โ”€ libraries/
โ”œโ”€โ”€ logs/
โ”œโ”€โ”€ models/
โ”œโ”€โ”€ third_party/
โ””โ”€โ”€ views/

CodeIgniter System Subdirectories

Let us now look at system subdirectories in the CI file structure. Remember this is where the framework source code resides, therefore do not make any changes to the files in this directory.

  • core โ€“ this is like the heart of the CodeIgniter Framework. All of the core files that make up the framework are located here. If you would like to extend the functionality of the core file, then you need to create a custom core file in the application directory. After that, you can override or add new behavior that you wish. You should never make changes directly in here.
  • database โ€“ database drivers, cache, and other files needed for database operations are provided in here.
  • fonts โ€“ as the name suggests, this directory contains fonts and information relating to fonts.
  • helpers โ€“ this directory in the CodeIgniter structure folder contains helper functions that come out of the box.
  • language โ€“ contains language files that are used by the framework.
  • libraries โ€“ contains the source files for the various libraries that come with CodeIgniter out of the box.

The system folder layout looks like this:

// system/ subdirectories
system/
โ”œโ”€โ”€ core/
โ”œโ”€โ”€ database/
โ”œโ”€โ”€ fonts/
โ”œโ”€โ”€ helpers/
โ”œโ”€โ”€ language/
โ””โ”€โ”€ libraries/

CodeIgniter user_guide Directory

This directory serves as a reference guide for when you want to understand the CodeIgniter API. You should not upload this directory when deploying your application to production, as it adds size and exposes documentation that has no place on a live server.

CodeIgniter Vendor Directory

This directory contains source files for packages that you install via composer. The files in this directory should be left as they are and no changes should be made to them. Unlike the user_guide directory, this directory should be uploaded if you are using composer packages in your application.

index.php File

The index.php file in the CodeIgniter file structure contains the bootstrap code that defines environment, paths, and error reporting before handing control to the framework. This file is located in the root directory and acts as the front controller for every incoming HTTP request.

How CodeIgniter 4 Changes the Structure

CodeIgniter 4.x re-organized the layout to improve security and PSR-4 autoloading. Instead of a single application folder, you now see three top-level folders that separate concerns more strictly:

  • app/ โ€“ equivalent to the older application/ folder, holding Controllers, Models, Views, Config, Filters, and Libraries.
  • public/ โ€“ the only web-exposed folder, containing index.php and your CSS, JS, and image assets.
  • writable/ โ€“ stores cache, logs, sessions, and uploads that the framework needs to write at runtime.
  • system/ โ€“ still holds the framework core, namespaced under CodeIgniter\.
  • vendor/ โ€“ composer packages, identical in role to CI 3.
// CodeIgniter 4 root layout
project-root/
โ”œโ”€โ”€ app/
โ”œโ”€โ”€ public/
โ”œโ”€โ”€ writable/
โ”œโ”€โ”€ system/
โ”œโ”€โ”€ vendor/
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ env
โ””โ”€โ”€ spark

If you are starting a new project today, CodeIgniter 4 is the recommended version. If you are maintaining an older codebase, the CI 3 structure described above will match what you see on disk.

Working With the CodeIgniter Structure Day-to-Day

Once you know where each folder lives, common tasks become straightforward. Create a new controller under application/controllers/ (or app/Controllers/ in CI 4), match it to a route in config/routes.php, build a model under models/, and render output from a view file in views/. Keep configuration in config/, drop reusable code into helpers/ or libraries/, and let composer manage everything inside vendor/. Stick to this discipline and your project will remain easy to navigate even as it grows.

FAQs

The application folder holds your project code such as controllers, models, and views, and you edit it freely. The system folder holds the framework core, and you should never modify its files because framework upgrades will overwrite them.

In CodeIgniter 4 you place new controllers in the app/Controllers/ folder using PSR-4 namespaces. Match the file name to the class name, then register a route in app/Config/Routes.php so the framework can dispatch requests to it.

No. The user_guide folder is local documentation only. Exclude it from production deployments to reduce footprint and avoid exposing framework reference material on a live server. Vendor and system folders, by contrast, must be deployed.

The index.php file is the front controller. It sets the environment, defines path constants, and loads the framework bootstrap so every incoming request is routed through the CodeIgniter pipeline before reaching your controllers and views.

Yes. AI tools such as GitHub Copilot, Cursor, and Claude can scaffold controllers, models, and views in the correct folders, explain unfamiliar files, and flag misplaced classes. They are especially helpful when you switch between CodeIgniter 3 and CodeIgniter 4 layouts.

AI assistants explain how controllers handle requests, models manage data, and views render output, then generate matching files in the correct folders. They can also review your code, suggest refactors, and reinforce MVC separation as you build real CodeIgniter projects.

Summarize this post with: