How the-brotherhood-of-scu/bugaoshan works
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: home_page.dart Home page · app.dart App · api_request.dart Campus APIs · database_service.dart Local services
Components 23
App shell
Flutter entrypoint, composition, localization, theme, and dependency wiring.
- main.dart · App startup entrypoint.
lib/main.dart - App · Assembles app-wide concerns such as theme, localization, and routing.
lib/app.dart - Injector · Dependency wiring and generated injector setup.
lib/injection/injector.dart - Localizations · Generated localization classes and ARB-backed translations.
lib/l10n/app_localizations.dart - Theme · 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 · First-run onboarding, EULA gate, login, and widget setup.
lib/pages/wizard/wizard_page.dart - Home page · Main app landing page that routes into major areas.
lib/pages/home_page.dart - Course pages · Course viewing, editing, import, and schedule management pages.
lib/pages/course/course_page.dart - Campus pages · University service pages for notices, balance, grades, classroom, and more.
lib/pages/campus_page/campus_page.dart - Profile page · Login status, user info, and account-facing controls.
lib/pages/profile/profile_page.dart - Settings · Personalization, display, language, icon, and widget setup pages.
lib/pages/settings/software_setting_page.dart - Dev tools · 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 · Coordinates course state, schedule operations, and export support.
lib/providers/course_provider.dart - Auth provider · Exposes authentication/session state to the UI.
lib/providers/scu_auth_provider.dart - Campus providers · 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 · Multi-domain login coordination, session handling, and secure storage.
lib/services/auth/auth_coordinator.dart - Campus APIs · Shared request layer and campus-system API clients.
lib/services/api/api_request.dart - Local services · Database, downloads, calendar export/import, OCR, updates, cache, and platform behavior.
lib/services/database_service.dart - Widget service · Flutter-side course widget update coordination.
lib/services/widget_update_service.dart
Platform shells
Native runners and Android widget integration.
- Android widget · 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 · iOS bootstrap and embedder code.
ios/Runner/AppDelegate.swift - Desktop runners · Linux, macOS, and Windows runner bootstrap layers.
linux/runner/main.cc
Release automation
Build, release, and tagging automation.
- Release flow · GitHub Actions and scripts for builds, changelogs, releases, and tagging.
.github/workflows/release.yml
Connections 29
- 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.