# the-brotherhood-of-scu/bugaoshan architecture

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

- Interactive diagram: https://gitdiagram.com/the-brotherhood-of-scu/bugaoshan
- Repository: https://github.com/the-brotherhood-of-scu/bugaoshan

## Overview

1. **Repository shape**
   - This is a **Flutter 3.44 / Dart 3.10** multi-platform client for SCU students.
   - The shared app logic lives in `lib/`, while platform shells exist for **Android, iOS, macOS, Linux, Windows, and web**.
   - The only substantial native code is the **Android home-screen widget** implementation under `android/app/src/main/kotlin/...`.

2. **App shell and composition**
   - `lib/main.dart` and `lib/app.dart` are the entry points for the Flutter UI.
   - Dependency wiring is centralized in `lib/injection/` with generated injector config.
   - Global concerns such as **theme**, **localization**, and app-wide configuration are assembled here before feature pages are shown.

3. **UI architecture: feature pages + shared widgets**
   - The UI is organized by feature under `lib/pages/`.
   - Major top-level areas are:
     - `course/` for timetable management
     - `campus/` for campus services
     - `profile/` for user/account state
     - `settings/` for personalization and widget setup
     - `wizard/` for first-run onboarding and EULA gating
     - `dev/` for diagnostics and internal tools
   - Common visual building blocks live in `lib/widgets/`, separated into course-specific, dialog, route, and general-purpose components.

4. **State boundary**
   - `lib/providers/` acts as the bridge between UI and backend logic.
   - Providers cover areas like **course data, authentication, balances, grades, train program, plan completion, app config, theme color, and user info**.
   - The architecture appears to use a **service/provider split**: pages render state, providers coordinate it, and services perform the actual IO or computation.

5. **Authentication subsystem**
   - Authentication is a first-class subsystem under `lib/services/auth/`.
   - It coordinates multiple SCU-related login domains: **SCU main auth, ZHJW, WFW, PayApp, CCYL, fitness**, and an **SSO relay**.
   - `auth_coordinator.dart` likely arbitrates login/session state across those subsystems, while `cookie_client.dart` suggests session persistence via cookies.
   - `secure_storage.dart` and `auth_logger.dart` support storing credentials/session tokens and recording login flow events.

6. **Backend/API layer**
   - Remote communication is isolated in `lib/services/api/`.
   - The repo has separate services for distinct campus systems, such as:
     - `zhjw_api_service.dart` for academic systems
     - `wfw_api_service.dart` for campus network/water-related services
     - `payapp_api_service.dart` for wallet/balance-related endpoints
     - `ccyl_api_service.dart` for the second-classroom platform
   - `api_request.dart` is the shared request abstraction, so feature services likely build on a common transport/error model.

7. **Domain services and local infrastructure**
   - `lib/services/` also contains non-API services that support app behavior:
     - `database_service.dart` for local persistence
     - `download_manager.dart` for attachment/file downloads
     - `ics_service.dart` and calendar utils for export/import of schedule data
     - `ocr_service.dart` backed by `assets/universal-login-ocr.tflite`
     - `update_checker.dart` / `update_service.dart` for release checks
     - `background_cache_service.dart`, `dynamic_icon_service.dart`, and `window_state_service.dart` for runtime/platform behavior
   - These services form the app’s local execution layer and hide platform-specific details from the UI.

8. **Course scheduling as a core domain**
   - Course management is one of the most developed subsystems.
   - Pages under `lib/pages/course/` handle **viewing, editing, importing, schedule settings, time-slot settings, and management**.
   - Shared course rendering logic lives in `lib/widgets/course/`, which contains the grid, day columns, sections, detail sheets, and special-day overlays.
   - This subsystem also feeds the widget/export functionality, making course data a central shared model.

9. **Campus feature cluster**
   - `lib/pages/campus/` groups the rest of the university services:
     - notices and attachment downloads
     - balance queries
     - classroom availability
     - exam plan
     - fitness test
     - network device management
     - grades
     - train program / plan completion
     - academic calendar
     - CCYL / second classroom flows
   - The notice area is notable because it includes both **webview-based notice browsing** and **downloaded attachment handling**, suggesting a hybrid browser + native file workflow.

10. **Widget system**
   - The app includes an Android home-screen widget for course schedules.
   - Native Kotlin classes such as `CourseGlanceWidget`, `WidgetUpdateWorker`, `WidgetAlarmManager`, `WidgetAlarmReceiver`, and `BootReceiver` indicate:
     - periodic/background refresh
     - boot re-registration
     - alarm-based scheduling
     - widget updates driven from app state
   - Flutter-side settings pages under `lib/pages/settings/add_widget/` guide the user through widget size and battery-optimization setup.

