# Welcome to Core Foundation

CoreFoundation is an enterprise-grade architectural framework for building robust, scalable, and modular APIs on **Laravel 11+** and **PHP 8.3+**.

It provides the "missing middle" between a raw Laravel installation and a complex enterprise application. By enforcing high-discipline conventions and providing powerful base abstractions, CoreFoundation eliminates structural "bikeshedding" and lets your team focus entirely on delivering unique business value.

> **Architecture as Code:** CoreFoundation isn't just a library; it's an opinionated structural foundation that ensures your API remains maintainable whether it has 10 endpoints or 1,000.

***

## Why CoreFoundation?

While Laravel is the world's best web framework, large-scale APIs often suffer from inconsistent response shapes, fragmented business logic, and "leaky" module boundaries. CoreFoundation solves these problems through:

* **Modular Monolith Native**: Designed specifically for applications that need to scale vertically within a single codebase. It provides unique mechanisms for modules to extend core models, resources, and services without ever touching the source module's code.
* **Predictable Reliability**: Every endpoint follows the same strict JSON envelope. Every error uses the same 3-layer exception system. Every repository uses the same SQL-injection safe filtering.
* **Octane & High Performance**: Built from the ground up to be safe for long-lived processes like **Laravel Octane**. It includes built-in observability via W3C Server-Timing to help you identify bottlenecks in real-time.
* **AI-First Developer Experience**: The first Laravel framework to ship with built-in **Agentic Skills**, providing AI coding assistants with the context they need to write perfect, compliant code automatically.

***

## Core Principles

The design of CoreFoundation is guided by four foundational pillars:

### 1. Consistency Over Configuration

We believe there should be one "right way" to build a feature. By standardizing the response envelope, the service execution flow, and the repository pattern, we eliminate decision fatigue and make it effortless for developers to move between different parts of a large system.

### 2. Deny by Default (Security First)

Security is baked into the foundation. Policies deny access unless explicitly granted. Repositories ignore filters unless columns are explicitly whitelisted. Controllers never expose raw Eloquent models. This "secure baseline" protects your data from accidental exposure.

### 3. Isolation & Encapsulation

In a modular monolith, module boundaries are sacred. CoreFoundation provides the tools to maintain this isolation while still allowing for rich extensibility. Modules communicate through events and structured service provider hooks, preventing "spaghetti" dependencies.

### 4. Zero State Leakage

Every component is **Octane-safe**. We use scoped bindings and automated reset listeners to ensure that state never bleeds between requests. This makes your application ready for the highest levels of performance without the usual pitfalls of long-running PHP processes.

***

## Architecture at a Glance

CoreFoundation organizes your application into clear, specialized layers:

1. **The Controller Layer**: Responsible only for request routing and response delivery. It utilizes standardized helpers to ensure a uniform API shape.
2. **The Service Layer**: The "brain" of your application. Orchestrates business logic using Pipelines (for intercepting flow) and Events (for fire-and-forget side effects).
3. **The Repository Layer**: The dedicated data access layer. Handles complex filtering, sorting, and implements a sophisticated tag-based caching strategy.
4. **The Entity Layer**: Strict base models that support modular extensibility for relations, casts, and scopes.
5. **The DTO & Transformer Layer**: Ensures that data entering and leaving your system is typed, validated, and consistently structured.

***

## Getting Started

If you're new to CoreFoundation, we recommend following this path:

1. [**Installation**](/installation.md): Add the package and publish your configuration.
2. [**Scaffolding**](/apm-and-devtools/scaffolding.md): Use `php artisan core:make` to generate your first compliant module.
3. [**Modular Extensibility**](/architecture-and-concepts/modular-extensibility.md): Learn how to grow your application without breaking module isolation.
4. [**Standardized Responses**](/http-and-api-layer/responses.md): Understand the strict envelope that your clients will love.

***

## Ecosystem Integration

CoreFoundation plays beautifully with the modern Laravel ecosystem:

* **Laravel Octane**: Fully supported with scoped state management.
* **Laravel Pennant**: First-class support for feature flags.
* **Laravel Passport / Sanctum**: Integrated with our authentication exception handlers.
* **Pest / PHPUnit**: Ships with a suite of custom assertions for API testing.

***

*CoreFoundation is maintained by the DubDubCo team. For architectural support or feedback, please visit our* [*support page*](/support.md)*.*


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://core-foundation-doc.rupeshstha.com.np/welcome-to-core-foundation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
