# Debrieft — Web Designer OS

A full-stack PHP application for web designers to manage their entire client workflow:
Intake → AI Brief → Quote → Contract → Client Portal → Handover

---

## Features

- **Intake Form** – Structured client onboarding questionnaire
- **AI Brief** – One-click brief generation using Claude (Anthropic API)
- **Quote Builder** – Dynamic line-item quote with tax & discounts
- **Contract Manager** – Draft, sign (with canvas signature pad), and manage contracts
- **Client Portal** – Public URL per client — clients can view brief, accept quotes, sign contracts
- **Handover Hub** – Store credentials, files, links, and instructions for project handoff
- **CSRF protection**, password hashing, session security built-in

---

## Requirements

- PHP 8.1+
- MySQL / MariaDB 5.7+
- Apache with `mod_rewrite` enabled (or Nginx equivalent)
- `curl` PHP extension (for AI brief generation)

---

## Installation

### 1. Upload Files

Upload the entire project to your server. Recommended structure:

```
/public_html/debrieft/   ← or your subdirectory of choice
    public/              ← this is your web root
    includes/
    config.php
    schema.sql
```

**Important:** Your web server's document root for this app should point to the `public/` folder.

### 2. Create the Database

1. In cPanel → MySQL Databases, create a new database and user
2. Import `schema.sql` via phpMyAdmin or:
   ```bash
   mysql -u your_user -p your_database < schema.sql
   ```

### 3. Configure the App

Edit `config.php` (in the project root, **not** inside public/):

```php
define('DB_HOST', 'localhost');
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_db_user');
define('DB_PASS', 'your_db_password');
define('APP_URL',  'https://yourdomain.com/debrieft/public');
define('APP_KEY',  'change-this-to-a-random-32-char-string');
define('ANTHROPIC_API_KEY', 'sk-ant-...');  // optional, can set per-user
```

### 4. Set APP_URL

Make sure `APP_URL` exactly matches where `public/index.php` is accessible.

### 5. First Login

Visit `https://yourdomain.com/debrieft/public/` and register a new account.

---

## Getting an Anthropic API Key

1. Go to [console.anthropic.com](https://console.anthropic.com)
2. Create an account and generate an API key
3. Paste it in `config.php` as `ANTHROPIC_API_KEY` **or** in Settings → Profile within the app

---

## Client Portal

Each client gets a unique portal URL automatically:
```
https://yourdomain.com/debrieft/public/portal.php?token=UNIQUE_TOKEN
```

- Clients can view the project brief
- Accept or decline quotes
- Sign contracts digitally
- Access handover materials

You can optionally set a portal password per-client (add `portal_password` field to the client record via SQL or extend the UI).

---

## File Structure

```
debrieft/
├── config.php              # DB + app config (keep above web root ideally)
├── schema.sql              # Database schema
├── includes/
│   ├── bootstrap.php       # DB helpers, auth, AI function
│   └── layout.php          # HTML layout components
└── public/                 # Web root
    ├── index.php           # Redirect
    ├── login.php           # Auth
    ├── logout.php
    ├── dashboard.php
    ├── projects.php
    ├── project-new.php
    ├── project.php         # Main project hub (all tabs)
    ├── clients.php
    ├── portal.php          # Public client portal
    ├── settings.php
    ├── .htaccess
    └── assets/
        ├── css/app.css
        └── js/app.js
```

---

## Security Notes

- CSRF tokens on all forms
- Passwords hashed with bcrypt
- Session regeneration on login
- SQL via PDO prepared statements (no injection risk)
- Config should ideally live **above** the web root
- Sensitive handover items are blurred on the client portal

---

## Caveats / Extending

- Email notifications (quote sent, contract signed) can be added via PHP `mail()` or a library like PHPMailer
- File uploads (logos, assets) can be added to the handover hub
- Multi-user team support is straightforward — extend the `users` table
