CodeIgniter Project Structure

CodeIgniter 235 views Dec 22, 2025 2 min read

Below is a clear explanation of the CodeIgniter project structure, focusing on CodeIgniter 4 (with a short note on CI3 at the end).


CodeIgniter 4 Project Structure

codeigniter4/ โ”‚ โ”œโ”€โ”€ app/ โ”œโ”€โ”€ public/ โ”œโ”€โ”€ system/ โ”œโ”€โ”€ writable/ โ”œโ”€โ”€ env โ”œโ”€โ”€ spark โ””โ”€โ”€ composer.json

1. app/ (Main Application Folder)

This is where you write most of your code.

app/ โ”œโ”€โ”€ Config/ โ”œโ”€โ”€ Controllers/ โ”œโ”€โ”€ Models/ โ”œโ”€โ”€ Views/ โ”œโ”€โ”€ Database/ โ”œโ”€โ”€ Filters/ โ”œโ”€โ”€ Helpers/ โ”œโ”€โ”€ Language/ โ””โ”€โ”€ Libraries/

???? Controllers/

Handles user requests and application flow.

class Home extends BaseController { public function index() { return view('home'); } }

???? Models/

Manages database interactions.

class UserModel extends Model { protected $table = 'users'; }

???? Views/

Contains UI files (HTML, CSS, JS).

<h1>Welcome to CodeIgniter</h1>

???? Config/

Application configuration files:

  • App.php โ†’ baseURL, app name

  • Database.php โ†’ database settings

  • Routes.php โ†’ URL routing


???? Database/

Database-related files:

Database/ โ”œโ”€โ”€ Migrations/ โ”œโ”€โ”€ Seeds/ โ””โ”€โ”€ Factories/
  • Migrations โ†’ version control for database schema

  • Seeds โ†’ insert dummy data


???? Filters/

Middleware-like logic (auth, CSRF, etc.)


???? Helpers/

Reusable functions (form, URL, text helpers)


???? Language/

Multilingual support files


???? Libraries/

Custom libraries and classes


2. public/ (Web Root)

public/ โ”œโ”€โ”€ index.php โ”œโ”€โ”€ .htaccess โ””โ”€โ”€ assets/
  • Entry point of the application

  • CSS, JS, images go inside assets/


3. system/ (Core Framework)

  • Contains CodeIgniter core files

  • โŒ Do NOT modify


4. writable/ (Writable Directory)

writable/ โ”œโ”€โ”€ cache/ โ”œโ”€โ”€ logs/ โ”œโ”€โ”€ session/ โ””โ”€โ”€ uploads/
  • Cache

  • Logs

  • File uploads

  • Must have write permissions


5. env / .env

Environment configuration:

CI_ENVIRONMENT = development

6. spark

Command-line tool for:

  • Creating controllers/models

  • Running migrations

  • Starting server

Example:

php spark make:controller Home

7. composer.json

  • Dependency management

  • Autoloading


CodeIgniter 3 Structure (Quick Comparison)

application/ โ”œโ”€โ”€ controllers/ โ”œโ”€โ”€ models/ โ”œโ”€โ”€ views/ โ”œโ”€โ”€ config/ system/

Key Differences: CI3 vs CI4

FeatureCI3CI4
PHP Version5.6+7.4+
Folder StructureSimpleModular
NamespacesโŒโœ…
CLI ToolโŒโœ… (Spark)

Summary

  • app/ โ†’ your application code

  • public/ โ†’ web-accessible files

  • system/ โ†’ framework core

  • writable/ โ†’ cache, logs, uploads

Some advanced sections are available for Registered Members
Share this Post
๐Ÿš€ Want to Test Your Knowledge?

Take quizzes related to this topic and see where you stand!

Start Quiz Now
Back to Tutorials