# alexerrant/pentive architecture

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

- Interactive diagram: https://gitdiagram.com/alexerrant/pentive
- Repository: https://github.com/alexerrant/pentive

## Overview

##### Main System Components

a. Core Applications:
- Main App (app/)
- Hub (hub/)
- API Services (api-ugc/, cwa/)
- Peer Sync Service (peer/)

b. Shared Libraries:
- shared/
- shared-dom/
- shared-edge/

c. Plugin System:
- example-plugins/
- Plugin Manager Infrastructure

##### Architecture Representation

Frontend Layer:
- Hub interface (hub/) separately
- Plugin integration points
- Service worker architecture

Middle Layer:
- TRPC client/server communication
- Peer-to-peer syncing mechanism
- Plugin manager system
- Database replication system

Backend Layer:
- API services (api-ugc, cwa)
- Database infrastructure
- Authentication system

##### Key Relationships to Highlight

- Plugin system integration with the main application
- Data flow between the local database and remote sync
- Service worker's role in offline functionality

##### Specific Implementation Details

- Blue rectangles for core applications
- Green hexagons for shared libraries
- Yellow diamonds for plugin system components
- Purple circles for database components

##### Technical Stack Elements

- SQLite/CRSQLite for local storage
- TRPC for API communication
- Service Workers for offline functionality
- Vite for build system
- Cloudflare Workers for edge computing

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        MainApp["Main Application"]
        Hub["Hub Interface"]
        SW["Service Worker"]
        Templates["Template System"]
        Study["Study System"]
    end

    subgraph PluginSystem
        PluginManager["Plugin Manager"]
        ExamplePlugins["Example Plugins"]
    end

    subgraph SharedLibs
        SharedCore["Shared Core"]
        SharedDom["Shared DOM"]
        SharedEdge["Shared Edge"]
    end

    subgraph DataLayer
        DB["Database (SQLite/CRSQLite)"]
        DBRep["Database Replicator"]
        WholeDBRTC["Whole DB RTC"]
    end

    subgraph APIServices
        APIUGC["API UGC"]
        CWA["Cloudflare Workers"]
        PeerSync["Peer Sync Service"]
    end

    MainApp --> SW
    MainApp --> Templates
    MainApp --> Study
    MainApp --> PluginManager
    MainApp --> DB
    Hub --> DB
    PluginManager --> ExamplePlugins
    DB --> DBRep
    DBRep --> WholeDBRTC
    WholeDBRTC --> PeerSync
    PeerSync --> CWA
    APIUGC --> CWA

    SharedCore --> MainApp
    SharedDom --> MainApp
    SharedEdge --> CWA

    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef frontend fill:#ddf,stroke:#333
    classDef plugin fill:#ffd,stroke:#333
    classDef shared fill:#dfd,stroke:#333
    classDef data fill:#fdf,stroke:#333
    classDef api fill:#fdd,stroke:#333

    class MainApp,Hub,SW,Templates,Study frontend
    class PluginManager,ExamplePlugins plugin
    class SharedCore,SharedDom,SharedEdge shared
    class DB,DBRep,WholeDBRTC data
    class APIUGC,CWA,PeerSync api

    click MainApp "https://github.com/AlexErrant/Pentive/tree/main/app"
    click Hub "https://github.com/AlexErrant/Pentive/tree/main/hub"
    click APIUGC "https://github.com/AlexErrant/Pentive/tree/main/api-ugc"
    click CWA "https://github.com/AlexErrant/Pentive/tree/main/cwa"
    click PeerSync "https://github.com/AlexErrant/Pentive/tree/main/peer"
    click ExamplePlugins "https://github.com/AlexErrant/Pentive/tree/main/example-plugins"
    click PluginManager "https://github.com/AlexErrant/Pentive/blob/main/app/src/pluginManager.ts"
    click DB "https://github.com/AlexErrant/Pentive/tree/main/app/src/sqlite"
    click DBRep "https://github.com/AlexErrant/Pentive/blob/main/app/src/sqlite/wholeDbReplicator.ts"
    click SW "https://github.com/AlexErrant/Pentive/blob/main/app/src/serviceWorker.ts"
    click SharedCore "https://github.com/AlexErrant/Pentive/tree/main/shared"
    click SharedDom "https://github.com/AlexErrant/Pentive/tree/main/shared-dom"
    click SharedEdge "https://github.com/AlexErrant/Pentive/tree/main/shared-edge"
    click WholeDBRTC "https://github.com/AlexErrant/Pentive/blob/main/app/src/sqlite/wholeDbRtc.ts"
    click Templates "https://github.com/AlexErrant/Pentive/blob/main/app/src/components/editTemplate.tsx"
    click Study "https://github.com/AlexErrant/Pentive/blob/main/app/src/pages/study.tsx"
```
