# Phase 0 — Scaffolding

> **Goal:** Create all directories and register all modules with the framework.
> **No business logic.** Every file is a stub or empty skeleton.
> **Done-when:** `php artisan module:list` shows CoreApp and CrmApp enabled; Vite build exits 0.

---

## Steps

### 1. Directory Structure
Create these directories (see [phase0_plan.md](../phase0_plan.md) for full tree):
```
CoreApp/app/{Providers,Services,Models,Traits,Contracts,Exceptions}/
CoreApp/database/{migrations,seeders}/
CoreApp/routes/
CrmApp/{Lead,Deal,Pipeline,Contact,Activity,Proposal}/app/
CrmApp/{Lead,Deal,Pipeline,Contact,Activity,Proposal}/database/migrations/
CrmApp/{Lead,Deal,Pipeline,Contact,Activity,Proposal}/routes/
CrmApp/{Lead,Deal}/resources/assets/js/pages/
```

### 2. `app/composer.json` — PSR-4 + merge-plugin
```json
"autoload": {
  "psr-4": {
    "CoreApp\\": "CoreApp/app/",
    "CrmApp\\Lead\\": "CrmApp/Lead/app/",
    "CrmApp\\Deal\\": "CrmApp/Deal/app/",
    "CrmApp\\Pipeline\\": "CrmApp/Pipeline/app/",
    "CrmApp\\Contact\\": "CrmApp/Contact/app/",
    "CrmApp\\Activity\\": "CrmApp/Activity/app/",
    "CrmApp\\Proposal\\": "CrmApp/Proposal/app/"
  }
}
```
```json
"extra": {
  "merge-plugin": {
    "include": ["CoreApp/composer.json", "CrmApp/composer.json", "...existing..."]
  }
}
```
Run: `composer dump-autoload` inside container.

### 3. `modules_statuses.json`
```json
"CoreApp": true,
"CrmApp": true
```

### 4. `resources/js/app.tsx` — CrmApp Glob
```ts
const crmPages = import.meta.glob(
  '../../../CrmApp/**/resources/assets/js/pages/**/*.tsx',
  { eager: false }
);
// merge into existing resolver
```

### 5. Service Provider Stub
```php
// CoreApp/app/Providers/CoreAppServiceProvider.php
class CoreAppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        // Phase 1: bind engines here
    }
    public function boot(): void
    {
        $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
    }
}
```

### 6. `CoreApp/module.json`
```json
{
  "name": "CoreApp",
  "alias": "coreapp",
  "description": "Headless CRM engine layer",
  "providers": ["CoreApp\\Providers\\CoreAppServiceProvider"],
  "files": [], "requires": []
}
```

### 7. `CrmApp/module.json`
```json
{
  "name": "CrmApp",
  "alias": "crmapp",
  "description": "CRM application modules",
  "providers": [],
  "files": [], "requires": ["CoreApp"]
}
```

---

## Done-When Checklist

- [ ] `php artisan module:list` shows `CoreApp` ✓ and `CrmApp` ✓ (both enabled)
- [ ] `composer dump-autoload` exits 0, no PSR-4 conflicts
- [ ] `php artisan migrate --path=CoreApp/database/migrations --pretend` prints 14 stubs
- [ ] `npm run build` exits 0 (Vite finds CrmApp glob)
- [ ] `php artisan config:clear && php artisan route:list` — no PHP errors