11. **Platform-specific boundaries**
   - Android, iOS, macOS, Linux, Windows, and web are all present, but most business logic is shared in Flutter.
   - Platform folders mainly contain runner/bootstrap code and packaging configuration.
   - Android is the only platform with substantial custom native logic because of the widget integration.

12. **Localization, theming, and generated assets**
   - Locales are maintained via `l10n.yaml` and ARB files under `lib/l10n/`, with generated localization classes checked in.
   - Theme and style control live in `lib/theme.dart` plus settings pages for language, font, theme color, icon, dock, and display behavior.
   - Static assets include EULA text, webview helper HTML, JavaScript beautifiers for notice pages, and icons/resources for the widget and app branding.

13. **Release and automation boundary**
   - GitHub Actions handles platform builds for **Android, Linux, and Windows**, plus release orchestration.
   - Additional scripts under `.github/scripts/` generate changelog/release metadata, and `update_and_push_tag.py` supports tagging/release flow.
   - The repo is set up for repeatable app distribution rather than just local development.

14. **How to draw the architecture**
   - A good diagram would show:
     - Flutter UI pages at the top
     - Providers as the state/coordination layer
     - Services split into auth, API, persistence, downloads, updates, and widget support
     - External SCU campus systems as multiple backend targets
     - Native Android widget services as a separate platform boundary
   - The key cross-cutting flows are: **login/session establishment → provider state → feature pages**, and **course data → local storage/widget/export**.

