# fks-benri-app/benriapp architecture

> Architecture diagram of the GitHub repository fks-benri-app/benriapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fks-benri-app/benriapp
- Repository: https://github.com/fks-benri-app/benriapp

## Overview

BenriApp is a React PWA for receiving and browsing Google Classroom announcements. The student flow links a school account through GAS, signs into Firebase, enables push notifications, then views announcements and their details; GAS detects new posts and sends notifications. Other documented capabilities include per-class notification preferences, an editable home gadget layout, offline announcement caching, and experimental timetable OCR. The graph includes these domain stages and supporting storage/theme layers. Some subsystem implementations were not excerpted, so their internal connections are omitted; README-described external flows are cited there.

Main entry points: [`src/App.jsx`](https://github.com/fks-benri-app/benriapp/blob/main/src/App.jsx) (App routes), [`src/lib/announcements.js`](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/announcements.js) (Announcement access and cache), [`src/pages/LinkPage.jsx`](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/LinkPage.jsx) (Link and permissions), [`src/pages/Class.jsx`](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Class.jsx) (Announcement list and detail)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_account["Account and app shell"]
  node_app["App routes<br/>[App.jsx]"]
  node_identity["Identity session<br/>[identity.jsx]"]
  node_firebase_auth["Firebase Auth<br/>[firebase.js]"]
  node_settings["Account settings<br/>[Settings.jsx]"]
  node_local_storage[("Device storage<br/>[storage.js]")]
  node_link["Link and permissions<br/>[LinkPage.jsx]"]
end

subgraph group_classroom["Announcements"]
  node_class_page["Announcement list and detail<br/>[Class.jsx]"]
  node_announcement_data["Announcement access and cache<br/>[announcements.js]"]
  node_firestore["Lazy Firestore access<br/>[firestoreLazy.js]"]
  node_live_store["Live user data<br/>[liveStore.js]"]
  node_filters["Announcement filters<br/>[filters.js]"]
end

subgraph group_push["Push notifications"]
  node_notify_settings["Class notification preferences<br/>[NotifySettings.jsx]"]
  node_notify_prefs["Preference access<br/>[notifyPrefs.js]"]
  node_push_status["Push health and repair<br/>[pushStatus.js]"]
  node_onesignal["OneSignal subscription<br/>[onesignal.js]"]
  node_fcm["FCM messaging<br/>[fcm.js]"]
  node_push_service["Push services"]
end

subgraph group_home["Home gadgets"]
  node_home_page["Home layout editor<br/>[Home.jsx]"]
  node_gadget_registry["Gadget registry<br/>[index.js]"]
  node_class_gadget["Announcement gadget"]
  node_next_gadget["Next class gadget"]
  node_layout["Layout persistence<br/>[homeLayout.js]"]
end

subgraph group_ocr["Timetable OCR"]
  node_ocr_page["Timetable test screen<br/>[OcrTest.jsx]"]
  node_ocr_engine["PaddleOCR runtime<br/>[paddleOcr.js]"]
  node_timetable_grid["Timetable grid builder<br/>[timetableGrid.js]"]
  node_timetable_match["Course matching<br/>[timetableMatch.js]"]
end

node_student(("Student"))
node_gas["GAS login and notifier"]

node_student -->|"starts linking"| node_link
node_link -->|"requests school login"| node_gas
node_gas -->|"returns login token"| node_identity
node_identity -->|"signs in"| node_firebase_auth
node_identity -->|"persists identity"| node_local_storage
node_app -->|"checks session"| node_identity
node_link -->|"initializes and subscribes"| node_onesignal
node_link -->|"checks push key"| node_push_status
node_gas -->|"sends notifications"| node_push_service
node_push_service -->|"delivers push"| node_student
node_app -->|"starts foreground listener"| node_fcm
node_fcm -.->|"uses subscription integration"| node_onesignal
node_app -->|"routes to announcements"| node_class_page
node_class_page -->|"loads and marks read"| node_announcement_data
node_announcement_data -->|"reads and updates"| node_firestore
node_announcement_data -->|"watches live data"| node_live_store
node_announcement_data -->|"caches announcements"| node_local_storage
node_class_page -->|"filters announcements"| node_filters
node_class_page -->|"checks repair state"| node_push_status
node_notify_settings -->|"manages class preferences"| node_notify_prefs
node_notify_settings -->|"reads device subscription"| node_onesignal
node_settings -->|"uses preferences"| node_notify_prefs
node_app -->|"routes home"| node_home_page
node_home_page -->|"loads gadget definitions"| node_gadget_registry
node_home_page -->|"loads and saves layout"| node_layout
node_layout -->|"persists layout"| node_local_storage
node_gadget_registry -->|"registers component"| node_class_gadget
node_gadget_registry -->|"registers component"| node_next_gadget
node_class_gadget -->|"reads announcements"| node_announcement_data
node_app -->|"routes test screen"| node_ocr_page
node_ocr_page -->|"runs OCR"| node_ocr_engine
node_ocr_page -->|"builds timetable"| node_timetable_grid
node_ocr_page -->|"matches course names"| node_timetable_match
node_timetable_grid -->|"uses matching"| node_timetable_match

click node_app "https://github.com/fks-benri-app/benriapp/blob/main/src/App.jsx"
click node_identity "https://github.com/fks-benri-app/benriapp/blob/main/src/auth/identity.jsx"
click node_firebase_auth "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/firebase.js"
click node_settings "https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Settings.jsx"
click node_local_storage "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/storage.js"
click node_link "https://github.com/fks-benri-app/benriapp/blob/main/src/pages/LinkPage.jsx"
click node_class_page "https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Class.jsx"
click node_announcement_data "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/announcements.js"
click node_firestore "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/firestoreLazy.js"
click node_live_store "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/liveStore.js"
click node_filters "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/filters.js"
click node_notify_settings "https://github.com/fks-benri-app/benriapp/blob/main/src/pages/NotifySettings.jsx"
click node_notify_prefs "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/notifyPrefs.js"
click node_push_status "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/pushStatus.js"
click node_onesignal "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/onesignal.js"
click node_fcm "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/fcm.js"
click node_home_page "https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Home.jsx"
click node_gadget_registry "https://github.com/fks-benri-app/benriapp/blob/main/src/gadgets/index.js"
click node_class_gadget "https://github.com/fks-benri-app/benriapp/blob/main/src/gadgets/ClassNoticesGadget.jsx"
click node_next_gadget "https://github.com/fks-benri-app/benriapp/blob/main/src/gadgets/NextClassGadget.jsx"
click node_layout "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/homeLayout.js"
click node_ocr_page "https://github.com/fks-benri-app/benriapp/blob/main/src/pages/OcrTest.jsx"
click node_ocr_engine "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/paddleOcr.js"
click node_timetable_grid "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/timetableGrid.js"
click node_timetable_match "https://github.com/fks-benri-app/benriapp/blob/main/src/lib/timetableMatch.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_identity,node_firebase_auth,node_settings,node_local_storage,node_link toneBlue
class node_class_page,node_announcement_data,node_firestore,node_live_store,node_filters toneAmber
class node_notify_settings,node_notify_prefs,node_push_status,node_onesignal,node_fcm,node_push_service toneMint
class node_home_page,node_gadget_registry,node_class_gadget,node_next_gadget,node_layout toneRose
class node_ocr_page,node_ocr_engine,node_timetable_grid,node_timetable_match,node_student,node_gas toneIndigo
```

## Components

### Account and app shell

- [App routes](https://github.com/fks-benri-app/benriapp/blob/main/src/App.jsx): `src/App.jsx`
- [Identity session](https://github.com/fks-benri-app/benriapp/blob/main/src/auth/identity.jsx): `src/auth/identity.jsx`
- [Firebase Auth](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/firebase.js): `src/lib/firebase.js`
- [Account settings](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Settings.jsx): `src/pages/Settings.jsx`
- [Device storage](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/storage.js): `src/lib/storage.js`
- [Link and permissions](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/LinkPage.jsx): `src/pages/LinkPage.jsx`

### Announcements

- [Announcement list and detail](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Class.jsx): `src/pages/Class.jsx`
- [Announcement access and cache](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/announcements.js): `src/lib/announcements.js`
- [Lazy Firestore access](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/firestoreLazy.js): `src/lib/firestoreLazy.js`
- [Live user data](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/liveStore.js): `src/lib/liveStore.js`
- [Announcement filters](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/filters.js): `src/lib/filters.js`

### Push notifications

- [Class notification preferences](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/NotifySettings.jsx): `src/pages/NotifySettings.jsx`
- [Preference access](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/notifyPrefs.js): `src/lib/notifyPrefs.js`
- [Push health and repair](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/pushStatus.js): `src/lib/pushStatus.js`
- [OneSignal subscription](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/onesignal.js): `src/lib/onesignal.js`
- [FCM messaging](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/fcm.js): `src/lib/fcm.js`
- **Push services**

### Home gadgets

- [Home layout editor](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/Home.jsx): `src/pages/Home.jsx`
- [Gadget registry](https://github.com/fks-benri-app/benriapp/blob/main/src/gadgets/index.js): `src/gadgets/index.js`
- [Announcement gadget](https://github.com/fks-benri-app/benriapp/blob/main/src/gadgets/ClassNoticesGadget.jsx): `src/gadgets/ClassNoticesGadget.jsx`
- [Next class gadget](https://github.com/fks-benri-app/benriapp/blob/main/src/gadgets/NextClassGadget.jsx): `src/gadgets/NextClassGadget.jsx`
- [Layout persistence](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/homeLayout.js): `src/lib/homeLayout.js`

### Timetable OCR

- [Timetable test screen](https://github.com/fks-benri-app/benriapp/blob/main/src/pages/OcrTest.jsx): `src/pages/OcrTest.jsx`
- [PaddleOCR runtime](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/paddleOcr.js): `src/lib/paddleOcr.js`
- [Timetable grid builder](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/timetableGrid.js): `src/lib/timetableGrid.js`
- [Course matching](https://github.com/fks-benri-app/benriapp/blob/main/src/lib/timetableMatch.js): `src/lib/timetableMatch.js`

### Other components

- **Student**
- **GAS login and notifier**

## Connections

- Student → Link and permissions: starts linking
- Link and permissions → GAS login and notifier: requests school login
- GAS login and notifier → Identity session: returns login token
- Identity session → Firebase Auth: signs in (evidence: `src/auth/identity.jsx`)
- Identity session → Device storage: persists identity (evidence: `src/auth/identity.jsx`)
- App routes → Identity session: checks session (evidence: `src/App.jsx`)
- Link and permissions → OneSignal subscription: initializes and subscribes (evidence: `src/pages/LinkPage.jsx`)
- Link and permissions → Push health and repair: checks push key (evidence: `src/pages/LinkPage.jsx`)
- GAS login and notifier → Push services: sends notifications
- Push services → Student: delivers push
- App routes → FCM messaging: starts foreground listener (evidence: `src/App.jsx`)
- FCM messaging → OneSignal subscription: uses subscription integration (evidence: `src/lib/fcm.js`)
- App routes → Announcement list and detail: routes to announcements (evidence: `src/App.jsx`)
- Announcement list and detail → Announcement access and cache: loads and marks read (evidence: `src/pages/Class.jsx`)
- Announcement access and cache → Lazy Firestore access: reads and updates (evidence: `src/lib/announcements.js`)
- Announcement access and cache → Live user data: watches live data (evidence: `src/lib/announcements.js`)
- Announcement access and cache → Device storage: caches announcements (evidence: `src/lib/announcements.js`)
- Announcement list and detail → Announcement filters: filters announcements (evidence: `src/pages/Class.jsx`)
- Announcement list and detail → Push health and repair: checks repair state (evidence: `src/pages/Class.jsx`)
- Class notification preferences → Preference access: manages class preferences (evidence: `src/pages/NotifySettings.jsx`)
- Class notification preferences → OneSignal subscription: reads device subscription (evidence: `src/pages/NotifySettings.jsx`)
- Account settings → Preference access: uses preferences (evidence: `src/pages/Settings.jsx`)
- App routes → Home layout editor: routes home (evidence: `src/App.jsx`)
- Home layout editor → Gadget registry: loads gadget definitions (evidence: `src/pages/Home.jsx`)
- Home layout editor → Layout persistence: loads and saves layout (evidence: `src/pages/Home.jsx`)
- Layout persistence → Device storage: persists layout (evidence: `src/lib/homeLayout.js`)
- Gadget registry → Announcement gadget: registers component (evidence: `src/gadgets/index.js`)
- Gadget registry → Next class gadget: registers component (evidence: `src/gadgets/index.js`)
- Announcement gadget → Announcement access and cache: reads announcements (evidence: `src/gadgets/ClassNoticesGadget.jsx`)
- App routes → Timetable test screen: routes test screen (evidence: `src/App.jsx`)
- Timetable test screen → PaddleOCR runtime: runs OCR (evidence: `src/pages/OcrTest.jsx`)
- Timetable test screen → Timetable grid builder: builds timetable (evidence: `src/pages/OcrTest.jsx`)
- Timetable test screen → Course matching: matches course names (evidence: `src/pages/OcrTest.jsx`)
- Timetable grid builder → Course matching: uses matching (evidence: `src/lib/timetableGrid.js`)
