# BizNovia

BizNovia is a modular Business Operating System SaaS built with Laravel API backend and Vue frontend.

## Stack

- Backend: Laravel 12, Sanctum token auth, MySQL, modular `app/Modules` structure
- Frontend: Vue 3, Vite, Pinia, Vue Router
- API style: versioned JSON API under `/api/v1`
- Tenant model: each authenticated tenant request uses `X-Company-ID`

## Project Structure

```text
backend/
  app/Modules/
    Core
    Tenant
    Subscription
    SuperAdmin
    Invoice
    POS
    Inventory
    Accounting
    CRM
    Reports
    Notification
    CustomerPortal

frontend/
  src/modules/
    auth
    dashboard
    invoice
    pos
    inventory
    accounting
    crm
    reports
    notification
    settings
    customerPortal

docs/
  API_REFERENCE.md
```

## Local Setup

Backend:

```bash
cd backend
composer install
copy .env.example .env
php artisan key:generate
php artisan migrate --seed
php artisan serve --host=127.0.0.1 --port=8000
```

Frontend:

```bash
cd frontend
npm install
copy .env.example .env
npm run dev -- --port 5174
```

Open:

```text
Frontend: http://127.0.0.1:5174
Backend:  http://127.0.0.1:8000
API:      http://127.0.0.1:8000/api/v1
```

## Important Environment Values

Backend `.env`:

```env
APP_URL=http://127.0.0.1:8000
FRONTEND_URL=http://127.0.0.1:5174
CORS_ALLOWED_ORIGINS=http://localhost:5173,http://127.0.0.1:5173,http://localhost:5174,http://127.0.0.1:5174
SANCTUM_STATEFUL_DOMAINS=localhost:5173,127.0.0.1:5173,localhost:5174,127.0.0.1:5174
DB_CONNECTION=mysql
DB_DATABASE=biznovia
```

Frontend `.env`:

```env
VITE_API_BASE_URL=http://127.0.0.1:8000/api/v1
```

Seeded super admin values are controlled by:

```env
BIZNOVIA_SUPER_ADMIN_EMAIL=admin@biznovia.test
BIZNOVIA_SUPER_ADMIN_PASSWORD=password
```

## Testing

Backend full test suite:

```bash
cd backend
php artisan test
```

Frontend production build/type check:

```bash
cd frontend
npm run build
```

Health check:

```bash
curl http://127.0.0.1:8000/api/v1/health
```

Expected:

```json
{
  "status": "ok",
  "service": "BizNovia"
}
```

## API Usage for Mobile Apps

Mobile apps should use Sanctum bearer tokens and store tenant and customer portal tokens separately.

Tenant app flow:

1. `POST /api/v1/auth/login`
2. Store `data.token`
3. `GET /api/v1/companies`
4. Select a company and store `company.id`
5. Send `Authorization: Bearer <token>` and `X-Company-ID: <company_id>` on module API calls
6. Use `GET /api/v1/tenant/current` to hydrate active plan, features, and permissions

Customer portal app flow:

1. `POST /api/v1/customer-portal/auth/login`
2. Store customer portal token separately
3. Use `/api/v1/customer-portal/*` endpoints without `X-Company-ID`

Full endpoint list: [docs/API_REFERENCE.md](docs/API_REFERENCE.md)

## Current Verification Baseline

Latest verified baseline:

- Backend: `129` tests passed, `624` assertions
- Frontend: `npm run build` passed
- API route list: `103` `/api/v1` routes

## Deployment Notes

- Set `APP_ENV=production` and `APP_DEBUG=false`.
- Configure real mail transport for password reset and email verification.
- Run `php artisan migrate --force` during deployment.
- Run `php artisan config:cache`, `route:cache`, and `view:cache` after env setup.
- Build frontend with `npm run build` and serve `frontend/dist` from the chosen web server/CDN.
- Ensure production frontend origin is included in `CORS_ALLOWED_ORIGINS`.
