# Project: BarkWho
**Role:** Senior Full-Stack Engineer / Home Lab Architect
**Objective:** Build a self-hosted, local parental control dashboard ("BarkWho") that interfaces with a UniFi Dream Router (UDR) to manage family internet access.

---

## 1. Core Technical Requirements
- **Framework:** React (Vite) Frontend + Node.js (Express) Backend.
- **Infrastructure:** Docker Compose (Service 1: Frontend, Service 2: Backend).
- **Target Hardware:** UniFi Dream Router (Local API).
- **Primary Logic:**
    - UI "Allow" (Green) = Backend calls UniFi to **DISABLE** the blocking rule.
    - UI "Block" (Red) = Backend calls UniFi to **ENABLE** the blocking rule.
    - **Note:** To toggle a rule, you must fetch the entire rule object, modify the `enabled` property, and PUT the full payload back to the UDR.

---

## 2. API Implementation Details (UDR Local API)
- **Auth:** `POST https://<UDR_IP>/api/auth/login` (Body: username, password).
- **Session:** Extract the `unifises` cookie and `x-csrf-token` from response headers for all subsequent calls.
- **Traffic Rule Endpoint:** `/proxy/network/v2/api/site/default/trafficrules`
- **Method for Toggle:** `PUT /proxy/network/v2/api/site/default/trafficrules/{rule_id}`

---

## 3. Version 1 Features (Functional Requirements)

### FR1: The Bark-Style Policy Engine
Map one UI "Category" to an array of UniFi Rule IDs in a `policy_map.json`:
- **Social Media:** [Rule_ID_TikTok, Rule_ID_Instagram]
- **Streaming:** [Rule_ID_Netflix, Rule_ID_Hulu]
- **Adult Content:** [Rule_ID_Adult_Filter]
- **Gaming:** [Rule_ID_Roblox, Rule_ID_Fortnite]

### FR2: Device Library & Dynamic Groups
- **Discovery:** Fetch all clients via `/proxy/network/api/s/default/stat/sta`.
- **Assignment:** Implement a way to add/remove a device's MAC address to/from the "Kids" IP Group profile in UniFi.
- **"Nuke" Button:** A high-visibility button for each device to instantly kill its connectivity.

### FR3: "Bonus Time" Timer System
- **Presets:** 15m, 30m, 60m.
- **Custom:** Manual minute/hour entry.
- **Reliability:** Timers must persist in a `timers.json` file so they resume after a container restart.

### FR4: Automated Curfew (Bedtime)
- **Schedule:** Integrated `node-cron` to enable the "Total Internet Block" at 9:00 PM and disable it at 7:00 AM.

---

## 4. UI/UX & Aesthetic Guidelines
- **Theme:** Dark Academia Tech.
- **Palette:**
    - Background: Deep Viridian (#2E473B) with circuit/blueprint overlays.
    - Text/Icons: Cream (#F5F5DC).
    - Status Indicators: Vibrant Green for "Active/Allowed", Deep Red/Magenta for "Blocked/Nuke".
- **Design Layout:**
    - Mobile-first PWA (iPad/iPhone optimized).
    - Bottom Navigation: [Control Dashboard] | [Device Library].
    - Use Framer Motion for the "Slide-up" Bonus Time drawer.

---

## 5. Deployment Instructions
- Provide a `docker-compose.yml` that mounts a `/data` volume for persistent JSON state.
- Use a `.env` file for: `UDR_IP`, `UDR_USER`, `UDR_PASSWORD`, `APP_SECRET_KEY`.
