PHPackages                             dcardenasl/ci4-api-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. dcardenasl/ci4-api-core

ActiveLibrary[HTTP &amp; Networking](/categories/http)

dcardenasl/ci4-api-core
=======================

DTO-first API runtime foundation for CodeIgniter 4: base classes, HTTP layer, services, repositories, filters, audit chain, and queue. Powers ci4-api-starter and ci4-domain-starter. Pair with dcardenasl/ci4-api-scaffolding for CRUD generation.

v0.9.3(1w ago)01.6k↑117.4%[3 PRs](https://github.com/dcardenasl/ci4-api-core/pulls)1MITPHPPHP ^8.2CI passing

Since May 3Pushed 2d agoCompare

[ Source](https://github.com/dcardenasl/ci4-api-core)[ Packagist](https://packagist.org/packages/dcardenasl/ci4-api-core)[ Docs](https://github.com/dcardenasl/ci4-api-core)[ RSS](/packages/dcardenasl-ci4-api-core/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (24)Versions (18)Used By (1)

ci4-api-core
============

[](#ci4-api-core)

[![CI](https://github.com/dcardenasl/ci4-api-core/actions/workflows/ci.yml/badge.svg)](https://github.com/dcardenasl/ci4-api-core/actions/workflows/ci.yml)[![Coverage](https://camo.githubusercontent.com/38e2146949ef2b493c1504c8be7161ca74a5dba2c302b06613856fe3f3af82ca/68747470733a2f2f636f6465636f762e696f2f67682f6463617264656e61736c2f6369342d6170692d636f72652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/dcardenasl/ci4-api-core)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/d1fb67e8aae8200f23058ad7fa4c6d61e0ee9ad490f9c6acf5ce0581bb366b34/68747470733a2f2f706f7365722e707567782e6f72672f6463617264656e61736c2f6369342d6170692d636f72652f76)](https://packagist.org/packages/dcardenasl/ci4-api-core)[![Total Downloads](https://camo.githubusercontent.com/bb672e93e9b34450297242d3b4715276ffa2b516820b5ef6f409ee2b52a7a39c/68747470733a2f2f706f7365722e707567782e6f72672f6463617264656e61736c2f6369342d6170692d636f72652f646f776e6c6f616473)](https://packagist.org/packages/dcardenasl/ci4-api-core)

Production-ready REST API foundation for CodeIgniter 4. Drop it into any CI4 project to get a DTO-first architecture, JWT-ready HTTP layer, audit trail, queue, RBAC-ready filters, and a repository pattern — without writing boilerplate. Pair with [`dcardenasl/ci4-api-scaffolding`](https://github.com/dcardenasl/ci4-api-scaffolding) to scaffold full CRUD modules in one command.

> **Status:** `v1.0.0` — stable, published on Packagist. Semantic versioning applies from this release: `^1.0` is safe for production.

Contents
--------

[](#contents)

- [Quick Start](#quick-start)
- [What it does](#what-it-does)
- [Why a package](#why-a-package)
- [Runtime foundation](#runtime-foundation)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configure](#configure)
- [Usage](#usage)
- [Field syntax](#field-syntax)
- [Scope and limitations](#scope-and-limitations-v0x)
- [Customization](#customization)
- [Scaffolding contract](#scaffolding-contract)
- [Wiring assumption](#wiring-assumption)
- [Troubleshooting](#troubleshooting)
- [See also](#see-also)
- [Toward 1.0](#toward-10)
- [Development](#development)
- [License](#license)

Quick Start
-----------

[](#quick-start)

```
# Runtime foundation
composer require dcardenasl/ci4-api-core:^1.0

# Scaffolding engine (dev-only — provides make-crud.sh and spark commands)
composer require --dev dcardenasl/ci4-api-scaffolding:^0.7

# Scaffold a CRUD module
bash vendor/bin/make-crud.sh Product Catalog \
  'name:string:required|searchable,price:decimal:required|filterable' yes

# Validate wiring
php spark module:check Product --domain Catalog
```

What it does
------------

[](#what-it-does)

> **Package boundary:** `ci4-api-core` provides the **runtime foundation** — base classes, HTTP layer, services, repositories, models, filters, audit chain, queue, and security utilities. The scaffolding engine (generators, `make-crud.sh`, spark commands) lives in the companion package `dcardenasl/ci4-api-scaffolding`. The flowchart below shows the full system when both packages are installed.

Generates a complete, production-ready CRUD module from a single command:

```
bash vendor/bin/make-crud.sh Product Catalog \
  'name:string:required|searchable,price:decimal:required|filterable,category_id:fk:categories:required' \
  yes
```

 ```
flowchart TB
    Input["Field specname:string:required|searchable,price:decimal:filterable,category_id:fk:categories"]
    Schema["ResourceSchema(parsed Fields,typed via TypeMapper)"]

    subgraph Generators["8 Generators"]
        direction TB
        DTO["DTO(Index/Create/Update/Response)"]
        Service["Service(interface + impl)"]
        Controller["Controller + OpenAPI doc"]
        Migration["Migration(timestamped)"]
        Model["Model + Entity"]
        Routes["Routes(v1/{domain}.php)"]
        Lang["Language files(en + es)"]
        Tests["Tests(Unit + Integration + Feature)"]
    end

    Wiring["ConfigWireman(injects intoConfig/Services.php)"]

    Input --> Schema --> Generators --> Wiring
```

      Loading Outputs:

- 4 DTOs (Index/Create/Update request + Response) with validation and OpenAPI annotations
- Service interface + implementation extending your base CRUD service
- Controller with explicit CRUD methods and OpenAPI doc class
- Timestamped database migration
- Model + Entity extending your auditable base
- Route file under `app/Config/Routes/v1/{domain-kebab}.php`
- Language files (`en` + `es`)
- Unit / Integration / Feature test skeletons
- Service registrations injected into `Config/Services.php` (or printed for manual paste with `--no-wire`)

Why a package
-------------

[](#why-a-package)

The engine was being copied between projects manually, leading to drift. Extracting it gives:

- **Single source of truth** — bug fixes apply to all consumers via `composer update`.
- **Versioned upgrades** — projects pin to a constraint and adopt new versions when ready.
- **Configurable conventions** — base class FQCNs, paths, and route filters are declared per project in `Config\Scaffolding`.

Runtime foundation
------------------

[](#runtime-foundation)

`ci4-api-core` ships the classes that generated (and hand-written) modules extend and depend on at runtime:

LayerKey classes**HTTP**`ApiController` (`handleRequest()` pipeline), `ApiRequest`, `ApiResponse`, `ContextHolder`, `RequestIdHolder`**HTTP filters**`CorsFilter`, `CorrelationIdFilter`, `IdempotencyFilter`, `LocaleFilter`, `MaintenanceFilter`, `RequestLoggingFilter`, `DeprecationHeadersFilter`, `FeatureToggleFilter`**DTOs**`BaseRequestDTO` (auto-validation), `PaginatedResponseDTO`, `DataTransferObjectInterface`, `SecurityContext`**Services**`BaseCrudService`, `CrudServiceContract`, `HandlesTransactions` trait, `AuditService`, `AuditServiceInterface`, `NullAuditService`**Repositories**`RepositoryInterface`, `GenericRepository`, `BaseRepository`, `AuditRepositoryInterface`**Models**`BaseAuditableModel`, `Auditable` trait, `Filterable` trait, `Searchable` trait, `DecimalCast`**Query layer**`FilterParser`, `FilterOperatorApplier`, `SearchQueryApplier`, `QueryBuilder`**Exceptions**`ApiException` + `NotFoundException`, `ValidationException`, `BadRequestException`, `AuthenticationException`, `AuthorizationException`, `ConflictException`, `ServiceUnavailableException`, `TooManyRequestsException`**Support**`OperationResult`, `OperationState` enum, `ApiResult`, `ExceptionFormatter`, `ApiConfigFacade` · `RelationLabelLoader` (batch label loading, no N+1) · `CacheHelper` (cache-aside in one line) · `DateHelper` (null-safe date normalisation) — see [`docs/SUPPORT_UTILITIES.md`](docs/SUPPORT_UTILITIES.md)**Security**`Security\Hasher`, `Security\Token`, `Security\Mask`**Queue**`QueueManager`, `SyncQueueManager`, `Job` base, `WriteAuditLogJob`, `LogRequestJob`**Logging**`JsonFormatter`, `MonologHandler`Requirements
------------

[](#requirements)

- PHP `^8.2`
- CodeIgniter 4 `^4.7`

Installation
------------

[](#installation)

```
composer require dcardenasl/ci4-api-core:^1.0
```

Configure
---------

[](#configure)

### Runtime — `Config\Api` (optional)

[](#runtime--configapi-optional)

`ci4-api-core` reads an optional `Config\Api` class for search and pagination knobs. Defaults are safe when absent:

```
