Application Structure

To get the most out of CodeIgniter, you need to understand how the application is structured, by default, and what youcan change to meet the needs of your application.

Default Directories

A fresh install has six directories: /app, /system, /public,/writable, /tests and possibly /docs.Each of these directories has a very specific part to play.

app

The app directory is where all of your application code lives. This comes with a default directorystructure that works well for many applications. The following folders make up the basic contents:

  1. /app
  2. /Config Stores the configuration files
  3. /Controllers Controllers determine the program flow
  4. /Database Stores the database migrations and seeds files
  5. /Filters Stores filter classes that can run before and after controller
  6. /Helpers Helpers store collections of standalone functions
  7. /Language Multiple language support reads the language strings from here
  8. /Libraries Useful classes that don't fit in another category
  9. /Models Models work with the database to represent the business entities.
  10. /ThirdParty ThirdParty libraries that can be used in application
  11. /Views Views make up the HTML that is displayed to the client.

Because the app directory is already namespaced, you should feel free to modify the structureof this directory to suit your application’s needs. For example, you might decide to start using the Repositorypattern and Entity Models to work with your data. In this case, you could rename the Models directory toRepositories, and add a new Entities directory.

Note

If you rename the Controllers directory, though, you will not be able to use the automatic method ofrouting to controllers, and will need to define all of your routes in the routes file.

All files in this directory live under the App namespace, though you are free to change that inapp/Config/Constants.php.

system

This directory stores the files that make up the framework, itself. While you have a lot of flexibility in how youuse the application directory, the files in the system directory should never be modified. Instead, you shouldextend the classes, or create new classes, to provide the desired functionality.

All files in this directory live under the CodeIgniter namespace.

public

The public folder holds the browser-accessible portion of your web application,preventing direct access to your source code.It contains the main .htaccess file, index.php, and any applicationassets that you add, like CSS, javascript, orimages.

This folder is meant to be the “web root” of your site, and your web serverwould be configured to point to it.

writable

This directory holds any directories that might need to be written to in the course of an application’s life.This includes directories for storing cache files, logs, and any uploads a user might send. You should add any otherdirectories that your application will need to write to here. This allows you to keep your other primary directoriesnon-writable as an added security measure.

tests

This directory is set up to hold your test files. The _support directory holds various mock classes and otherutilities that you can use while writing your tests. This directory does not need to be transferred to yourproduction servers.

docs

If this directory is part of your project, it holds a local copy of the CodeIgniter4User Guide.

Modifying Directory Locations

If you’ve relocated any of the main directories, you can change the configurationsettings inside app/Config/Paths.

Please read Managing your Applications