rupeshstha / core-foundation
A foundational package for streamlined development, offering essential core functionality and components to accelerate project creation and enhance scalability.
Requires
- php: ^8.3|^8.4
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- laravel/slack-notification-channel: ^3.8
- symfony/stopwatch: ^7.0 | ^8.0
Requires (Dev)
- laravel/boost: ^2.4
- laravel/pennant: ^1.23
- laravel/pint: ^1.29
- nikic/php-parser: ^5.7
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.6
- phpstan/phpstan: ^2.1
- rector/rector: ^2.4
Suggests
- laravel/pennant: Required for BaseFeature and FeatureFlagController (GET /features).
README
core-foundation is a foundational package for streamlined development, offering essential core functionality and components to accelerate project creation and enhance scalability. It replaces hand-rolled base classes with highly opinionated, extensible, and Octane-safe abstractions.
This foundation is built for developers creating modular monoliths who require strong conventions, structured extensibility, and built-in observability out of the box.
Key Features
- Modular Extensibility: Extend
BaseModel,BaseResource,BaseService, and Repositories across module boundaries without modifying the source module. Uses structured Service Provider hooks (extendModels,extendResources, etc.). - Application Context: Collision-safe, domain-scoped state management using
ApplicationContext, optimized for long-running processes. - Consistent Response Envelopes: Enforces a uniform application response shape (
message,payload,meta,errors,exception_id) across all successful and failed endpoints usingBaseController. - Three-Layer Exception Handling: Features a predictable error system with an
ExceptionRenderer(handles framework exceptions),BaseApiException(domain exceptions), andhandleException()(fatal controller safety net with UUIDs). - Built-in Server-Timing Profiling: Gain real-time performance insights directly in browser DevTools. Auto-measure pipelines, cache hit/miss rates, and query times via
ServerTimingMiddleware. - Octane Safety: Ensures complete safety in long-running processes (Laravel Octane). Contexts are scoped and reset per request automatically.
- Race Condition Handling: Native support for Pessimistic Locking (
lockForUpdate,sharedLock) and Atomic Updates (Compare-and-Swap) viaupdateAtomicin repositories to prevent lost updates in high-concurrency scenarios. - Repository Pattern & Caching: Advanced
BaseRepositorywithFilterApplicatorandSortApplicator. Built-in tag-based read-through caching that automatically invalidates upon create, update, and delete actions. Supports proactive Parallel Cache Warming via background jobs. - Security & Authentication: Secure httpOnly Cookie-based Authentication out of the box via
AuthenticateWithCookieandSetAuthCookiemiddleware. Auth guard is config-driven — works with Sanctum, Passport, JWT, or any custom guard without modifying the package. - WebSocket & Real-time Foundation: Structured base for broadcasting events (
BaseBroadcastEvent,TenantBroadcastEvent) with built-in tenant isolation and a secure Cookie-aware Authorization Controller. - DTOs and Pipelines: Standardized
BaseDataObject(DTOs) andHasPipeline/HasEventtraits to enforce clean data transitions and logic decoupling. - Built-in AI Assistant Context (Agentic Skills): This package ships with expert-level
.mdrule files and guidelines (located inresources/boost/skills/core-foundation-best-practices). When used with an AI coding assistant, it instantly provides the AI with the exact architecture rules, patterns, and conventions of CoreFoundation, ensuring your AI writes compliant code from day one.
Installation
You can install the package via composer:
composer require rupeshstha/core-foundation
Once installed, you can publish the package configuration:
php artisan vendor:publish --tag=core-foundation php artisan vendor:publish --tag=core-foundation-server-timing
Quick Start
CoreFoundation provides interactive scaffolding to rapidly generate compliant modules.
php artisan core:make Order
This generates your Model, Factory, Repository, Service, Controller, Requests, Resource, DTO, Policy, Observer, Provider, and Feature Test – properly wired and ready to use.
Usage
For detailed usage instructions, guidelines on writing base classes, and architectural documentation, please refer to the official documentation.
Testing
composer test
Code Quality Analysis
Analyze your project's PHP method complexity and code smell scores using the built-in analyzer:
php artisan core:analyse
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email contact@rupeshstha.com.np instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.