# gsenrdx/persona-insight architecture

> Architecture diagram of the GitHub repository gsenrdx/persona-insight, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gsenrdx/persona-insight
- Repository: https://github.com/gsenrdx/persona-insight

## Overview

##### Project Type and Purpose
- Persona Insight is a full-stack AI-powered customer persona analysis platform built with Next.js (App Router), React, TypeScript, Supabase (PostgreSQL), and MISO AI APIs.
- Users upload interview data, the system processes it via AI pipelines, stores results in Supabase, then renders interactive dashboards and chat interfaces on the frontend.

##### High-Level File Structure Analysis
- app/
- app/api/… → Backend API routes (chat, personas, interviews, projects, insights, files, workflow)
- app/auth/, app/login/, app/projects/, app/insights/, app/chat/… → Page routes
- components/ → Reusable React UI components organized by domain (auth, chat, persona, project, shared, ui)
- hooks/ → Custom React hooks for data fetching and business logic separation
- lib/ → Core utilities: API clients, constants, error handlers, Supabase clients, MISO integration
- types/ → TypeScript type definitions
- public/ & styles/ → Static assets and global styles

##### Key System Components
a. Frontend Layer
- Next.js App (app/layout.tsx, pages under app/)
- UI Components (components/ui, components/shared)
- Domain Components (components/auth, chat, persona, project)
- State & Data Fetching (TanStack Query via lib/query-client & hooks/use-*)
b. Backend Layer (Next.js API Routes)
- Chat Endpoints → /api/chat, /api/chat/summary
- Persona Management → /api/personas (search, sync, synthesis, criteria, update-dataset)
- Interview Processing → /api/interviews/[id]
- Project Management → /api/projects/[id]/members, /api/projects/members
- Insights & Workflow → /api/insights, /api/insights/years, /api/workflow
- File Handling → /api/files/download
- Supabase Helpers → /api/supabase/personas
c. Data & External Services
- Supabase (PostgreSQL) for persistence
- MISO API (AI processing, persona generation, chat agent)
- Authentication (OAuth callbacks under app/auth/callback)

##### Relationships and Data Flows
1. User → Frontend UI (pages, components)
2. Frontend → Next.js API Routes (via fetch or TanStack Query hooks)
3. API Routes →
- Supabase (CRUD interview data, personas, projects)
- MISO API (invoke AI pipelines: STT, persona synthesis, chat, summary, mind-map)
4. External services → API Routes → Frontend real-time updates
5. Frontend state updates and re-renders via React and Query Provider

