CodeIgniter 4 Backend Development with JWT and Caching

When hosting resources are limited and you need to launch a project quickly, choosing a PHP framework often comes down to balancing performance and functionality. We've encountered situations where Laravel proved excessive—30–50 MB at startup, slow compilation, and high memory demand. For such cases

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1281
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1237
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    977
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1025
  • image_website-sbh_0.webp
    Website development for SBH Partners
    1103
  • image_website-_0.webp
    Website development for Red Pear
    550

When hosting resources are limited and you need to launch a project quickly, choosing a PHP framework often comes down to balancing performance and functionality. We've encountered situations where Laravel proved excessive—30–50 MB at startup, slow compilation, and high memory demand. For such cases, we use CodeIgniter 4: lightweight, no magic, with straightforward documentation. According to CodeIgniter's official documentation, the framework is designed for optimal performance on low-cost hosting. A typical project starts at $2,500, with savings up to 40% on server costs compared to heavier frameworks.

CodeIgniter 4 is a framework that doesn't get in the way of writing fast code. It provides a built-in ORM (Query Builder + Model), HTTP layer via PSR-7, JWT authentication out of the box, while consuming minimal resources. Ideal scenarios for CI4: small to medium websites, budget web servers, teams experienced with this framework, and projects with strict response time requirements on weak hardware. Learn more about the language's capabilities in the PHP documentation.

Starting Point for Backend Development on PHP (CodeIgniter)

The first step is always an audit of the current infrastructure and requirements. We analyze load, data volume, and expected growth. Then we design the database architecture and API, choosing optimal caching tools. CI4 allows quick scaffolding via its built-in code generator and migrations.

Common Problems Solved in CodeIgniter Backends

N+1 Queries and Inefficient Database Operations

A typical scenario: in a product list, an additional query is made for each category in a loop. In CodeIgniter 4, we use repositories or custom model methods with JOIN. For example, the getWithCategory() method pulls related data in one query. Instead of calling $product->category() for each product in a loop, we do one JOIN query: $this->db->join('categories', 'categories.id = products.category_id'). This reduces queries from N+1 to 1.

Lack of Structure in API

Many start writing logic directly in controllers. We apply a service layer and repositories. The controller only accepts requests and returns responses; all business logic is in services. This simplifies testing and maintenance.

Authentication and Authorization

We implement a JWT filter with role checking. The filter checks the token in the Authorization header, decodes JWT, and stores the payload in $request->user. Admin routes are protected with separate filters. This JWT authentication for CodeIgniter backend is both fast and secure.

How Does CodeIgniter 4 Perform on Shared Hosting?

On low-cost hosting, CodeIgniter 4 processes requests 2–3 times faster than Laravel under equal conditions. This is achieved through its streamlined architecture: fewer loaded classes, no facade magic, a simplified service container. For high-traffic sites, this yields up to 40% improvement in TTFB, which can translate to significant hosting cost savings.

Characteristic CodeIgniter 4 Laravel
Memory per request ~5 MB ~15 MB
Response time (shared hosting) ~200 ms ~500 ms
Framework size ~1.2 MB ~25 MB

Configuring CodeIgniter 4: Step-by-Step Guide

  1. Install the framework via Composer: composer create-project codeigniter4/appstarter project-root.
  2. Configure database connection in .env: database.default.hostname = localhost, etc.
  3. Create migrations for tables via php spark make:migration.
  4. Implement models with validation and relationships.
  5. Write controllers and routes, connect the JWT filter.

Implementing JWT Authentication in CI4