Main entry points: [`lib/pages/home_page.dart`](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/home_page.dart) (Home page), [`lib/app.dart`](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/app.dart) (App), [`lib/services/api/api_request.dart`](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/api/api_request.dart) (Campus APIs), [`lib/services/database_service.dart`](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/database_service.dart) (Local services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_app["App shell"]
  node_main["main.dart<br/>flutter entry<br/>[main.dart]"]
  node_app["App<br/>composition root<br/>[app.dart]"]
  node_injector["Injector<br/>di config<br/>[injector.dart]"]
  node_l10n["Localizations<br/>generated i18n"]
  node_theme["Theme<br/>style system<br/>[theme.dart]"]
end

subgraph group_g_ui["UI features"]
  node_wizard["Wizard<br/>onboarding flow<br/>[wizard_page.dart]"]
  node_home["Home page<br/>navigation hub<br/>[home_page.dart]"]
  node_course_ui["Course pages<br/>feature area<br/>[course_page.dart]"]
  node_campus_ui["Campus pages<br/>feature area<br/>[campus_page.dart]"]
  node_profile_ui["Profile page<br/>account area<br/>[profile_page.dart]"]
  node_settings_ui["Settings<br/>preferences area"]
  node_dev_ui["Dev tools<br/>diagnostics area<br/>[dev_page.dart]"]
end

subgraph group_g_state["State boundary"]
  node_course_provider["Course provider<br/>state coordinator"]
  node_auth_provider["Auth provider<br/>state coordinator"]
  node_campus_providers["Campus providers<br/>state coordinators"]
end

subgraph group_g_services["Services"]
  node_auth["Auth system<br/>service subsystem"]
  node_api["Campus APIs<br/>service subsystem<br/>[api_request.dart]"]
  node_local["Local services<br/>runtime services"]
  node_widget_svc["Widget service<br/>platform bridge"]
end

subgraph group_g_platform["Platform shells"]
  node_android_widget["Android widget<br/>native integration"]
  node_ios_shell["iOS runner<br/>platform shell<br/>[AppDelegate.swift]"]
  node_desktop_shell["Desktop runners<br/>platform shells<br/>[main.cc]"]
end

subgraph group_g_release["Release automation"]
  node_release["Release flow<br/>automation<br/>[release.yml]"]
end

node_main -->|"boots"| node_app
node_app -->|"wires"| node_injector
node_app -->|"loads"| node_l10n
node_app -->|"applies"| node_theme
node_app -->|"navigates"| node_home
node_home -.->|"routes to"| node_wizard
node_home -->|"opens"| node_course_ui
node_home -->|"opens"| node_campus_ui
node_home -->|"opens"| node_profile_ui
node_home -->|"opens"| node_settings_ui
node_home -->|"opens"| node_dev_ui
node_wizard -->|"auth gates"| node_auth_provider
node_course_ui -->|"reads/writes"| node_course_provider
node_campus_ui -->|"reads/writes"| node_campus_providers
node_profile_ui -->|"reflects"| node_auth_provider
node_settings_ui -->|"configures"| node_widget_svc
node_course_provider -->|"fetches"| node_api
node_campus_providers -->|"fetches"| node_api
node_auth_provider -->|"coordinates"| node_auth
node_auth -->|"logs in via"| node_api
node_auth -->|"persists"| node_local
node_api -->|"uses"| node_local
node_course_provider -->|"exports"| node_local
node_widget_svc -->|"updates"| node_android_widget
node_local -.->|"supports"| node_android_widget
node_android_widget -.->|"shipped with"| node_release
node_ios_shell -->|"hosts"| node_app
node_desktop_shell -->|"hosts"| node_app
node_release -.->|"builds"| node_android_widget

click node_main "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/main.dart"
click node_app "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/app.dart"
click node_injector "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/injection/injector.dart"
click node_l10n "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/l10n/app_localizations.dart"
click node_theme "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/theme.dart"
click node_wizard "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/wizard/wizard_page.dart"
click node_home "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/home_page.dart"
click node_course_ui "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/course/course_page.dart"
click node_campus_ui "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/campus_page/campus_page.dart"
click node_profile_ui "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/profile/profile_page.dart"
click node_settings_ui "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/settings/software_setting_page.dart"
click node_dev_ui "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/dev/dev_page.dart"
click node_course_provider "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/providers/course_provider.dart"
click node_auth_provider "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/providers/scu_auth_provider.dart"
click node_campus_providers "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/providers/balance_query_provider.dart"
click node_auth "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/auth/auth_coordinator.dart"
click node_api "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/api/api_request.dart"
click node_local "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/database_service.dart"
click node_widget_svc "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/widget_update_service.dart"
click node_android_widget "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/android/app/src/main/kotlin/io/github/the_brotherhood_of_scu/bugaoshan/CourseGlanceWidget.kt"
click node_ios_shell "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/ios/Runner/AppDelegate.swift"
click node_desktop_shell "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/linux/runner/main.cc"
click node_release "https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/.github/workflows/release.yml"

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_main,node_app,node_injector,node_l10n,node_theme toneBlue
class node_wizard,node_home,node_course_ui,node_campus_ui,node_profile_ui,node_settings_ui,node_dev_ui toneAmber
class node_course_provider,node_auth_provider,node_campus_providers toneMint
class node_auth,node_api,node_local,node_widget_svc toneRose
class node_android_widget,node_ios_shell,node_desktop_shell toneIndigo
class node_release toneTeal
```

## Components

### App shell

Flutter entrypoint, composition, localization, theme, and dependency wiring.

- [main.dart](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/main.dart): flutter entry · App startup entrypoint. · `lib/main.dart`
- [App](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/app.dart): composition root · Assembles app-wide concerns such as theme, localization, and routing. · `lib/app.dart`
- [Injector](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/injection/injector.dart): di config · Dependency wiring and generated injector setup. · `lib/injection/injector.dart`
- [Localizations](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/l10n/app_localizations.dart): generated i18n · Generated localization classes and ARB-backed translations. · `lib/l10n/app_localizations.dart`
- [Theme](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/theme.dart): style system · App-wide theme and visual styling control. · `lib/theme.dart`

### UI features

Feature pages and shared widgets that make up the student-facing app.

- [Wizard](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/wizard/wizard_page.dart): onboarding flow · First-run onboarding, EULA gate, login, and widget setup. · `lib/pages/wizard/wizard_page.dart`
- [Home page](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/home_page.dart): navigation hub · Main app landing page that routes into major areas. · `lib/pages/home_page.dart`
- [Course pages](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/course/course_page.dart): feature area · Course viewing, editing, import, and schedule management pages. · `lib/pages/course/course_page.dart`
- [Campus pages](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/campus_page/campus_page.dart): feature area · University service pages for notices, balance, grades, classroom, and more. · `lib/pages/campus_page/campus_page.dart`
- [Profile page](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/profile/profile_page.dart): account area · Login status, user info, and account-facing controls. · `lib/pages/profile/profile_page.dart`
- [Settings](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/settings/software_setting_page.dart): preferences area · Personalization, display, language, icon, and widget setup pages. · `lib/pages/settings/software_setting_page.dart`
- [Dev tools](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/pages/dev/dev_page.dart): diagnostics area · Internal tooling for auth logs, updates, changelog, and environment info. · `lib/pages/dev/dev_page.dart`

### State boundary

Providers that bridge pages to services and shared app state.

- [Course provider](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/providers/course_provider.dart): state coordinator · Coordinates course state, schedule operations, and export support. · `lib/providers/course_provider.dart`
- [Auth provider](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/providers/scu_auth_provider.dart): state coordinator · Exposes authentication/session state to the UI. · `lib/providers/scu_auth_provider.dart`
- [Campus providers](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/providers/balance_query_provider.dart): state coordinators · Providers for balances, grades, CCYL, train program, plan completion, and user info. · `lib/providers/balance_query_provider.dart`

### Services

Authentication, campus APIs, persistence, exports, updates, and runtime support.

- [Auth system](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/auth/auth_coordinator.dart): service subsystem · Multi-domain login coordination, session handling, and secure storage. · `lib/services/auth/auth_coordinator.dart`
- [Campus APIs](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/api/api_request.dart): service subsystem · Shared request layer and campus-system API clients. · `lib/services/api/api_request.dart`
- [Local services](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/database_service.dart): runtime services · Database, downloads, calendar export/import, OCR, updates, cache, and platform behavior. · `lib/services/database_service.dart`
- [Widget service](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/lib/services/widget_update_service.dart): platform bridge · Flutter-side course widget update coordination. · `lib/services/widget_update_service.dart`

### Platform shells

Native runners and Android widget integration.

- [Android widget](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/android/app/src/main/kotlin/io/github/the_brotherhood_of_scu/bugaoshan/CourseGlanceWidget.kt): native integration · Home-screen course widget, alarms, boot handling, and update worker. · `android/app/src/main/kotlin/io/github/the_brotherhood_of_scu/bugaoshan/CourseGlanceWidget.kt`
- [iOS runner](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/ios/Runner/AppDelegate.swift): platform shell · iOS bootstrap and embedder code. · `ios/Runner/AppDelegate.swift`
- [Desktop runners](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/linux/runner/main.cc): platform shells · Linux, macOS, and Windows runner bootstrap layers. · `linux/runner/main.cc`

### Release automation

Build, release, and tagging automation.

- [Release flow](https://github.com/the-brotherhood-of-scu/bugaoshan/blob/main/.github/workflows/release.yml): automation · GitHub Actions and scripts for builds, changelogs, releases, and tagging. · `.github/workflows/release.yml`

## Connections

- main.dart → App: boots · Application startup enters shared app composition.
- App → Injector: wires · App composition resolves dependencies through generated injector setup.
- App → Localizations: loads · App-wide localization is assembled before feature pages render.
- App → Theme: applies · Theme and visual style are initialized at the app root.
- App → Home page: navigates · Root UI exposes the main navigation hub.
- Home page → Wizard: routes to · First-run and gating flows are reachable from app navigation.
- Home page → Course pages: opens · Main navigation enters course management.
- Home page → Campus pages: opens · Main navigation enters campus services.
- Home page → Profile page: opens · Main navigation enters account state.
- Home page → Settings: opens · Main navigation enters settings.
- Home page → Dev tools: opens · Main navigation enters diagnostics and internal tools.
- Wizard → Auth provider: auth gates · Onboarding and login flows establish user session state.
- Course pages → Course provider: reads/writes · Course pages coordinate state through the course provider.
- Campus pages → Campus providers: reads/writes · Campus feature pages are driven by dedicated providers.
- Profile page → Auth provider: reflects · Profile state shows login/session status.
- Settings → Widget service: configures · Settings include course widget setup and runtime preferences.
- Course provider → Campus APIs: fetches · Course state depends on campus API clients and shared request transport.
- Campus providers → Campus APIs: fetches · Campus domains obtain remote data through the API layer.
- Auth provider → Auth system: coordinates · Provider delegates session handling to the authentication subsystem.
- Auth system → Campus APIs: logs in via · Authentication reaches multiple SCU campus domains through service clients.
- Auth system → Local services: persists · Credentials, tokens, and auth flow state are stored locally and logged.
- Campus APIs → Local services: uses · Remote-facing services rely on local support for downloads and storage.
- Course provider → Local services: exports · Course data feeds calendar/export and local persistence flows.
- Widget service → Android widget: updates · Flutter-side widget settings drive the Android widget integration.
- Local services → Android widget: supports · Background cache, update logic, and platform behavior support widget refreshes.
- Android widget → Release flow: shipped with · Native widget code is packaged through the repository release pipeline.
- iOS runner → App: hosts · iOS runner hosts the shared Flutter application.
- Desktop runners → App: hosts · Desktop runners host the shared Flutter application.
- Release flow → Android widget: builds · Release automation includes platform build and packaging support.
