# mbiz — Complete Operator Guide

**mbiz** (Media Biz) is a member-funded AI-assisted media production platform.
Live site: https://mbiz.1bz.biz

---

## 1. Business model

mbiz is the **escrow agent + marketing partner** for AI-assisted media projects.

### Revenue streams
1. **Annual membership fee:** $2,000/year per creator. Pays for AI rendering credits, software access, marketing by 1BZ network, and the right to launch projects.
2. **Platform fee:** 10% flat — deducted from every pledge and every revenue event (YouTube / OTT / theater royalties). Non-negotiable, baked into the code.
3. **Future:** DZIT on-chain settlement, OTT distribution partnership fees.

### Money flow
```
Backer pledges $X
    → 10% ($X*0.10) → mbiz platform fee
    → 90% ($X*0.90) → project escrow (held by mbiz)
Owner accepts a deliverable (artistic work for a role)
    → role_percent of escrow → credited to artist's mbiz wallet
Revenue arrives from YouTube / OTT
    → 10% platform fee, 90% split per declared revenue shares
Artist withdraws from wallet → admin processes payout
```

### Content rule (IMPORTANT — no video uploads)
**Every video on mbiz is a YouTube embed.** We do NOT host mp4 files.
Creators upload to their own YouTube channel (or use the dashboard's one-click YouTube publisher), then paste the YouTube URL into their project — the site embeds it via iframe. Saves server bandwidth and storage.

---

## 2. User journeys

### 2A. New creator joins mbiz
1. Visit https://mbiz.1bz.biz → click **Join**
2. Register at `/register.php` with email + password + display name
3. Email `shashi@1bz.biz` with payment proof for the $2,000 annual membership
4. Admin sets `membership_paid_until` in `/admin.php`
5. Creator now sees `/submit.php` to create their first project (1 project per calendar month limit)

### 2B. Creator launches a project
1. `/submit.php` → fill in:
   - Title, category (music_video / film / documentary / short / podcast / commercial)
   - Description + YouTube teaser ID (optional at launch)
   - Budget (USD) + release dates
   - **Budget splits**: declare how the 90% (after 10% platform fee) is divided across roles (e.g., artist 30%, musicians 20%, director 20%, editor 15%, production 15%). Must sum to 100%.
2. Each role declared becomes an **open role** members can apply to.
3. Creator sets project status to `funding` on the project page → pledges accepted.

### 2C. Member pledges to a project
1. `/browse.php` → open a project
2. Click **Pledge** → enter USD amount (min $10) → redirected to Stripe Checkout
3. On payment success, webhook records it:
   - 100% in `mbiz_escrow_ledger` as `pledge_in`
   - 10% out as `platform_fee`
   - Contribution status = `held` (funds locked in escrow)
   - Project `funded_usd` recomputed
4. Owner gets a `pledge_received` notification.

### 2D. Member applies for a role
1. Open project page → Roles table shows open roles with budget %
2. Click **Apply** → submit message + portfolio URL
3. Owner reviews in "Applications to review" section → Accept/Reject
4. On accept: role assigned, other pending applications auto-rejected, applicant notified

### 2E. Filled member submits deliverable
1. Project page shows "Your role: X" with a submit form
2. Submit title + URL (YouTube / SoundCloud / Drive / any) + description
3. All deliverables public on project page (transparency — everyone sees every contribution)

### 2F. Owner reviews deliverable
1. Project page "Deliverables" section → inline Accept / Request revision
2. **On accept** (auto-atomic):
   - Payout = `funded_usd * 0.9 * role_percent/100` → credited to artist's wallet
   - Entry in `mbiz_wallet_ledger` as `credit_role_payout`
   - Entry in `mbiz_escrow_ledger` as `role_payout` (negative amount)
   - Role status → `completed`
   - Artist notified
3. On revision: artist notified with review note

### 2G. Artist withdraws earnings
1. `/dashboard.php` → Wallet section shows balance + ledger
2. Enter amount (min $10) → submit
3. Admin processes in `/admin.php` (for now: manual bank/UPI/crypto; future: Stripe Connect payout)

---

## 3. Architecture

### Stack
- **PHP 8.1** on Apache/CWP (VPS: 144.91.114.245, port 28, root@1bz.biz)
- **MySQL / MariaDB 10.5** — DB `crn0s&hahi`, 13 tables (prefixed `mbiz_`)
- **Stripe Checkout** — redirect mode, no pk_live needed on frontend
- **Telegram Bot API** — Python long-polling bot (`@onebizmusic_bot`)
- **Playwright** — YouTube publishing automation (no API keys)
- **YouTube iframe** — all video rendering, no mp4 uploads

### File layout
```
C:\nodesrunning\mbiz-site\         (local)
├─ index.html                       Landing page
├─ help.md                          This file
├─ register.php login.php logout.php
├─ dashboard.php                    Member home: projects, subs, contribs, wallet
├─ submit.php                       New project form (1/month quota)
├─ project.php                      Detail page: teaser, funding, roles, applications, deliverables, updates
├─ browse.php                       Public listing
├─ contribute.php                   Redirects to Stripe Checkout
├─ pledge_success.php               Post-Stripe success page
├─ subscribe.php                    Follow a project
├─ apply.php                        Apply to an open role
├─ review_application.php           Owner accept/reject
├─ deliverable_submit.php           Filled member submits work
├─ deliverable_review.php           Owner accept/revise → auto-pays wallet
├─ post_update.php                  Owner posts update → notifies subscribers
├─ project_status.php               Owner moves status
├─ withdraw.php                     Member requests withdrawal
├─ admin.php                        Admin panel
├─ inc/
│  ├─ config.php                    Loads /home/1bzbiz/.mbiz_env
│  ├─ db.php                        PDO singleton
│  ├─ auth.php                      Sessions + CSRF + helpers
│  ├─ layout.php                    Nav/head/footer templates
│  └─ stripe.php                    Stripe Checkout + webhook verification
├─ api/
│  ├─ publish.php                   POST YouTube URL → showcase.json
│  ├─ projects.php                  GET browse/detail + POST subscribe
│  └─ stripe_webhook.php            Handles checkout.session.completed
├─ sql/
│  ├─ schema.sql                    Phase 1 tables
│  └─ schema_phase2.sql             Phase 2 (roles, escrow, wallet)
├─ bot/
│  └─ mbiz_bot.py                   Telegram bot
├─ css/mbiz.css
├─ js/showcase.js
├─ logos/*.png
├─ media/*_thumb.jpg                (only thumbnails; no mp4 files)
└─ deploy.ps1                       SCP to VPS
```

### Database tables (13)
**Phase 1 (member + projects):**
- `mbiz_members` — email, password_hash, api_key, membership_paid_until, is_admin, telegram_user_id
- `mbiz_projects` — title, slug, category, youtube_teaser_id, youtube_final_id, budget_usd, funded_usd, platform_fee_pct (10), status
- `mbiz_budget_splits` — legacy split table (now mirrored into `mbiz_project_roles`)
- `mbiz_contributions` — backer_id, amount_usd, escrow_status (pledged/held/released/refunded), payment_ref (Stripe session ID)
- `mbiz_subscriptions` — project_id × member_id
- `mbiz_updates` — project timeline entries
- `mbiz_notifications` — per-member queue (read_at, telegram_sent_at)

**Phase 2 (escrow + roles):**
- `mbiz_project_roles` — role_name, percent_budget, percent_revenue, filled_by, status (open/applied/filled/completed)
- `mbiz_role_applications` — member_id, message, portfolio_url, status (pending/accepted/rejected)
- `mbiz_deliverables` — role_id, title, url, description, status (submitted/revision_requested/accepted/rejected), review_note
- `mbiz_escrow_ledger` — append-only: pledge_in, platform_fee, role_payout, revenue_in, revenue_split, refund
- `mbiz_wallet_ledger` — append-only per member: credit_role_payout, credit_revenue, debit_withdrawal, etc.
- `mbiz_withdrawals` — member_id, amount_usd, status (pending/processing/completed/failed), stripe_payout_id

---

## 4. REST API

### Public (no auth)
| Endpoint | Method | Returns |
|---|---|---|
| `/api/projects.php` | GET | All non-draft projects, newest first |
| `/api/projects.php?slug={slug}` | GET | Single project + splits |

### Member (requires `X-Mbiz-ApiKey` header — key from `mbiz_members.api_key`)
| Endpoint | Method | Body | Purpose |
|---|---|---|---|
| `/api/projects.php` | POST | `{"action":"subscribe","slug":"..."}` | Follow a project |

### Admin (requires `X-Mbiz-Key: mbiz-admin-demo` for now)
| Endpoint | Method | Body | Purpose |
|---|---|---|---|
| `/api/publish.php` | POST | `{title, youtube_url, duration_sec, credits}` | Add entry to showcase |

### Webhook (Stripe)
| Endpoint | Event | Action |
|---|---|---|
| `/api/stripe_webhook.php` | `checkout.session.completed` | Records pledge, takes 10% fee, notifies owner |

---

## 5. Telegram bot (@onebizmusic_bot)

### Commands
| Command | Effect |
|---|---|
| `/start` | Welcome + command list |
| `/browse` | List up to 10 active projects |
| `/project <slug>` | Show project details + budget + splits |
| `/subscribe <slug>` | Link to website subscribe |
| `/wallet` | Link to dashboard |
| `/help` | Command list |

### Run the bot
```
python C:\nodesrunning\mbiz-site\bot\mbiz_bot.py
```
Token is read from `MBIZ_BOT_TOKEN` in `C:\nodesrunning\seelab\.env`.

---

## 6. Deploy

```
powershell -File C:\nodesrunning\mbiz-site\deploy.ps1
```

Uses `~/.ssh/biznode_deploy` (port 28, root@1bz.biz). Uploads HTML, CSS, JS, PHP, logos, thumbnail jpgs. **Does NOT upload mp4 files** (videos live on YouTube).

Fixes ownership to `1bzbiz:1bzbiz` and sets `a+r` on api/*.php.

---

## 7. VPS configuration

### Secrets (VPS: `/home/1bzbiz/.mbiz_env`, chmod 640)
```
DB_HOST=localhost
DB_NAME=crn0s&hahi
DB_USER=JanakTanTan32!
DB_PASS=LjgqXM*W*CCLBbC9Dp
STRIPE_SECRET_KEY=sk_live_51S2pnk...
STRIPE_WEBHOOK_SECRET=whsec_vnN0aauxP4jEqdx8OzkiVV2K3fLdTfGI
```

### Connect to VPS
```
ssh -p 28 -i ~/.ssh/biznode_deploy root@1bz.biz
```

### Run schema (one-time)
```bash
scp -P 28 -i ~/.ssh/biznode_deploy mbiz-site/sql/schema.sql root@1bz.biz:/tmp/
scp -P 28 -i ~/.ssh/biznode_deploy mbiz-site/sql/schema_phase2.sql root@1bz.biz:/tmp/
ssh -p 28 -i ~/.ssh/biznode_deploy root@1bz.biz \
  "mysql -u 'JanakTanTan32!' -p'LjgqXM*W*CCLBbC9Dp' 'crn0s&hahi' < /tmp/schema.sql && \
   mysql -u 'JanakTanTan32!' -p'LjgqXM*W*CCLBbC9Dp' 'crn0s&hahi' < /tmp/schema_phase2.sql"
```

### Promote an admin
```
ssh -p 28 -i ~/.ssh/biznode_deploy root@1bz.biz \
  "mysql -u 'JanakTanTan32!' -p'LjgqXM*W*CCLBbC9Dp' 'crn0s&hahi' -e \
   \"UPDATE mbiz_members SET is_admin=1, membership_paid_until='2027-04-15' WHERE email='shashi@1bz.biz'\""
```

---

## 8. Admin operations (`/admin.php`)

Only visible to `is_admin=1` members.

### Members table
- Set `membership_paid_until` per member (activates posting rights).

### Contributions table
- Move escrow state: pledged → held → released → refunded.
- `held` / `released` count toward `funded_usd`; `refunded` reverts.

### Withdrawals (new — pending processing)
Manual for now: admin sees pending `mbiz_withdrawals` rows, pays externally (UPI / bank / crypto), marks `completed`. Wallet debit already happened when the request was made.

---

## 9. YouTube publishing from SeeLab dashboard

Use `http://localhost:7105/` (the local SeeLab dashboard, not mbiz).

1. Every project card with a rendered video shows **▶ Publish to YouTube** (red button)
2. Click → confirm → Playwright opens Chrome, logs into YouTube Studio (using saved profile at `C:\nodesrunning\seelab\youtube\chrome_profile\`), auto-fills title/description/tags/thumbnail/privacy, uploads, captures the URL
3. Returns `https://youtu.be/<id>` — store that in the mbiz project's `youtube_teaser_id` or `youtube_final_id`

**First-time setup:**
```
python C:\nodesrunning\seelab\youtube\yt_playwright.py --login
```

---

## 10. Add a video to mbiz showcase

Only YouTube URLs. Two ways:

**A) Via admin UI on SeeLab dashboard** (`http://localhost:7105/mbiz`):
- Add showcase item with the YouTube URL → writes to `data/showcase.json`
- Deploy the JSON via the dashboard's Deploy button

**B) Via API:**
```bash
curl -X POST https://mbiz.1bz.biz/api/publish.php \
  -H "X-Mbiz-Key: mbiz-admin-demo" \
  -H "Content-Type: application/json" \
  -d '{"title":"Pulakeshi","subtitle":"Music Video","project":"pulakeshi-ND","youtube_url":"https://www.youtube.com/watch?v=L5r_z54D-GI","duration_sec":353}'
```

The showcase grid on the homepage auto-loads from `/data/showcase.json`.

---

## 11. Troubleshooting

| Problem | Fix |
|---|---|
| White page on mbiz.1bz.biz | CSS/JS path issue. All asset paths are root-relative (`/css/`, `/logos/`) — not `/mbiz/...` |
| HTTPS shows blog page | Subdomain missing :443 vhost. Add Let's Encrypt cert via CWP for `mbiz.1bz.biz` |
| Stripe webhook 400 signature invalid | Webhook secret doesn't match Stripe. Get new `whsec_...` from Stripe dashboard, update `/home/1bzbiz/.mbiz_env` |
| Bot not responding | Check `MBIZ_BOT_TOKEN` in `C:\nodesrunning\seelab\.env`; run `python mbiz-site/bot/mbiz_bot.py` |
| `funded_usd` out of sync | Run: `UPDATE mbiz_projects p SET funded_usd = (SELECT COALESCE(SUM(amount_usd),0) FROM mbiz_contributions WHERE project_id=p.id AND escrow_status IN ('held','released'))` |
| "Not logged in" on YouTube upload | Re-run `yt_playwright.py --login` |
| YouTube upload missing thumbnail | Playwright selectors for YouTube Studio may have drifted — see `yt_playwright.py` |

---

## 12. Branding (mandatory on all deliverables)
- **Produced by 1BZ DZIT DAO STUDIO**
- **Marketed by 1BZ network**
- **Copyrights, lyrics and music rights in favour of Shashikanth Ramamurthy**
- **Website:** https://mbiz.1bz.biz
- **Contact:** shashi@1bz.biz

---

## 13. Phase 3 roadmap
- Stripe Connect: direct payouts to artist bank accounts (replace manual withdrawals)
- DZIT on-chain escrow smart contract
- Telegram notification pusher (cron reads `mbiz_notifications`, sends via bot)
- YouTube OAuth for official channel API (if Playwright drifts too much)
- Revenue ingestion (YouTube Analytics API → `mbiz_escrow_ledger.revenue_in` → auto-split)
- Milestone-based releases (vs. per-deliverable)
- Member Telegram-account linking (verify code + store `telegram_user_id`)
