# Local Dev Setup

## Prerequisites

- PHP 8.2+
- Composer
- Node.js 18+ / npm
- MySQL or MariaDB
- Laravel CLI (optional): `composer global require laravel/installer`

## 1. Create the project

```bash
composer create-project laravel/laravel nirmanos
cd nirmanos
```

## 2. Install Livewire + Alpine + Tailwind

```bash
composer require livewire/livewire
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
```

Configure `tailwind.config.js` content paths to include
`./resources/views/**/*.blade.php` and `./app/Livewire/**/*.php`.

## 3. Database

```bash
cp .env.example .env
php artisan key:generate
```

Edit `.env`:

```
DB_CONNECTION=mysql
DB_DATABASE=nirmanos
DB_USERNAME=root
DB_PASSWORD=
```

Create the database, then:

```bash
php artisan migrate
```

## 4. Build out the model layer

Migrations and models should follow `DATABASE_SCHEMA.md` exactly — table
names, column types, and the tenant_id scoping on every tenant-owned table.
Start in this order (respects foreign key dependencies):

1. `tenants`
2. `users` (add `tenant_id`, `role` to the default Laravel users migration)
3. `projects`
4. `project_user` (pivot)
5. `inventory_items`
6. `inventory_transactions`
7. `cash_receipts`
8. `expenses`

## 5. Tenant scoping

Build the `BelongsToTenant` trait + global scope described in
`ARCHITECTURE.md` before writing any Livewire components that touch
tenant data. Every tenant-owned model uses it. This is the one piece of
infrastructure worth getting right before feature work starts.

## 6. Auth

Use Laravel Breeze or Fortify as a starting point for the auth scaffolding,
then customize the username resolution to accept phone or email, and
remove public registration (accounts are super-admin-created only, per
`ARCHITECTURE.md`).

## 7. First vertical slice to build

Don't build all tables/screens before testing anything end-to-end. Build
one full vertical slice first: tenant + project creation + one inventory
transaction, working end-to-end with tenant scoping enforced. Confirms the
architecture works before you commit to it across 6 more tables.

## 8. PWA

Add `manifest.json` and a basic service worker (cache static assets, no
offline write queue) once the core app works. Don't do this first —
it adds nothing until there's something to install.