View the filter we use in every project
namespace App\Filters; use CodeIgniter\Filters\FilterInterface; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Firebase\JWT\JWT; use Firebase\JWT\Key; class JwtFilter implements FilterInterface { public function before(RequestInterface $request, $arguments = null) { $authHeader = $request->getHeaderLine('Authorization'); if (!str_starts_with($authHeader, 'Bearer ')) { return service('response')->setStatusCode(401)->setJSON(['error' => 'Unauthorized']); } try { $token = substr($authHeader, 7); $payload = JWT::decode($token, new Key(getenv('JWT_SECRET'), 'HS256')); // Check role if provided in arguments if ($arguments && !in_array($payload->role, $arguments)) { return service('response')->setStatusCode(403)->setJSON(['error' => 'Forbidden']); } // Store in request for controllers $request->user = $payload; } catch (\Exception $e) { return service('response')->setStatusCode(401)->setJSON(['error' => 'Invalid token']); } } public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) {} } 

Stack and Configuration Example

We use the latest CodeIgniter version on modern PHP, PostgreSQL or MySQL, Redis for caching, Nginx. Frontend—Vue.js or React via API. Here's an example routing structure and controller.

// app/Config/Routes.php $routes->group('api/v1', ['namespace' => 'App\Controllers\Api\V1'], function ($routes) { // Auth (public) $routes->post('auth/login', 'AuthController::login'); $routes->post('auth/refresh', 'AuthController::refresh'); // Protected via filter $routes->group('', ['filter' => 'jwt'], function ($routes) { $routes->get('profile', 'UserController::profile'); $routes->resource('products', ['controller' => 'ProductController']); // Generates: GET /, GET /:id, POST /, PUT /:id, DELETE /:id }); // Admin-only $routes->group('admin', ['filter' => 'jwt:admin'], function ($routes) { $routes->resource('users', ['controller' => 'Admin\UserController']); }); }); 
namespace App\Controllers\Api\V1; use App\Controllers\BaseController; use App\Models\ProductModel; use CodeIgniter\HTTP\ResponseInterface; class ProductController extends BaseController { private ProductModel $productModel; public function __construct() { $this->productModel = new ProductModel(); } public function index(): ResponseInterface { $page = (int) ($this->request->getGet('page') ?? 1); $limit = min((int) ($this->request->getGet('limit') ?? 20), 100); $query = $this->productModel ->where('is_active', 1) ->orderBy('created_at', 'DESC'); if ($categoryId = $this->request->getGet('category_id')) { $query->where('category_id', (int) $categoryId); } $total = $query->countAllResults(false); $products = $query->paginate($limit, 'default', $page); return $this->response->setJSON([ 'data' => $products, 'pagination' => [ 'page' => $page, 'limit' => $limit, 'total' => $total, 'pages' => (int) ceil($total / $limit), ], ]); } public function create(): ResponseInterface { $data = $this->request->getJSON(true); if (!$this->validate($this->productModel->getValidationRules())) { return $this->response->setStatusCode(422)->setJSON([ 'errors' => $this->validator->getErrors(), ]); } $id = $this->productModel->insert($data); $product = $this->productModel->find($id); return $this->response->setStatusCode(201)->setJSON($product); } } 

Model with validation and custom methods:

namespace App\Models; use CodeIgniter\Model; class ProductModel extends Model { protected $table = 'products'; protected $primaryKey = 'id'; protected $returnType = 'array'; protected $useSoftDeletes = true; protected $useTimestamps = true; protected $allowedFields = ['name', 'slug', 'price', 'category_id', 'description', 'is_active', 'attributes']; protected $validationRules = [ 'name' => 'required|min_length[2]|max_length[255]', 'price' => 'required|decimal|greater_than[0]', 'category_id' => 'permit_empty|integer|is_not_unique[categories.id]', ]; protected $validationMessages = [ 'name' => ['required' => 'Name is required'], 'price' => ['greater_than' => 'Price must be greater than zero'], ]; protected $beforeInsert = ['generateSlug']; protected $beforeUpdate = ['generateSlug']; protected function generateSlug(array $data): array { if (isset($data['data']['name']) && empty($data['data']['slug'])) { $data['data']['slug'] = url_title($data['data']['name'], '-', true); } return $data; } } 

Estimated Timelines and What's Included

Component Duration
Configuration + models + migrations 2–4 days
Routes + controllers + auth 1–1.5 weeks
Business logic 1–3 weeks
Tests (phpunit + CI Test Tools) 3–5 days

Small or medium site: 3–7 weeks. Timelines depend on API complexity and integrations. Typical project cost: starting from $2,500 (includes configuration, API, auth, caching). We'll estimate your project in 1 day—just contact us.

What We Do:

  • Design database architecture and create migrations
  • Implement REST API with JWT authentication
  • Configure caching (Redis/File) and optimize queries
  • Write unit and integration tests
  • Prepare API documentation (Swagger/Postman)
  • Deploy the project on server (Docker or bare-metal)
  • Hand over access and train your team
  • Provide 30-day warranty support

With over 8 years of PHP development and 20+ projects on CodeIgniter 4—from simple landing pages to marketplaces—we deliver 98% of projects on time. Get a fast, reliable backend without overpaying by contacting us for a consultation today.