# splitbee/react-notion architecture

> Architecture diagram of the GitHub repository splitbee/react-notion, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/splitbee/react-notion
- Repository: https://github.com/splitbee/react-notion

## Overview

This project is a React-based library that renders Notion pages into a web-friendly format. It is designed as a lightweight renderer and is best used to display content from Notion as a blog, documentation site, or personal page. The main goal of this project is to transform the Notion API’s response (the block map of a Notion page) into React elements with support for rich content (text, headings, images, code blocks with PrismJS highlighting, etc).

##### Main Components and Their Roles
- Library Core (src/index.tsx and src/renderer.tsx): This is the entry point that initializes the NotionRenderer and handles the mapping of Notion blocks to React components.
- Block Rendering Modules (src/block.tsx): Responsible for interpreting and rendering individual Notion blocks.
- React Components (src/components/):
- asset.tsx – Likely handles media (images, other assets).
- code.tsx – Renders code blocks with PrismJS integration.
- Utilities & Types (src/utils.ts and src/types.ts): Provide helper functions, type definitions, and other support routines used across the library.
- Styles (src/styles.css): The main stylesheet that dictates the appearance of the rendered Notion pages.
- Example Application (example folder): Contains a minimal Next.js (or React) example that demonstrates how to integrate and use the library. This includes configuration for TypeScript, environment definitions, and example page components.

##### Interactions and Data Flow
- Input: The library expects a Notion API response in the form of a block map (a collection of blocks with their content and metadata).
- Flow: The main NotionRenderer receives the block map and iterates over it. Depending on the block type (e.g., text, heading, image, code), it delegates rendering to specific component modules.
- External Integration: Although the library does not handle API communication directly, the README explains that an external service (like the notion-api-worker) is used to fetch data. You might indicate an “External Notion API” component that feeds data into a client (shown in the example) which then passes it to NotionRenderer.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: Emphasize the React component hierarchy where each block type is modular and can be extended or replaced.
- Separation of Concerns: The library cleanly separates rendering logic (in src/renderer.tsx and block.tsx) from UI components (in src/components) and styles (in src/styles.css).
- Reusability and Extensibility: The organization into modules (utilities, types, components) allows for easy extension and maintenance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Source
    extAPI["External Notion API"]:::external

    %% Example Application
    exApp["Example Application"]:::example

    %% Library Core
    coreGroup["Library Core"]
    notionRenderer["NotionRenderer (Entry)"]:::core
    blockRenderer["Block Renderer"]:::core

    %% React Components Subgraph
    subgraph "React Components"
        asset["Asset Component"]:::component
        code["Code Component"]:::component
        pageHeader["Page Header Component"]:::component
        pageIcon["Page Icon Component"]:::component
    end

    %% Utilities & Styles
    utilities["Utilities & Types"]:::utility
    styles["Styles"]:::styles

    %% External Dependencies
    prism["PrismJS"]:::external

    %% Data Flow Connections
    extAPI -->|"fetches"| exApp
    exApp -->|"imports"| notionRenderer
    notionRenderer -->|"delegates"| blockRenderer
    notionRenderer -->|"uses"| utilities
    notionRenderer -->|"applies"| styles

    blockRenderer -->|"renders"| asset
    blockRenderer -->|"renders"| code
    blockRenderer -->|"renders"| pageHeader
    blockRenderer -->|"renders"| pageIcon

    code -->|"integrates"| prism

    %% Click Events
    click notionRenderer "https://github.com/splitbee/react-notion/blob/master/src/index.tsx"
    click blockRenderer "https://github.com/splitbee/react-notion/blob/master/src/block.tsx"
    click asset "https://github.com/splitbee/react-notion/blob/master/src/components/asset.tsx"
    click code "https://github.com/splitbee/react-notion/blob/master/src/components/code.tsx"
    click pageHeader "https://github.com/splitbee/react-notion/blob/master/src/components/page-header.tsx"
    click pageIcon "https://github.com/splitbee/react-notion/blob/master/src/components/page-icon.tsx"
    click utilities "https://github.com/splitbee/react-notion/blob/master/src/utils.ts"
    click styles "https://github.com/splitbee/react-notion/blob/master/src/styles.css"
    click exApp "https://github.com/splitbee/react-notion/tree/master/example"

    %% Styles
    classDef external fill:#ffe6cc,stroke:#d35400,stroke-width:2px
    classDef example fill:#dff0d8,stroke:#3c763d,stroke-width:2px
    classDef core fill:#d9edf7,stroke:#31708f,stroke-width:2px
    classDef component fill:#fcf8e3,stroke:#8a6d3b,stroke-width:2px
    classDef utility fill:#f2dede,stroke:#a94442,stroke-width:2px
    classDef styles fill:#e6e6e6,stroke:#999,stroke-width:2px
```
