# Deploying NOAH Logistics (fleet-api) to fleetcontroll.com

This backend is a git repository. Deploy by cloning it to the server and
pulling for future updates — no zip files needed after the first setup.

## 1. Requirements on the server

- PHP 8.3+ with extensions: `mbstring`, `pdo_mysql`, `openssl`, `tokenizer`,
  `xml`, `ctype`, `json`, `bcmath`, `fileinfo`, `curl`, `gd`
- Composer 2
- MySQL 8+ (a database + user already created)
- SSH access (confirmed available)
- A web server (Apache/nginx) able to point its document root at this
  project's `public/` folder — **not** the project root
- SSL certificate for `fleetcontroll.com` (Let's Encrypt via the hosting
  panel is fine)

## 2. Clone the repo

```bash
git clone <repo-url> fleet-api
cd fleet-api
```

(If the repo isn't pushed anywhere yet, we'll hand over a tarball of the
`.git` folder instead — ask if `<repo-url>` isn't available.)

## 3. Install dependencies

```bash
composer install --no-dev --optimize-autoloader
```

## 4. Create `.env`

Copy `.env.production` (included in this handoff, sent alongside this file)
to `.env`, then fill in the blanks (DB credentials, mail, etc. — see the
comments in that file for exactly what's needed and where to get each
value).

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

## 5. Firebase service account file

Push notifications need a Firebase service account JSON file. This is
**not** in git (secrets aren't committed). We'll send it to you separately
(secure channel, not email/chat in plaintext).

Place it at:

```
storage/app/firebase-service-account.json
```

Then in `.env`:

```
FIREBASE_CREDENTIALS=/full/path/to/fleet-api/storage/app/firebase-service-account.json
```

## 6. Database

```bash
php artisan migrate
```

This runs every migration from scratch, including the newest ones
(trip destination/notes, AI damage-detection columns). No manual SQL
needed — that was only a workaround on the old server, which had no SSH.

Then create the first admin user (either via `php artisan tinker` or ask us
for a seed command — do **not** copy user data from the old server, this
should be a clean production database).

## 7. Storage symlink + permissions

```bash
php artisan storage:link
chmod -R 775 storage bootstrap/cache
```

## 8. Web server document root

Point the vhost's document root at:

```
/path/to/fleet-api/public
```

Standard Laravel Apache `.htaccess` (already in `public/`) or nginx
`try_files` rewrite to `index.php` — whichever the panel/stack expects.

## 9. SSL

Issue a certificate for `fleetcontroll.com` (and `www.` if used) and force
HTTPS. The admin panel is a PWA and push notifications require HTTPS to
work at all.

## 10. Queue worker (if not already running)

Check `config/queue.php` — if `QUEUE_CONNECTION` is not `sync`, a worker
process (or supervisor/cron entry) needs to run:

```bash
php artisan queue:work --daemon
```

## 11. Sanity check

- Visit `https://fleetcontroll.com/admin-panel.html` — should show the
  login screen.
- Log in, check the live map, trips, and handovers panels load without
  errors.
- Submit a test handover from the mobile app and confirm the AI
  damage-detection result shows up (proves `GEMINI_API_KEY` is wired
  correctly).

## Future updates

From then on, deploying a new version is just:

```bash
git pull
composer install --no-dev --optimize-autoloader   # only if composer.json changed
php artisan migrate                                 # only if new migrations exist
```

## Mobile app note

This repo is only the backend + admin panel. The driver mobile app
(`noah-driver`) is a separate React Native/Expo project with its own build
process (EAS Build) — it is not deployed via this server and doesn't need
anything from this handoff.
