# Decent Billing ERP - Server Installation (S0.1)

This ZIP is the **source snapshot** of the S0.1 Infrastructure Spine. It is
not a pre-built binary; it must be composed on the target server using
Composer and npm so that the vendor libraries match the server's PHP
version.

> **Important scope note**
>
> S0.1 delivers the infrastructure spine only: config, logging, error
> handling, security headers, Bootstrap 5.3 Decent DS UI foundation, base
> layouts, style guide, admin shell preview, and health probe.
>
> **There is no `/login` and no default user in S0.1.** Authentication,
> users, roles, and permissions are the deliverable of **S0.2 - Identity
> & Access**, which begins after you approve the S0.1 completion report.
>
> The URLs available today are:
>
> - `https://billing.decentonline.com/`          -> Marketing landing page
> - `https://billing.decentonline.com/styleguide` -> Decent DS reference
> - `https://billing.decentonline.com/shell`      -> Admin shell preview
> - `https://billing.decentonline.com/api/v1/ready` -> Readiness probe (JSON)

---

## 1. Prerequisites on the server

- PHP 8.2+ with extensions: `pdo_mysql`, `mbstring`, `intl`, `bcmath`,
  `openssl`, `curl`, `zip`, `fileinfo`, `gd` (or `imagick`)
- Composer 2.6+
- Node.js 20+ and npm 10+
- MySQL 8.0+ or MariaDB 10.6+

---

## 2. Database (already provisioned)

The database, user, and password given to us:

- Database: `decenton_amit_billing`
- User:     `decenton_amit_billing1`
- Password: `Amit @3197`
- Host:     `127.0.0.1`
- Charset:  `utf8mb4`, collation `utf8mb4_0900_ai_ci` (or
  `utf8mb4_unicode_ci` on MariaDB)

These values are already filled in `.env.production`.

---

## 3. Deploy steps

Upload the ZIP contents to your web root, then:

```bash
# 1. From the project root
cp .env.production .env

# 2. Install PHP dependencies
composer install --no-dev --optimize-autoloader

# 3. Generate the application key
php artisan key:generate

# 4. Ensure writable paths
mkdir -p storage/framework/{cache/data,sessions,testing,views} storage/app/private storage/logs bootstrap/cache
chmod -R ug+rwX storage bootstrap/cache

# 5. Build the frontend
npm ci
npm run build

# 6. Run migrations + seed default UI settings
php artisan migrate --force
php artisan db:seed --force

# 7. Cache configuration for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
```

Point your web server (Apache or nginx) at `public/` as the document root
so that `public/index.php` is the front controller. The bundled
`public/.htaccess` handles rewrites for Apache. For nginx use:

```nginx
server {
    listen 443 ssl http2;
    server_name billing.decentonline.com;
    root /var/www/decent-billing-erp/public;
    index index.php;

    ssl_certificate     /etc/letsencrypt/live/billing.decentonline.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/billing.decentonline.com/privkey.pem;

    location / { try_files $uri $uri/ /index.php?$query_string; }

    location ~ \.php$ {
        include        fastcgi_params;
        fastcgi_pass   unix:/run/php/php8.2-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  HTTPS on;
    }

    location ~ /\.(?!well-known).* { deny all; }
}
```

---

## 4. Verifying the install

Visit each of the following in a browser:

1. `https://billing.decentonline.com/`
   -> Marketing landing page renders the product identity.

2. `https://billing.decentonline.com/styleguide`
   -> Decent DS reference (colors, typography, buttons, forms, tables,
   badges, alerts, skeletons, empty state).

3. `https://billing.decentonline.com/shell`
   -> Admin shell preview (sidebar + topbar + content grid + stat cards).

4. `https://billing.decentonline.com/api/v1/ready`
   -> JSON envelope with `ok: true`, checks for PHP version, extensions,
   writable paths, and database connectivity.

If `/api/v1/ready` returns `ok: false`, check the `checks[*]` object for
the failing dependency (extension, writable path, or database).

---

## 5. What comes next

The next sub-sprint you have to approve is **S0.2 - Identity & Access**.
That is the sub-sprint that introduces:

- Users, Roles, Permissions tables
- Login screen at `/login`, forgot / reset password flows
- Session hardening (rotate on privilege change, remote revoke)
- Two-factor authentication (TOTP + WhatsApp OTP)
- RBAC + ABAC policies at controller boundaries
- Audit log + activity log
- First admin bootstrap console command (`php artisan decent:admin:create`)
- Full unit + feature tests + completion report

**Do not expect a `/login` endpoint or admin credentials in this build.**
That will land after your explicit approval to start S0.2.

---

## 6. Support

Product: **Decent Billing ERP**
Vendor: Decent Online
Support: support@decentonline.com
Domain: billing.decentonline.com
