# Punkit Creative — Management Auto 1: CEO Briefing
## Developer Handover & Implementation Guide

This document outlines the architecture and deployment steps for **Management Automation 1: The CEO Intelligence Briefing**. This is a premium R10k/month product requiring absolute reliability.

### 1. System Architecture
This automation replaces manual executive reporting by combining 4 different API data feeds into an AI-synthesized narrative, delivered via a Web Dashboard and an email alert.

*   **Frontend (CEO Command Center V2):** A highly polished, dark-mode web dashboard (`ceo_briefing_dashboard.html`). It is heavily styled using the Punkit Creative brand palette. It features a top-level AI narrative, Progress-to-Target tracking, CSS Sparkline trend charts, and a 4-pillar data grid (Treasury, Revenue, Audience, Operations). It also includes a bottom "Chief of Staff" AI chat input.
*   **Backend (n8n Workflow V2):** The workflow (`ceo_briefing_workflow.json`) acts as the orchestration engine.
    1. **Trigger:** A CRON node fires every weekday at 6:45 AM.
    2. **Extraction:** It makes sequential API calls to Xero (Treasury), HubSpot (Revenue), Google Analytics (Audience), and BambooHR (Operations).
    3. **Synthesis:** The 4 JSON payloads are injected into an OpenAI `gpt-4o` prompt where the AI acts as a "Chief of Staff" to write the morning narrative.
    4. **Storage:** The data is pushed via an HTTP POST to the Dashboard's database.
    5. **Alert:** A Gmail node fires off an email to the CEO at exactly 7:00 AM containing the narrative and a link to the dashboard.
    6. **Deep Dive Chat (V2):** A separate Webhook listens for POST requests from the Dashboard's chat input. It passes the CEO's ad-hoc question and the latest DB payload to OpenAI for instant, data-driven answers.

### 2. Deployment Steps

#### Step 1: Deploy the Dashboard
1. Host `ceo_briefing_dashboard.html` on a secure, restricted route (e.g., `https://punkit.co.za/ceo-command-center`).
2. Connect the frontend to your database so it dynamically populates the 4-pillar grid metrics based on the latest n8n push.

#### Step 2: Import & Configure n8n Workflow
1. Import `ceo_briefing_workflow.json` into the production n8n instance.
2. Authenticate the following nodes:
   *   **Xero Node:** Requires an active OAuth2 connection with `accounting.reports.read` scopes.
   *   **HubSpot Node:** Requires a Private App Access Token with `crm.objects.deals.read` scope.
   *   **Google Analytics Node:** Requires a Google Service Account JSON key with read access to the GA4 Property.
   *   **BambooHR Node:** Ensure the Basic Auth credentials (API Key) are valid for the `time_off/requests` endpoint.
   *   **OpenAI Node:** Ensure the API key is active.
   *   **Gmail Node:** Authorize the sending address.
3. Update the HTTP Node URL to point to your live dashboard database endpoint.

#### Step 3: Testing
1. Manually execute the n8n workflow.
2. Verify that the Dashboard Database receives the payload perfectly.
3. Verify the email arrives in the inbox looking pristine.

### 3. Maintenance Notes
*   If any of the 4 API connections fail (e.g., token expiry), the workflow will break. Ensure "Continue on Fail" is properly configured for the API nodes if you want partial data to still generate a report.
*   The OpenAI prompt is highly tuned. If the CEO requests a different tone, adjust the "System Role" prompt inside the n8n OpenAI node.
