A lightweight, high-performance RESTful JSON API built with PHP 8.3, Slim Framework 4, SQLite Database (PDO), Docker Containerization, CLI Health Diagnostics Prober, GitHub Actions CI, OpenAPI 3.0 Documentation & Swagger UI, PSR-7 Request/Response interfaces, PSR-15 Middleware pipeline (CORS, Request Tracing, Rate Limiting, Bearer Authentication, Input Validation, Body Parser, Content-Type), and unit tests powered by PHPUnit.
- Language / Runtime: PHP 8.3
- Framework: Slim 4 (
slim/slim) - Database Engine: SQLite 3 via PHP PDO
- Containerization: Docker & Docker Compose (PHP 8.3 Alpine)
- Documentation Engine: OpenAPI 3.0 & Swagger UI v5
- HTTP Engine: Slim PSR-7 (
slim/psr7) - CI / CD Pipeline: GitHub Actions (PHP 8.2 & 8.3 matrix testing)
- Architecture: PSR-7 Request/Response, PSR-15 Middleware Pipeline, Action Controllers, Domain Service Layer (Repository Pattern), Standalone CLI Health Prober
- Testing: PHPUnit 10 (
phpunit/phpunit)
- PHP 8.1 or higher with
pdo_sqliteextension enabled - Composer
- Docker & Docker Compose (Optional for containerized execution)
# Clone the repository
git clone https://github.com/breakingthebot/minimal-json-api-build68.git
cd minimal-json-api-build68
# Install dependencies
composer installphp -S localhost:8080 -t public# Build and start container in background
docker compose up -d --build
# View container logs
docker compose logs -f
# Check container health status
docker ps- Swagger UI Playground:
http://localhost:8080/docs - OpenAPI 3.0 Schema:
http://localhost:8080/openapi.json GET http://localhost:8080/api/v1/healthGET http://localhost:8080/api/v1/statusGET http://localhost:8080/api/v1/itemsGET http://localhost:8080/api/v1/items?category=FrameworkGET http://localhost:8080/api/v1/items?search=Slim&limit=2&offset=0GET http://localhost:8080/api/v1/items/1POST http://localhost:8080/api/v1/items(RequiresAuthorization: Bearer secret-token-123)PUT http://localhost:8080/api/v1/items/1(RequiresAuthorization: Bearer secret-token-123)DELETE http://localhost:8080/api/v1/items/1(RequiresAuthorization: Bearer secret-token-123)
Run automated system diagnostics directly from your command line for container liveness and deployment pipeline health checks:
# Human-readable report
php bin/health-check.php
# JSON formatted report
php bin/health-check.php --json
# Quiet mode (exit code 0 = healthy, exit code 1 = unhealthy)
php bin/health-check.php --quiet(Composer alias shortcut: composer health-check)
# Run PHPUnit tests locally
vendor/bin/phpunit
# Validate composer configuration
composer validate --strictThis repository uses GitHub Actions (.github/workflows/ci.yml) to automatically execute the following checks on every push and pull request against main:
- Matrix build validation across PHP 8.2 and PHP 8.3
- Composer configuration validation (
composer validate --strict) - Dependency caching and installation (
composer install) - Full PHPUnit test suite execution (
vendor/bin/phpunit) - CLI health diagnostics prober verification (
php bin/health-check.php --json)
All HTTP responses include standard cross-origin, correlation tracing, rate limiting, and execution time headers:
Access-Control-Allow-Origin:*(Configurable allowed cross-origin domain)Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS, HEADAccess-Control-Allow-Headers:X-Requested-With, Content-Type, Accept, Origin, Authorization, X-Request-IDX-Request-ID: Unique correlation UUID/hash assigned to every request lifecycleX-Response-Time: Server execution latency in milliseconds (e.g.1.25ms)X-RateLimit-Limit: Maximum requests allowed per window (default:20)X-RateLimit-Remaining: Remaining request quota in current windowX-RateLimit-Reset: Unix timestamp when request window resetsRetry-After: Seconds to wait before retrying when HTTP 429 is returned
| Method | Endpoint | Authentication | Description | Status Code |
|---|---|---|---|---|
OPTIONS |
/* |
Public | CORS preflight request handler | 204 No Content |
GET |
/docs |
Public | Interactive Swagger UI API playground | 200 OK |
GET |
/openapi.json |
Public | Raw OpenAPI 3.0 JSON specification schema | 200 OK |
GET |
/api/v1/health |
Public | API health check & timestamp | 200 OK / 429 |
GET |
/api/v1/status |
Public | System telemetry & PHP runtime info | 200 OK / 429 |
GET |
/api/v1/items |
Public | List SQL items with query filters (category, search, status, limit, offset) |
200 OK / 400 / 429 |
GET |
/api/v1/items/{id} |
Public | Get single SQL item by numeric ID | 200 OK / 404 / 429 |
POST |
/api/v1/items |
Bearer Token | Create item with SQL INSERT & validation rules (name >= 3 chars, status enum) |
201 / 401 / 400 / 429 |
PUT |
/api/v1/items/{id} |
Bearer Token | Update item resource with SQL UPDATE & validation rules (name >= 3 chars, status enum) |
200 / 401 / 400 / 404 / 429 |
DELETE |
/api/v1/items/{id} |
Bearer Token | Delete item resource from SQLite database by numeric ID | 200 / 401 / 404 / 429 |
- Docker Containerization: Multi-stage
Dockerfileandcompose.yamlrun non-root system users (appuser) and attach DockerHEALTHCHECKdirectives invokingbin/health-check.php. - Resource Management: Complete RESTful CRUD actions (
GET,POST,PUT,DELETE) executed via parameterized SQL PDO queries against SQLite database. - CORS Protection:
CorsMiddlewarehandles browser preflightOPTIONSrequests and sets explicit cross-origin headers to secure frontend SPA and cross-domain integrations. - CI/CD Security: Automated GitHub Actions workflow validates all commits and pull requests against automated regression tests before deployment.
- CLI Diagnostics Prober:
bin/health-check.phpchecks PHP engine compatibility, SQLite database connectivity, and HTTP endpoint readiness. - Interactive Documentation: Swagger UI at
/docsallows visual, interactive testing of all API endpoints directly within the web browser. - Request Tracing:
RequestTracingMiddlewaretags every request stream with a uniqueX-Request-IDcorrelation token and measures millisecond latency. - Database Storage: Item resources are stored in SQLite database (
var/database.sqlite) via PHP PDO using prepared SQL statements. - Rate Limiting Protection:
RateLimitingMiddlewareevaluates client IP request frequencies using a sliding window. - Bearer Token Security: All state-modifying requests (POST/PUT/DELETE) require a valid
Authorization: Bearer <token>header. - Data Posture: Store minimal data required for API operation. Zero personal data collected or logged.
This application uses a modular PSR-7 / PSR-15 architecture with Slim Framework 4. Controllers are decoupled into single-purpose Action classes (HealthAction, GetItemsAction, CreateItemAction, UpdateItemAction, DeleteItemAction, OpenApiJsonAction, SwaggerUiAction), keeping routing logic lean and testable. CORS, distributed request tracing, rate limiting, authentication, request body parsing, parameter validation, and Content-Type response formatting are handled by dedicated PSR-15 middlewares. Automated regression testing is handled by GitHub Actions CI workflows, and containerization is managed by multi-stage Docker builds.