How leohsuprogramminglab/ntuef_survey_app works
Main components
a. Presentation Layer (UI & Navigation)
• Single Activity: MainActivity
• Router: NTUEFScreen enum → controls which Composable screen to display
• Composable Screens under layout/ (e.g., SurveyScreen, PlotOptionsScreen, ResultDisplayScreen, DownloadUploadJsonScreen, SaveScreen)
• UI Widgets & Dialogs under ui/widget/ and ui/widget/dialog/
• Theme definitions under ui/theme/
b. ViewModel Layer
• SurveyViewModel (in viewModel/) — holds UI state, exposes flows/Livedata
c. Domain/Data Layer
• DataSource (in data/): orchestrates calls to network and file I/O
• Models (in model/): e.g., PlotData, TreeData
• Utilities (in utils/): FileIO (JSON read/write), Permission handlers, general Func, ButtonHandlers
d. Network/API Layer
• Retrofit configuration in RetrofitInstance
• API definitions in DatabaseApi
• Data-transfer objects under api/dataType/ grouped by endpoint (plotInfoResponse, plotsCatalogueResponse, surveyDataForUpload, uploadDataResponse, userAndConditionCodeResponse)
• Helpers in api/Utils.kt
e. Local Storage
• UI-package resources & mappings (survey.json, config.json in ui-packages/)
• Local JSON file generation via FileIO
f. External Services
• Remote database REST service (the endpoint targeted by DatabaseApi)
Relationships and data flows
• User interacts with UI Composables → UI events trigger SurveyViewModel methods
→ ViewModel invokes DataSource
→ DataSource either reads/writes local JSON via FileIO or calls DatabaseApi (Retrofit)
→ RetrofitInstance makes HTTP requests → remote DB → responses mapped to dataType objects
→ DataSource returns domain models or status back to ViewModel
→ ViewModel updates UI state → Composables re-compose to display results
Architectural patterns & design principles
• MVVM: clear separation between View (Compose UI), ViewModel, and Model/Data layers
• Single-Activity + Navigation by Router enum (NTUEFScreen)
• Dependency inversion: DataSource hides Retrofit details behind a simple interface
• Immutable data models for thread safety
• Compose theming for consistent styling
Detailed breakdown of components
• MainActivity
• hosts Compose NavHost
• Router (NTUEFScreen enum)
• defines route graph
• Screens (PlotOptionsScreen, SurveyScreen, etc.)
• UI→ViewModel calls like viewModel.loadPlots()
• SurveyViewModel
• methods: downloadPlots(), saveSurvey(), uploadJson()
• exposes StateFlows/LiveData to UI
• DataSource
• functions: getPlotsCatalogue(), getPlotInfo(), prepareSurveyJson(), uploadSurveyJson()
• DatabaseApi
• endpoints: /catalogue, /plotInfo, /uploadSurvey, /userCodes
• RetrofitInstance
• OkHttpClient, Interceptors, ConverterFactory
• FileIO
• read/write JSON to device storage
• Remote Database
• RESTful service, returns JSON