# madarco/mada-vector architecture

> Architecture diagram of the GitHub repository madarco/mada-vector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/madarco/mada-vector
- Repository: https://github.com/madarco/mada-vector

## Overview

##### Component Details

a. Client Layer:
- Public Page (app/page.tsx)
- Admin Panel (app/admin/page.tsx)
- UI Components (components/ directory)
- Use rounded rectangles for these components

b. Application Layer:
- Authentication API (app/api/auth)
- RAG API (app/api/rag)
- Vector Search API (app/api/vector-search)
- Secure Page APIs (app/api/secure)
- Middleware (middleware.ts) as a gateway

c. Data Access Layer:
- PgVector extension
- Database tables based on prisma/schema.prisma:
- Pages
- Content
- Chunks
- Documents

d. External Services Layer:
- OpenAI Services:
- text-embedding-ada-002 model
- API integration
- Vercel Postgres

##### Connections and Data Flow

- User interactions with frontend
- API calls between layers
- Database queries
- External service calls
- Authentication flow

##### Technical Details

Annotations for:
- Next.js 13+ App Router
- Prisma ORM with pgvector
- OpenAI Embeddings
- LlamaIndex Integration
- Vercel Postgres

##### Important Notes

Callouts for:
- Environment Variables Configuration
- Admin Authentication
- Vector Search Capabilities
- Database Migrations

- The RAG pipeline flow
- Vector search implementation
- Secure admin access
- Database structure with vector capabilities
- Integration with OpenAI services

Remember to show the relationship between the frontend search dialog (components/SearchDialog.tsx) and the vector search API, as this is a core feature of the application.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef frontend fill:#d0e1f9,stroke:#333
    classDef api fill:#90ee90,stroke:#333
    classDef data fill:#fff59d,stroke:#333
    classDef external fill:#e1bee7,stroke:#333
    classDef middleware fill:#ffcc80,stroke:#333

    %% Client Layer
    subgraph ClientLayer["Client Layer"]
        PublicPage["Public Frontend"]
        AdminPanel["Admin Panel"]
        UIComponents["UI Components"]
        SearchDialog["Search Interface"]
        AddPageDialog["Content Management"]
    end

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        AuthMiddleware["Authentication Middleware"]
        
        subgraph APIRoutes["API Routes"]
            AuthAPI["Authentication API"]
            RAGAPI["RAG API"]
            VectorSearchAPI["Vector Search API"]
            SecurePageAPI["Secure Page APIs"]
        end
    end

    %% Data Access Layer
    subgraph DataLayer["Data Access Layer"]
        PrismaORM["Prisma ORM"]
        PgVector["PgVector Extension"]
        DBClient["Database Client"]
        
        subgraph Tables["Database Tables"]
            Pages["Pages Table"]
            Content["Content Table"]
            Chunks["Chunks Table"]
            Documents["Documents Table"]
        end
    end

    %% External Services Layer
    subgraph ExternalLayer["External Services"]
        OpenAI["OpenAI Services"]
        VercelPG["Vercel Postgres"]
    end

    %% Connections
    PublicPage --> SearchDialog
    SearchDialog --> VectorSearchAPI
    AdminPanel --> AddPageDialog
    AddPageDialog --> SecurePageAPI
    
    AuthMiddleware --> APIRoutes
    
    APIRoutes --> PrismaORM
    PrismaORM --> PgVector
    PgVector --> VercelPG
    
    RAGAPI --> OpenAI
    VectorSearchAPI --> OpenAI

    %% Click Events
    click PublicPage "https://github.com/madarco/mada-vector/blob/main/app/page.tsx"
    click AdminPanel "https://github.com/madarco/mada-vector/blob/main/app/admin/page.tsx"
    click UIComponents "https://github.com/madarco/mada-vector/tree/main/components/ui/"
    click SearchDialog "https://github.com/madarco/mada-vector/blob/main/components/SearchDialog.tsx"
    click AuthAPI "https://github.com/madarco/mada-vector/blob/main/app/api/auth/route.ts"
    click RAGAPI "https://github.com/madarco/mada-vector/blob/main/app/api/rag/route.ts"
    click VectorSearchAPI "https://github.com/madarco/mada-vector/blob/main/app/api/vector-search/route.ts"
    click SecurePageAPI "https://github.com/madarco/mada-vector/tree/main/app/api/secure/page/"
    click AuthMiddleware "https://github.com/madarco/mada-vector/blob/main/middleware.ts"
    click PrismaORM "https://github.com/madarco/mada-vector/blob/main/prisma/schema.prisma"
    click Tables "https://github.com/madarco/mada-vector/tree/main/prisma/migrations/"
    click OpenAI "https://github.com/madarco/mada-vector/blob/main/lib/openai.ts"
    click PgVector "https://github.com/madarco/mada-vector/blob/main/lib/pgPrismaStore.ts"
    click DBClient "https://github.com/madarco/mada-vector/blob/main/lib/prisma.ts"
    click AddPageDialog "https://github.com/madarco/mada-vector/blob/main/components/AddPageDialog.tsx"

    %% Legend
    subgraph Legend["Legend"]
        Frontend["Frontend Components"]:::frontend
        APIComp["API Components"]:::api
        DataComp["Data Components"]:::data
        ExtComp["External Services"]:::external
        MidComp["Middleware"]:::middleware
    end
```
