# HouseDye Marketing Video Portal

Self-hostable **PHP / HTML / JavaScript** portal for Shopify product sync and
**in-browser product video editing**. Look and feel follows the original portal
(white chrome, outline icons, configurable highlight color). Wholesale CRM
(cart, orders, work orders, chat, analytics) has been removed.

> Application root: [`portal/`](portal/). Web root: `portal/public/`.
> Secrets and SQLite live outside the web root (`portal/config/`, `portal/data/`).

## What it does

- **Login** for superuser (config), admin, and staff
- **Dashboard** — product / project / render KPIs and recent activity
- **Users** — staff & admin accounts
- **Products** — catalog grid; synced from Shopify
- **Product Sources** — Shopify API sync + CSV import (credentials in Settings)
- **Settings** — branding, Shopify credentials, **video export presets**
- **Projects** — create / rename / delete video projects; expandable version list;
  open any version in the editor; download last rendered MP4 per version

### Video editor

- Multi-track timeline (image/video + audio)
- JPG/PNG (and catalog product images) + MP3 on the timeline
- Cross-fade transitions, auto scale & center (cover, aspect-preserving)
- PixiJS (WebGL) realtime preview + Web Audio playback
- Realtime autosave of timeline JSON
- **Save as new version**
- **Render** → PHP queues FFmpeg on the server (default **1080×1080 H.265 30fps**)
- Render range auto-detects first visual frame → last A/V content frame

## Stack

| Layer | Tech |
| --- | --- |
| API / pages | PHP 8 + SQLite (PDO) |
| Render | FFmpeg (`xfade` / overlays / `amix`) via `VideoRenderer` + `bin/render-video.php` |
| Preview | PixiJS 7 (CDN), Web Audio API |
| UI | Existing portal CSS/JS + `assets/editor.js` |

## Quick start

```bash
cd portal
php bin/install.php --seed
# Set superuser password_hash in config/config.php (php bin/hash.php)
# Ensure ffmpeg is on PATH (or set ffmpeg_path in Settings)

php -S 127.0.0.1:8080 -t public
# http://127.0.0.1:8080/
```

### Demo logins (from `--seed`)

| Role | Login | Password |
| --- | --- | --- |
| Superuser | `superadmin` | *(hash you set in config.php)* |
| Admin | `admin@housedye.example` | `admin12345` |
| Staff | `staff@housedye.example` | `staff12345` |

## Layout

```
portal/
├── public/           Web root (index.php, assets, editor)
├── app/              Controllers, Views, Shopify, VideoProjects, VideoRenderer
├── config/           config.sample.php (+ config.php)
├── migrations/       schema.sql + seed
├── data/             SQLite, uploads/, renders/ (git-ignored)
└── bin/              install.php, hash.php, render-video.php, shopify-periodic-sync.php
```

## Deploy notes

- Install `ffmpeg` (with libx265 for default H.265 exports; H.264 presets also available).
- Cron optional: `php bin/shopify-periodic-sync.php` when periodic sync is enabled in Settings.
- Keep `config/` and `data/` outside the document root (already the case).
