Skip to content

Repository files navigation

BrandBrain

BrandBrain is the memory layer for marketing agencies. It turns scattered client knowledge into cited answers, Ogilvy-style copy judgment, and reusable workflows.

Built for OpenAI x Outskill Hackathon Next.js 14 Supabase OpenAI


What is BrandBrain?

Most agencies lose context when work moves between people, docs, and chats. BrandBrain makes that memory searchable and reusable by ingesting campaigns, briefs, and brand guides, then scoring new copy against the agency's own best work using David Ogilvy's 15 advertising principles.

The product was built in an AI-native workflow: validate the wedge, build the narrow MVP, and ship the working product fast.


Architecture Overview

graph TD
    A[User / Agency] --> B[BrandBrain App]
    B --> C{Core Layers}
    C --> D[Knowledge Layer<br/>Ingest Documents]
    C --> E[Judgment Layer<br/>Ogilvy Scorer]
    C --> F[Skills Layer<br/>Query Brain]

    D --> G[(Supabase PostgreSQL)]
    G --> H[raw_sources]
    G --> I[knowledge_cards]
    G --> J[query_log]
    G --> K[score_log]

    E --> L[GPT-4o-mini]
    F --> L

    B --> M[Public Share Link]
    M --> N[Read-only Brain Access]
Loading

User Flow

flowchart LR
    S([Start]) --> AU[Sign Up / Login]
    AU --> DB[Dashboard]

    DB --> IN[Ingest Doc]
    DB --> QU[Query Brain]
    DB --> SC[Score Copy]
    DB --> SH[Share Brain]
    DB --> AN[Analytics]

    IN --> |Paste campaign / brief / brand guide| EX[GPT extracts 3-7 knowledge cards]
    EX --> KC[(knowledge_cards)]
    KC --> QU

    QU --> |Natural language question| KS[Keyword search over cards]
    KS --> GPT[GPT answers with citations]
    GPT --> RS[Response + source titles]

    SC --> |Paste new copy + pick client| OG[Ogilvy 15-principle scoring]
    OG --> BR[Breakdown + top 3 failures]
    BR --> RW[AI rewrite, then score again]

    SH --> |Toggle public ON| PL[Public share URL /b/token]
    PL --> |Anyone with link| QB[Query Brain - read only]
Loading

Database Schema

