# open-biz/openbooklm architecture

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

- Interactive diagram: https://gitdiagram.com/open-biz/openbooklm
- Repository: https://github.com/open-biz/openbooklm

## Overview

##### Main System Components

A. Frontend Layer (Next.js Application):
- Pages/Routes (from /src/app)
- UI Components (from /src/components)
- API Routes (from /src/app/api)
- Database Interface (from /src/lib/db.ts)

B. Backend Layer (Python Services):
- PDF Processing (pdf_to_text.py)
- Text Summarization (text_to_summary.py)
- Dialogue Generation (summary_to_dialogue.py)
- Audio Generation (text_to_audio.py, dialogue_to_audio.py)

C. Storage Layer:
- Containers for:
- Input Storage (/input - PDF documents)
- Output Storage (/output - processed text, summaries, dialogues, and audio)

##### Component Relationships and Data Flow

**User Interface → API Routes → Backend Services**
**PDF Input → Text Extraction → Summary Generation → Dialogue Creation → Audio Generation**

##### Specific Implementation Details

Frontend:
- Next.js router structure
- Chat interface components
- Notebook management system
- Theme provider integration

Backend Pipeline:
- Sequential processing steps
- Utility functions integration
- Where Python virtual environment is used

Storage:
- Different output formats (text, summaries, dialogue, audio)
- File organization structure

##### Technical Stack Indicators
- Next.js 14
- TypeScript
- Tailwind CSS
- shadcn/ui
- Python backend services
- Database system (from db.ts)

##### Additional Elements
- A section for environment configurations
- Setup process flow
- Where middleware (middleware.ts) intercepts requests

##### Audio generation process

Remember to indicate the project's modular nature, showing how the frontend and backend services can be developed and scaled independently.

This system design should clearly communicate how the application transforms PDFs into interactive, audio-enabled study materials through a series of processing steps while maintaining a modern, user-friendly interface.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[UI Layer]
        Pages["Pages/Routes"]
        Components["UI Components"]
        APIRoutes["API Routes"]
        DB["Database Interface"]
        Theme["Theme Provider"]
        Mid["Middleware"]
        
        UI --> Pages
        UI --> Components
        UI --> Theme
        Pages --> APIRoutes
        APIRoutes --> DB
        Mid -.- APIRoutes
    end

    subgraph Backend
        PDF["PDF Processing"]
        Summary["Text Summarization"]
        Dialogue["Dialogue Generation"]
        Audio["Audio Generation"]
        Utils["Backend Utilities"]
        
        PDF --> Summary
        Summary --> Dialogue
        Dialogue --> Audio
        Utils -.- PDF
        Utils -.- Summary
        Utils -.- Dialogue
        Utils -.- Audio
    end

    subgraph Storage
        Input["Input Storage"]
        OutputText["Text Output"]
        OutputSummary["Summary Output"]
        OutputDialogue["Dialogue Output"]
        OutputAudio["Audio Output"]
    end

    APIRoutes --> PDF
    Input --> PDF
    PDF --> OutputText
    Summary --> OutputSummary
    Dialogue --> OutputDialogue
    Audio --> OutputAudio

    classDef frontend fill:#3b82f6,color:white
    classDef backend fill:#22c55e,color:white
    classDef storage fill:#eab308,color:white
    classDef api fill:#a855f7,color:white
    classDef util fill:#94a3b8,color:white

    class UI,Pages,Components,Theme frontend
    class PDF,Summary,Dialogue,Audio backend
    class Input,OutputText,OutputSummary,OutputDialogue,OutputAudio storage
    class APIRoutes,DB api
    class Utils,Mid util

    click Pages "https://github.com/open-biz/OpenBookLM/blob/main/src/app/page.tsx"
    click Components "https://github.com/open-biz/OpenBookLM/tree/main/src/components"
    click APIRoutes "https://github.com/open-biz/OpenBookLM/tree/main/src/app/api"
    click DB "https://github.com/open-biz/OpenBookLM/blob/main/src/lib/db.ts"
    click Theme "https://github.com/open-biz/OpenBookLM/blob/main/src/components/theme-provider.tsx"
    click Mid "https://github.com/open-biz/OpenBookLM/blob/main/src/middleware.ts"
    click PDF "https://github.com/open-biz/OpenBookLM/blob/main/backend/pdf_to_text.py"
    click Summary "https://github.com/open-biz/OpenBookLM/blob/main/backend/text_to_summary.py"
    click Dialogue "https://github.com/open-biz/OpenBookLM/blob/main/backend/summary_to_dialogue.py"
    click Audio "https://github.com/open-biz/OpenBookLM/blob/main/backend/text_to_audio.py"
    click Utils "https://github.com/open-biz/OpenBookLM/blob/main/backend/utils/decorators.py"
    click Input "https://github.com/open-biz/OpenBookLM/tree/main/input"
    click OutputText "https://github.com/open-biz/OpenBookLM/tree/main/output/text"
    click OutputSummary "https://github.com/open-biz/OpenBookLM/tree/main/output/summaries"
    click OutputDialogue "https://github.com/open-biz/OpenBookLM/tree/main/output/dialogue"
    click OutputAudio "https://github.com/open-biz/OpenBookLM/tree/main/output/audio"
```
