# Deployment and production readiness

## 1. Production architecture recommendation

- App: Next.js + Prisma + MySQL/MariaDB
- Production database: MySQL/MariaDB
- Media storage: S3 / Cloudinary / Supabase Storage
- Auth: JWT in secure cookie
- Hosting: Vercel, Docker + VPS, or Namecheap Node hosting
- Domain: HTTPS required

## 1.1 Namecheap Node deployment notes

This project includes a custom `server.js` startup file and a production-safe `npm start` command so it can be uploaded to a Node-capable hosting environment such as Namecheap cPanel. The app listens on `0.0.0.0` and reads `PORT` from the environment when provided.

## 2. Required environment variables

```env
DATABASE_URL="mysql://DATABASE_USER:DATABASE_PASSWORD@localhost:3306/DATABASE_NAME"
JWT_SECRET="generate-a-long-random-secret"
NODE_ENV="production"
PORT="3000"
NEXT_PUBLIC_APP_URL="https://your-domain.com"
```

## 3. Recommended deployment flow

### Option A: Node hosting + MySQL/MariaDB

1. Configure MySQL/MariaDB and set the environment variables.
2. Import `database/photobook.mysql.sql` into the new database.
3. Run `npm ci` followed by `npm run build`.
4. Start or restart the Node.js application.

### Option B: Docker / VPS

1. Import `database/photobook.mysql.sql` into the new MySQL/MariaDB database.
2. Build the app:
   ```bash
   npm run build
   ```
3. Start app:
   ```bash
   npm run start
   ```
4. Use Nginx/PM2 or a managed process runner.
5. Set environment variables at system or container level.

### Option C: Namecheap / Node hosting

1. Follow the detailed [Namecheap cPanel guide](./DEPLOYMENT_NAMECHEAP.md).
2. Install dependencies:
   ```bash
   npm install
   ```
3. Import `database/photobook.mysql.sql` with phpMyAdmin.
4. Build the app:
   ```bash
   npm run build
   ```
5. Start the app:
   ```bash
   npm start
   ```
6. Set `DATABASE_URL`, `JWT_SECRET`, `PORT`, `HOSTNAME=0.0.0.0`, and `NODE_ENV=production` in the hosting panel.
7. Verify the app responds at the assigned domain or subdomain.

## 4. Production security checklist

- Change default admin credentials immediately
- Use a strong JWT secret
- Keep all secrets in environment variables
- Use HTTPS only
- Enable secure cookies in production
- Restrict tenant data using tenantId checks
- Validate all form data on API routes
- Add regular backups for the database
- Add audit logs for admin actions
- Review the app before public release

## 5. Recommended next production upgrades

- MySQL backup schedule
- S3/Cloudinary uploads for gallery images
- Role management for more granular permissions
- Client-side notifications and email reminders
- PDF export service for official documents
- Analytics history and export feature
- Multi-region or multi-tenant billing logic

## 6. Production launch notes

This app is already a functional MVP and is suitable for internal validation or staged launch. Before public commercial release, focus on production database migration, security review, image storage strategy, and backup automation.