erDiagram
    BRAINS {
        uuid id PK
        uuid user_id FK
        text name
        text description
        int docs_ingested
        int concepts_extracted
        int queries_answered
        text share_token
        bool is_public
        timestamptz created_at
    }

    RAW_SOURCES {
        uuid id PK
        uuid brain_id FK
        text title
        text content
        text source_type
        text client_name
        timestamptz created_at
    }

    KNOWLEDGE_CARDS {
        uuid id PK
        uuid brain_id FK
        uuid source_id FK
        text concept
        text summary
        text client_name
        text[] tags
        timestamptz created_at
    }

    QUERY_LOG {
        uuid id PK
        uuid brain_id FK
        text question
        text answer
        text[] sources_used
        int tokens_used
        float cost_usd
        timestamptz created_at
    }

    SCORE_LOG {
        uuid id PK
        uuid brain_id FK
        text client_name
        text original_copy
        int score_before
        int score_after
        jsonb breakdown
        jsonb top_3_failures
        text rewritten_copy
        float cost_usd
        timestamptz created_at
    }

    BRAINS ||--o{ RAW_SOURCES : "has"
    BRAINS ||--o{ KNOWLEDGE_CARDS : "has"
    BRAINS ||--o{ QUERY_LOG : "logs"
    BRAINS ||--o{ SCORE_LOG : "tracks"
    RAW_SOURCES ||--o{ KNOWLEDGE_CARDS : "generates"
Loading

Multi-Brain & Sharing Flow

sequenceDiagram
    participant U as User
    participant App as BrandBrain
    participant DB as Supabase
    participant AI as GPT-4o-mini
    participant P as Public User

    Note over U,P: Create & Populate Brain
    U->>App: Sign up -> auto-creates Brain #1
    U->>App: Ingest document (client: Nike)
    App->>AI: Extract 3-7 concepts
    AI-->>App: JSON knowledge cards
    App->>DB: Save raw_source + knowledge_cards

    Note over U,P: Create Second Brain
    U->>App: Creates Brain #2 for another client
    App->>DB: Saves separate brain workspace
    U->>App: Ingests document into Brain #2

    Note over U,P: Query Any Brain
    U->>App: Select Brain #1 (Nike), ask question
    App->>DB: Fetch knowledge_cards for Brain #1
    App->>AI: Build context + answer
    AI-->>App: Answer with citations
    App-->>U: Response showing source documents

    Note over U,P: Share Brain
    U->>App: Toggle Brain #1 public = true
    App->>DB: SET is_public = true
    App-->>U: Share URL -> /b/abc123token

    P->>App: Visit /b/abc123token
    App->>DB: Fetch brain by share_token WHERE is_public=true
    App-->>P: Public query console (read-only)
    P->>App: Ask question
    App->>AI: Answer from Brain #1 cards
    AI-->>P: Response with citations
Loading

Ogilvy Scoring Flow

flowchart TD
    A[User pastes copy] --> B{Brain has client history?}
    B -- No --> C[Error: Ingest first]
    B -- Yes --> D[Fetch client knowledge_cards]

    D --> E[Build context from cards]
    E --> F[GPT scores against 15 principles]

    F --> G[Score breakdown table]
    G --> H[Top 3 failures with fixes]
    H --> I[AI rewrites copy]
    I --> J[Score the rewrite again]

    J --> K{Improvement?}
    K -- Yes --> L[Show: Before -> After score]
    K -- No --> L

    L --> M[Save to score_log]
    M --> N[User can: Copy, Share, Save to Brain, Score again]

    style F fill:#412991,color:#fff
    style L fill:#1a6b3c,color:#fff
    style C fill:#c0391a,color:#fff
Loading

Three-Layer Company Brain Model

mindmap
  root((BrandBrain))
    Knowledge Layer
      Campaigns
        Headlines that worked
        CTR winners
        Seasonal patterns
      Brand Guides
        Voice and tone
        Never-do rules
        Visual language
      Briefs
        Target audience
        KPIs
        Budget signals
      Performance Data
        CAC benchmarks
        Conversion rates
        Channel mix
    Judgment Layer
      Ogilvy 15 Principles
        Product Positioning
        Unique Benefit
        Headline Quality
        Reader Focus
        Clear Tone
        Simple Language
        Evidence
        Emotion / Story
        Structure
        Call to Action
        Visuals
        Testability
        Length
        Attention Hook
        Repetition
    Skills Layer
      Query Brain
        Citation-backed answers
        Keyword matching
        Context building
      Score and Rewrite
        Principle breakdown
        Failure diagnosis
        AI rewrite
        Save rewrite to brain
      Share Brain
        Public read-only link
        Token-based access
        Multi-user queries
Loading

Tech Stack

graph LR
    FE[Next.js 14 App Router<br/>Tailwind CSS<br/>Recharts] --> API[API Routes<br/>/api/ingest<br/>/api/query<br/>/api/score]
    API --> RW[/api/rewrite/save]
    API --> OAI[OpenAI GPT-4o-mini]
    API --> SB[(Supabase<br/>Auth + PostgreSQL<br/>Row Level Security)]
    FE --> SB

    style FE fill:#000,color:#fff
    style OAI fill:#412991,color:#fff
    style SB fill:#3ECF8E,color:#000
Loading

Features

Knowledge Layer - Ingest

  • Paste campaigns, briefs, brand guides, or performance data
  • GPT-4o-mini extracts 3-7 structured knowledge cards per document
  • Each card: concept + summary + tags + client name
  • Multiple brains per user - one per client or project

Judgment Layer - Ogilvy Copy Scoring

  • Score any copy 0-100 using David Ogilvy's 15 advertising principles
  • Benchmarked against the client's own past campaigns
  • Get a detailed breakdown, top 3 failure diagnoses, and an AI rewrite
  • Copy, share, rescore, or save the rewrite back into the brain
  • Before vs after score tracked in analytics

Skills Layer - Query Brain

  • Ask anything in plain English
  • Answers cite the exact documents they came from
  • Answers are grounded in the agency's stored knowledge cards
  • Works across multiple brains with the brain selector

Public Brain Sharing

  • Toggle any brain public with one click
  • Anyone with the /b/{token} URL can query - no login required
  • Read-only access, no data modification possible
  • Share with clients, new hires, or the world

Analytics

  • Copy quality over time (before vs after scores)
  • Queries per day
  • Total docs, concepts, queries, scores
  • Token usage and estimated cost tracking

Auth

  • Email/password signup and login
  • Branded signup confirmation modal
  • Forgot password and reset password flow through Supabase Auth

Local Setup

git clone https://github.com/NikhilRaikwar/BrandBrain.git
cd BrandBrain
npm install
npm run dev

Environment variables:

NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEY=
SUPABASE_SERVICE_ROLE_KEY=
OPENAI_API_KEY=
NEXT_PUBLIC_SITE_URL=https://brandbrain-nu.vercel.app

API Reference

POST /api/ingest

{
  "brainId": "uuid (optional - creates one if missing)",
  "sourceType": "campaign | brand_guide | brief | performance_data",
  "clientName": "Nike",
  "title": "Summer 2026 Campaign",
  "content": "Full document text..."
}

Returns: { brain_id, concepts: [...], count, cost_usd }

POST /api/query

{
  "brainId": "uuid",
  "question": "What tone works best for youth FMCG?",
  "shareToken": "optional - for public brain access"
}

Returns: { answer, sources: ["Doc title 1", ...], cost_usd }

POST /api/score

{
  "brainId": "uuid",
  "clientName": "Nike",
  "copy": "Your copy to score here..."
}

Returns: { overall_score, breakdown, top_3_failures, rewrite, rewrite_score, cost_usd }

POST /api/rewrite/save

{
  "brainId": "uuid",
  "clientName": "Nike",
  "title": "Rewrite for Nike",
  "rewrite": "Improved copy..."
}

Returns: { source_id, cards_created }


Hackathon Context

OpenAI x Outskill AI Builders Hackathon - May 2026

Milestone Date Status
Kickoff Mon 26 May Done
Product brief + MVP Wed 28 May Submitted
Final Go Live Sun 31 May Done

Built for agencies, developers, AI engineers, and product builders who want their institutional knowledge to survive every team change and keep compounding instead of disappearing.


License

Private hackathon project - BrandBrain 2026

About

BrandBrain is a living company brain for marketing agencies that ingests client knowledge, answers with citations, and scores copy against Ogilvy-style judgment.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages