# steven-tey/novel architecture

> Architecture diagram of the GitHub repository steven-tey/novel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/steven-tey/novel
- Repository: https://github.com/steven-tey/novel

## Overview

##### Main System Components

a) Frontend Layer:
- Editor Interface (based in apps/web)
- UI Components (components/tailwind)
- Editor Components (from packages/headless)

b) Backend Services:
- AI Integration (/api/generate)
- Image Upload Service (/api/upload)

c) Core Libraries:
- Headless Package (packages/headless)
- Extensions System
- Plugin System

##### Architecture Representation

a) Core Editor Architecture:
**[Frontend UI Layer]**
- ↓
**[Editor Components]**
- ↓
**[Headless Core] ← → [Extensions]**
- ↓
**[Tiptap Engine]**

b) AI Integration Flow:
**[Editor] → [AI Command] → [OpenAI API]**
- ↲ [Completion Handler] ↱

c) Image Handling:
**[Image Upload UI] → [Upload Service] → [Vercel Blob Storage]**

##### Key Relationships to Highlight

- Relationship between the headless package and the Tailwind implementation
- Extension system's plugin architecture
- Demonstrate the AI completion flow
- Image upload and handling flow

##### Technical Details

- Next.js framework structure
- Tiptap integration points
- OpenAI API connection
- Vercel Blob storage integration
- Extension system hooks

##### Implementation Notes

- The monorepo structure (apps/, packages/)
- The separation between headless core and UI implementation
- The plugin architecture for extensibility
- The AI integration points
- The image handling system

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI["Editor Interface"]
        Components["UI Components"]
        EditorComp["Editor Components"]
        SlashUI["Slash Command UI"]
        ImageUI["Image Upload UI"]
        ThemeSystem["Theme System"]
        Selectors["Selector Components"]
    end

    subgraph Core
        Headless["Headless Core"]
        Extensions["Extensions System"]
        Plugins["Plugin System"]
        SlashCore["Slash Command Core"]
        Tiptap["Tiptap Engine"]
    end

    subgraph Backend
        AIService["AI Service"]
        UploadService["Upload Service"]
    end

    subgraph External
        OpenAI["OpenAI API"]
        VercelBlob["Vercel Blob Storage"]
    end

    UI --> Components
    UI --> EditorComp
    UI --> Headless
    Components --> Headless
    EditorComp --> Headless
    SlashUI --> SlashCore
    ImageUI --> UploadService
    
    Headless --> Extensions
    Headless --> Plugins
    Headless --> Tiptap
    
    SlashCore --> AIService
    AIService --> OpenAI
    UploadService --> VercelBlob

    %% Click events for component mapping
    click UI "https://github.com/steven-tey/novel/blob/main/apps/web/components/tailwind/advanced-editor.tsx"
    click Components "https://github.com/steven-tey/novel/tree/main/apps/web/components/tailwind/ui/"
    click EditorComp "https://github.com/steven-tey/novel/tree/main/packages/headless/src/components/"
    click AIService "https://github.com/steven-tey/novel/blob/main/apps/web/app/api/generate/route.ts"
    click UploadService "https://github.com/steven-tey/novel/blob/main/apps/web/app/api/upload/route.ts"
    click ImageUI "https://github.com/steven-tey/novel/blob/main/apps/web/components/tailwind/image-upload.ts"
    click Headless "https://github.com/steven-tey/novel/tree/main/packages/headless/"
    click Extensions "https://github.com/steven-tey/novel/tree/main/packages/headless/src/extensions/"
    click Plugins "https://github.com/steven-tey/novel/tree/main/packages/headless/src/plugins/"
    click SlashCore "https://github.com/steven-tey/novel/blob/main/packages/headless/src/extensions/slash-command.tsx"
    click SlashUI "https://github.com/steven-tey/novel/blob/main/apps/web/components/tailwind/slash-command.tsx"
    click Selectors "https://github.com/steven-tey/novel/tree/main/apps/web/components/tailwind/selectors/"
    click ThemeSystem "https://github.com/steven-tey/novel/tree/main/apps/web/styles/"

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

    class UI,Components,EditorComp,SlashUI,ImageUI,ThemeSystem,Selectors frontend
    class Headless,Extensions,Plugins,SlashCore,Tiptap core
    class AIService,UploadService backend
    class OpenAI,VercelBlob external
```
