# Development Guide

Local development setup for Venue Events Manager.

## Prerequisites

- PHP 8.2+ with required extensions
- Composer 2.x
- Node.js 18+ (optional, for asset tooling)
- SQLite (default) or local MySQL

## Initial Setup

```bash
git clone <repository> venue-events-manager
cd venue-events-manager
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate --seed
```

The `composer setup` script runs install, env copy, key generation, migrate, and npm build.

## Default Credentials

After seeding:

- Email: `admin@venue.local`
- Password: `password`

Change immediately in development if the app is network-accessible.

## Environment

Default `.env.example` uses SQLite for zero-config local setup:

```env
DB_CONNECTION=sqlite
SESSION_DRIVER=database
QUEUE_CONNECTION=database
CACHE_STORE=database
```

For MySQL locally, uncomment DB_* variables and set `DB_CONNECTION=mysql`.

## Running the Application

```bash
php artisan serve
# http://127.0.0.1:8000
```

## Code Organization

| Layer | Location |
|-------|----------|
| Controllers | `app/Http/Controllers/` |
| Form requests | `app/Http/Requests/` |
| Policies | `app/Policies/` |
| Domain services | `app/Services/` |
| Models | `app/Models/` |
| Views | `resources/views/` |
| Routes | `routes/web.php` |
| Migrations | `database/migrations/` |
| Tests | `tests/` |

Business logic belongs in **services**, not controllers or Blade views.

## Key Conventions

- Permissions: `{resource}.{action}` slugs, enforced in routes and policies
- Money: use `PricingService` and `Money` support class
- Document numbers: `DocumentNumberService` with row locking
- Settings: read via `SettingsService`, never hardcode property defaults in views
- Attachments: stored under `storage/app/attachments`, streamed via controller

## Testing

```bash
composer test
# or
php artisan test
```

See [TESTING.md](TESTING.md).

## Building cPanel Release

```bash
composer install --no-dev --optimize-autoloader
php scripts/export_install_sql.php --force
php scripts/build_cpanel_release.php
```

Output: `dist/venue-events-manager-cpanel.zip`

## Useful Artisan Commands

```bash
php artisan migrate:fresh --seed   # reset database
php artisan route:list
php artisan config:clear
php artisan cache:clear
```

## Installer Development

Core logic: `app/Install/Installer.php`  
Web UI: `public/install/index.php`

Tests: `tests/Feature/InstallerTest.php`

Regenerate SQL when migrations change:

```bash
php scripts/export_install_sql.php --force
```