##### Architectural Patterns & Principles
- Domain-Driven Design: feature folders under app/api and components
- Separation of Concerns: UI vs. business logic (custom hooks, lib/api)
- Reusable Design System: shadcn/ui + Radix UI components
- Type Safety: TypeScript end-to-end (types directory)
- API-First: all functionality exposed via Next.js API routes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        User["User"]:::external
        NextApp["Next.js App Router"]:::frontend
        RootPage["Root Page<br>(app/page.tsx)"]:::frontend
        LoginPage["Login Page<br>(app/login/page.tsx)"]:::frontend
        AuthCallback["Auth Callback Route<br>(app/auth/callback/route.ts)"]:::frontend
        EmailConfirm["Email Confirm Page<br>(app/auth/confirm/page.tsx)"]:::frontend
        ProjectsList["Projects List<br>(app/projects/page.tsx)"]:::frontend
        ProjectDetail["Project Detail<br>(app/projects/[id]/page.tsx)"]:::frontend
        InsightsPage["Insights Page<br>(app/insights/page.tsx)"]:::frontend
        ChatPage["Chat Page<br>(app/chat/[personaId]/page.tsx)"]:::frontend
        Providers["Theme & Query Providers<br>(components/providers/query-provider.tsx)"]:::frontend
        SharedNav["Shared Navigation & Theme<br>(components/shared/navigation.tsx<br>components/shared/theme-provider.tsx)"]:::frontend
        UIlib["UI Component Library<br>(components/ui/)"]:::frontend
        DomainUI["Domain UI Components<br>(components/auth/, components/chat/, components/persona/, components/project/)"]:::frontend
        ErrorHandling["Global Error Handling<br>(app/error.tsx<br>app/global-error.tsx)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        QueryProv["React Query Provider"]:::frontend
        APIChat["/api/chat Routes"]:::backend
        APIPersonas["/api/personas Routes"]:::backend
        APIInterviews["/api/interviews Routes"]:::backend
        APIProjects["/api/projects Routes"]:::backend
        APIInsights["/api/insights & workflow"]:::backend
        APIFiles["/api/files/download"]:::backend
        APISupabase["/api/supabase/personas"]:::backend
        APIKnowledge["/api/knowledge Routes"]:::backend
    end

    %% Data & Services Layer
    subgraph "Data & Services Layer"
        direction TB
        Supabase["Supabase<br>(PostgreSQL)"]:::database
        MISO["MISO AI API"]:::external
        AuthProvider["Auth Provider<br>(OAuth)"]:::external
    end

    %% Connections
    User -->|"interacts with"| NextApp
    NextApp --> RootPage
    NextApp --> LoginPage
    NextApp --> AuthCallback
    NextApp --> EmailConfirm
    NextApp --> ProjectsList
    NextApp --> ProjectDetail
    NextApp --> InsightsPage
    NextApp --> ChatPage
    NextApp --> ErrorHandling
    NextApp --> UIlib
    NextApp --> SharedNav
    NextApp --> Providers
    NextApp --> DomainUI

    RootPage -->|uses| Providers
    LoginPage -->|uses| Providers
    AuthCallback -->|uses| Providers
    ProjectsList -->|uses| Providers
    ProjectDetail -->|uses| Providers
    InsightsPage -->|uses| Providers
    ChatPage -->|uses| Providers

    Providers --> QueryProv
    DomainUI --> QueryProv
    UIlib --> QueryProv

    QueryProv -->|"fetch / TanStack Query"| APIChat
    QueryProv -->|"fetch / TanStack Query"| APIPersonas
    QueryProv -->|"fetch / TanStack Query"| APIInterviews
    QueryProv -->|"fetch / TanStack Query"| APIProjects
    QueryProv -->|"fetch / TanStack Query"| APIInsights
    QueryProv -->|"fetch / TanStack Query"| APIFiles
    QueryProv -->|"fetch / TanStack Query"| APISupabase
    QueryProv -->|"fetch / TanStack Query"| APIKnowledge

    APIChat -->|"CRUD & AI calls"| Supabase
    APIPersonas -->|"CRUD & AI calls"| Supabase
    APIInterviews -->|"CRUD"| Supabase
    APIProjects -->|"CRUD"| Supabase
    APIInsights -->|"CRUD"| Supabase
    APIFiles -->|"file storage"| Supabase
    APISupabase -->|"persona helpers"| Supabase

    APIChat -->|"invoke"| MISO
    APIPersonas -->|"invoke"| MISO
    APIInsights -->|"invoke"| MISO
    APIKnowledge -->|"invoke"| MISO

    AuthCallback -->|"OAuth flow"| AuthProvider
    AuthProvider -->|"token"| NextApp

    Supabase -->|"data"| NextApp
    MISO -->|"AI results"| NextApp

    %% Click Events
    click NextApp "https://github.com/gsenrdx/persona-insight/blob/main/app/layout.tsx"
    click RootPage "https://github.com/gsenrdx/persona-insight/blob/main/app/page.tsx"
    click LoginPage "https://github.com/gsenrdx/persona-insight/blob/main/app/login/page.tsx"
    click AuthCallback "https://github.com/gsenrdx/persona-insight/blob/main/app/auth/callback/route.ts"
    click EmailConfirm "https://github.com/gsenrdx/persona-insight/blob/main/app/auth/confirm/page.tsx"
    click ProjectsList "https://github.com/gsenrdx/persona-insight/blob/main/app/projects/page.tsx"
    click ProjectDetail "https://github.com/gsenrdx/persona-insight/blob/main/app/projects/[id]/page.tsx"
    click InsightsPage "https://github.com/gsenrdx/persona-insight/blob/main/app/insights/page.tsx"
    click ChatPage "https://github.com/gsenrdx/persona-insight/blob/main/app/chat/[personaId]/page.tsx"
    click ErrorHandling "https://github.com/gsenrdx/persona-insight/blob/main/app/error.tsx"
    click ErrorHandling "https://github.com/gsenrdx/persona-insight/blob/main/app/global-error.tsx"
    click UIlib "https://github.com/gsenrdx/persona-insight/tree/main/components/ui/"
    click Providers "https://github.com/gsenrdx/persona-insight/blob/main/components/providers/query-provider.tsx"
    click SharedNav "https://github.com/gsenrdx/persona-insight/blob/main/components/shared/navigation.tsx"
    click SharedNav "https://github.com/gsenrdx/persona-insight/blob/main/components/shared/theme-provider.tsx"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0066cc,color:#003366
    classDef backend fill:#d4edda,stroke:#28a745,color:#155724
    classDef database fill:#f0e6ff,stroke:#6f42c1,color:#4e1a7e
    classDef external fill:#fff3cd,stroke:#e0a800,color:#856404
```
