# mindful-ai-dude/gemini-bookwriter architecture

> Architecture diagram of the GitHub repository mindful-ai-dude/gemini-bookwriter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mindful-ai-dude/gemini-bookwriter
- Repository: https://github.com/mindful-ai-dude/gemini-bookwriter

## Overview

##### Project type and purpose
- This is a single-page React.js application (“Gemini BookWriter”) that serves as an AI-powered book-writing assistant.
- Its purpose is to guide users through defining a book description, generating an outline, drilling down into chapters/sections, generating content via Google’s Gemini 2.5 Pro API, and exporting the result as Markdown.

##### File structure
- Top-level files:
- package.json – Node/React dependencies and scripts
- public/index.html – HTML shell
- src/ – React source code
- .env (implied) for REACT_APP_GEMINI_API_KEY
- src/ directory:
- index.js & App.js – application entry and root component
- BookUtils.js – utility module for API calls, parsing, and export logic
- Description.js / Outline.js / ContentGeneration.js – feature components
- CSS files – styling for each component
- There is no backend folder: this is a purely client-side app that calls an external AI service.

##### README insights
- Stack: React.js frontend, Google Gemini API, Local browser storage for persistence.
- Workflow: four main steps (Description → Outline → Content → Export).

##### Main components and interactions
a. Components:
1. User (Browser)
2. React SPA (App.js)
- BookDescriptionComponent
- OutlineComponent
- ContentGenerationComponent
- ExportComponent
3. Service Layer (BookUtils.js)
4. Local Storage (Browser Web Storage)
5. External Google Gemini 2.5 Pro API
b. Relationships / Data flows:
- User interacts with components in the browser UI.
- Components invoke functions in BookUtils.js to:
- send requests to Gemini API
- parse outline responses
- generate parts & content
- assemble Markdown for export
- BookUtils stores intermediate state in Local Storage.
- Export triggers a download of Markdown files.
c. Architectural patterns / principles:
- Component-based UI with single responsibility.
- Unidirectional data flow (React state → UI → utils → API → state).
- Externalizing API calls to a Utils/service layer.
- Persistence via client-side storage.
d. Key technologies:
- React.js (functional components, hooks)
- fetch/Axios calls to Google Gemini via REST
- LocalStorage Web API
- Markdown generation logic (in-memory)
- Environment variable for API key

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Entry
    User["User (Browser)"]:::user
    HTMLShell["public/index.html"]:::html
    indexJS["src/index.js"]:::entry
    GlobalStyles["src/index.css"]:::config
    Package["package.json"]:::config
    Env[".env (REACT_APP_GEMINI_API_KEY)"]:::config

    %% UI Layer
    subgraph "React UI Layer"
        App["App.js"]:::ui
        DescriptionComp["DescriptionComponent"]:::ui
        OutlineComp["OutlineComponent"]:::ui
        ContentComp["ContentGenerationComponent"]:::ui
        ExportComp["ExportComponent"]:::ui
    end

    %% Service and Storage
    BookUtils["BookUtils.js"]:::service
    LocalStorage["Local Storage"]:::storage
    ExternalAPI["Google Gemini 2.5 Pro API"]:::api

    %% Connections
    User -->|"opens app"| HTMLShell
    HTMLShell -->|"loads entry"| indexJS
    indexJS -->|"imports styles"| GlobalStyles
    indexJS -->|"renders root"| App
    App -->|"renders UI components"| DescriptionComp
    App -->|"renders UI components"| OutlineComp
    App -->|"renders UI components"| ContentComp
    App -->|"renders UI components"| ExportComp

    DescriptionComp -->|"calls service"| BookUtils
    OutlineComp -->|"calls service"| BookUtils
    ContentComp -->|"calls service"| BookUtils
    ExportComp -->|"calls service"| BookUtils

    BookUtils -.->|"writes"| LocalStorage
    LocalStorage -.->|"reads"| BookUtils

    BookUtils -.->|"fetches"| ExternalAPI
    Env -.->|"provides API key"| BookUtils

    %% Click Events
    click HTMLShell "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/public/index.html"
    click indexJS "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/index.js"
    click GlobalStyles "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/index.css"
    click Package "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/package.json"
    click Env "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/.env"
    click App "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/App.js"
    click DescriptionComp "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/Description.js"
    click OutlineComp "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/Outline.js"
    click ContentComp "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/ContentGeneration.js"
    click BookUtils "https://github.com/mindful-ai-dude/gemini-bookwriter/blob/main/src/BookUtils.js"

    %% Styles
    classDef user fill:#E0F7FA,stroke:#006064,color:#006064
    classDef html fill:#FFF3E0,stroke:#E65100,color:#E65100
    classDef entry fill:#E8EAF6,stroke:#3949AB,color:#3949AB
    classDef config fill:#F3E5F5,stroke:#6A1B9A,color:#6A1B9A
    classDef ui fill:#E3F2FD,stroke:#1E88E5,color:#1E88E5
    classDef service fill:#E8F5E9,stroke:#43A047,color:#43A047
    classDef storage fill:#FFFDE7,stroke:#F9A825,color:#F9A825
    classDef api fill:#ECEFF1,stroke:#607D8B,color:#607D8B
```
