# chal0326/grantwriter architecture

> Architecture diagram of the GitHub repository chal0326/grantwriter, 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/chal0326/grantwriter
- Repository: https://github.com/chal0326/grantwriter

## Overview

##### Main Components

A. Frontend Layer:
- User Interface Components (ChatBot, DraftEditor, ProposalViewer)
- Client-side routing
- State Management

B. Backend Layer:
- API Endpoints (/api/ai, /api/fetch, /api/save)
- Server-side logic

C. External Services:
- Google AI (Gemini Flash 2.0)
- Supabase Database
- Use purple for external services

##### Component Relationships

- User Interface → API Routes (HTTP requests)
- API Routes → Google AI (AI processing)
- API Routes → Supabase (data persistence)
- Return paths for responses

##### Detailed Component Breakdown

**Client Side**
- Components/
- ChatBot
- DraftEditor
- ProposalViewer
- Input
- Pages/
- index.js
- Styles/
- globals.css (Tailwind)

**Server Side**
- API Routes
- /api/ai
- /api/fetch
- /api/save

##### Technology Stack Indicators

Badges or labels for:
- Next.js
- Node.js
- TailwindCSS
- NextUI
- Google AI SDK
- Supabase

##### Database Schema (Supabase)

A small section showing tables:
**Database**
- users
- drafts
- critiques
- proposals

##### Additional Elements

- A title: "Grant Writer App Architecture"
- Version number
- Timestamps for API calls
- Scaling points
- Security boundaries

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[User Interface]
        CB["ChatBot"]
        DE["DraftEditor"]
        PV["ProposalViewer"]
        IN["Input Components"]
        UI --> CB
        UI --> DE
        UI --> PV
        UI --> IN
    end

    subgraph APILayer
        AI["/api/ai"]
        FETCH["/api/fetch"]
        SAVE["/api/save"]
    end

    subgraph ExternalServices
        GEM[Google AI Gemini]
        DB[(Supabase DB)]
    end

    %% Main Flow
    UI --> AI
    UI --> FETCH
    UI --> SAVE
    
    AI --> GEM
    FETCH --> DB
    SAVE --> DB
    
    GEM --> AI
    DB --> FETCH
    DB --> SAVE

    %% Database Schema
    subgraph Database
        USERS[Users Table]
        DRAFTS[Drafts Table]
        CRITIQUES[Critiques Table]
        PROPOSALS[Proposals Table]
    end

    DB --> USERS
    DB --> DRAFTS
    DB --> CRITIQUES
    DB --> PROPOSALS

    %% Styling
    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef backend fill:#e8f5e9,stroke:#1b5e20
    classDef external fill:#f3e5f5,stroke:#4a148c
    classDef database fill:#fff3e0,stroke:#e65100

    class UI,CB,DE,PV,IN frontend
    class AI,FETCH,SAVE backend
    class GEM,DB external
    class USERS,DRAFTS,CRITIQUES,PROPOSALS database

    %% Click Events
    click CB "https://github.com/chal0326/grantwriter/blob/main/components/ChatBot.jsx"
    click DE "https://github.com/chal0326/grantwriter/blob/main/components/DraftEditor.jsx"
    click PV "https://github.com/chal0326/grantwriter/blob/main/components/ProposalViewer.jsx"
    click IN "https://github.com/chal0326/grantwriter/blob/main/components/Input.jsx"
    click AI "https://github.com/chal0326/grantwriter/blob/main/pages/api/ai.js"
    click FETCH "https://github.com/chal0326/grantwriter/blob/main/pages/api/fetch.js"
    click SAVE "https://github.com/chal0326/grantwriter/blob/main/pages/api/save.js"

    %% Legend
    subgraph Legend
        F[Frontend]:::frontend
        B[Backend]:::backend
        E[External Services]:::external
        D[Database]:::database
    end
```
