How normancao2702/cmpt362-stocksim works
Project Type and Purpose
• This is a full-stack Android mobile application (Kotlin) built under the MVVM pattern.
• Purpose: A stock-trading simulator where users start with 10,000 USD, fetch live stock prices via the Polygon API, track profits and portfolio value, and unlock achievements. It also includes social features (posts, friends, chat).
• The app communicates with:
– Polygon external API for live stock data
– A backend service (not in this repo) managing user accounts, achievements, portfolios, social posts, chat, all persisted in a MariaDB database
File Structure Analysis
• Top-level module “app” (Gradle/Kotlin DSL) contains:
– src/main/java/com/example/cmpt362_stocksim/…
• api: BackendRepository, ViewModel, ViewModelFactory
• ui: multiple features (auth, dashboard, home, inventory, notifications, portfolio, search, social) each with Activities/Fragments and ViewModels/Adapters
• userDataManager: business-logic managers (UserDataManager, NetWorthHistoryManager)
• utils: JWT helpers
– src/main/res: all Android UI resources (layouts, drawables, navigation, themes)
– src/androidTest and src/test for instrumentation and unit tests
• Build artifacts and configuration: build.gradle.kts, proguard, gradle wrapper
README Insights
• Highlights three core layers: View (Activities/Fragments), ViewModel, Repository (data sources).
• Mentions two external data endpoints:
– Polygon API (stock quotes)
– Custom backend with MariaDB (user data, history, social)
a. Main Components
• Android Client
– UI Layer: Activities & Fragments (Login, Register, Dashboard, etc.)
– ViewModel Layer: one per feature, exposes LiveData/StateFlow
– Repository Layer: BackendRepository – single entry point for data operations
– Local Managers: UserDataManager, NetWorthHistoryManager (caching/histories)
– Utilities: JwtUtils, UserJwtData (for auth token handling)
• External Services
– Polygon API (HTTPS REST)
– Custom Backend Service (HTTPS REST)
• Auth endpoints, portfolio endpoints, achievements endpoints, social/chat endpoints
• Persistence in MariaDB
• Database
– MariaDB hosting user credentials (encrypted), transactions, achievements, posts, chat history, stock metadata
b. Relationships and Interactions
• UI → ViewModel: Two-way data binding or LiveData/observers.
• ViewModel → Repository: invokes suspend functions or Rx calls.
• Repository → External Services: Retrofit/okhttp calls to Polygon and backend.
• External Services → MariaDB: backend query/update user data.
• Repository returns domain models to ViewModel which updates UI.
• UserDataManager caches token and history locally (in memory or lightweight storage).
c. Architectural Patterns & Principles
• MVVM: clear separation of concerns (UI, state, data).
• Single Repository: encapsulates all remote data sources.
• Dependency Injection (ViewModelFactory).
• Layered architecture: UI → VM → Repo → Network/DB.
• Resource management: background threads (Coroutines) ensure non-blocking UI.
d. Technologies, Frameworks, Libraries
• Kotlin + AndroidX (Fragments, ViewModel, LiveData)
• Retrofit/OkHttp for network calls
• Coroutines for threading
• MariaDB (backend)
• Polygon REST API
• JWT for authentication
• RecyclerView Adapters for lists (search, social feed, chat)