How ashik-z/microvest works
1. Overall shape
Microvest is a server-rendered FastAPI application rather than a separate frontend/backend split. Browser requests hit FastAPI routes, which fetch data from MySQL, call market-data services, and render Jinja2 templates back to the client.
2. Request entrypoint and app wiring
backend/main.py is the application bootstrap. It likely wires the FastAPI app, mounts routers, configures templates/static assets, and connects middleware/session handling. This is the top-level composition point for the whole system.
3. Configuration and runtime boundaries
backend/config.py centralizes environment-driven settings such as MySQL connection values, the secret key, and debug mode. That keeps deployment concerns separate from business logic and makes the app portable across environments.
4. Persistence layer
backend/database.py and backend/models.py define the SQLAlchemy boundary to MySQL. The data model probably includes users, watchlist entries, portfolio holdings, and transaction records, since those are the core domain objects exposed by the README features.
5. Authentication subsystem
backend/routers/auth.py and backend/services/auth_service.py handle registration, login, and session-backed access control. The README indicates secure session cookies, itsdangerous, and bcrypt/password hashing, so auth is stateful and server-managed rather than token-only API auth.
6. Dependency injection and request context
backend/dependencies.py is the glue layer for common request-scoped concerns such as obtaining a database session and resolving the currently authenticated user. This is an important architectural boundary because it keeps routers thin and consistent.
7. Watchlist and portfolio flows
backend/routers/watchlist.py and backend/routers/portfolio.py drive the two main user workflows: tracking symbols and simulating buy/sell activity. These routes likely orchestrate both database persistence and live price lookup before rendering the corresponding page.
8. Market-data service layer
backend/services/stock_service.py is the external-data boundary. The README says it uses yfinance with 60-second caching, so this service isolates market-price retrieval from the rest of the app and reduces repeated upstream calls.
9. Dashboard aggregation
backend/routers/dashboard.py is the read-heavy summary view. It likely combines portfolio valuation, profit/loss, watchlist counts, and recent transactions into a single page, making it a presentation-level aggregation over multiple database tables and stock-service calls.
10. Inflation subsystem
backend/routers/inflation.py and backend/services/inflation_service.py are a separate analytics slice from the core trading/watchlist flows. This appears to provide macro/inflation context as an additional dashboard-style view, probably backed by an external data source distinct from the stock quotes.
11. Template layer
backend/templates/ contains page templates for login, registration, dashboard, watchlist, portfolio, and inflation, all extending base.html. This confirms the app is multi-page, server-rendered, with Tailwind/Alpine used for styling and light interactivity rather than a SPA framework.
12. Typical data flow
A request usually flows as: browser → router → dependency resolution (DB/user) → service layer → MySQL and/or external market data → template rendering → browser response. The important architectural distinction is that routers coordinate, services encapsulate business/external logic, and models/database handle persistence.
13. External dependencies that shape the design
The main external systems are MySQL for persistence and yfinance for live stock data. Their presence drives the separation between database models, cached market-data service logic, and the server-rendered pages that present the results.
Main entry points: main.py App bootstrap · base.html Base layout · database.py DB session · auth.py Auth routes
Components 22
Backend App
FastAPI application wiring, routes, services, and shared runtime code.
- App bootstrap · Creates and configures the application, routers, templates, and middleware.
backend/main.py - Settings · Environment-driven configuration such as DB credentials, secret key, and debug mode.
backend/config.py - Dependencies · Shared request-scoped helpers for database sessions and current user resolution.
backend/dependencies.py - Auth routes · Registration, login, logout, and session-based access control endpoints.
backend/routers/auth.py - Dashboard · Aggregated summary view combining portfolio, watchlist, and transaction data.
backend/routers/dashboard.py - Watchlist · Routes for tracking symbols and displaying watchlist state.
backend/routers/watchlist.py - Portfolio · Routes for buy/sell simulation and portfolio views.
backend/routers/portfolio.py - Inflation · Routes for macro and inflation analytics pages.
backend/routers/inflation.py - Auth service · Implements user authentication, password handling, and login/session logic.
backend/services/auth_service.py - Stock service · Fetches live stock prices with caching to reduce upstream calls.
backend/services/stock_service.py - Inflation service · Loads inflation or macroeconomic data for the analytics views.
backend/services/inflation_service.py
Data Layer
Database boundary and domain models persisted in MySQL.
- DB session · Database engine/session boundary used by the application to reach MySQL.
backend/database.py - Domain models · SQLAlchemy models for users, watchlists, portfolios, and transactions.
backend/models.py
Templates
Server-rendered Jinja2 pages returned to the browser.
- Base layout · Shared page shell extended by all rendered views.
backend/templates/base.html - Login page · Sign-in form and authentication page.
backend/templates/login.html - Register page · User registration form.
backend/templates/register.html - Dashboard page · Server-rendered portfolio summary page.
backend/templates/dashboard.html - Watchlist page · Server-rendered symbol tracking page.
backend/templates/watchlist.html - Portfolio page · Server-rendered holdings and trade page.
backend/templates/portfolio.html - Inflation page · Server-rendered macro and inflation analytics page.
backend/templates/inflation.html
External Systems
Outside services and infrastructure the app depends on.
- MySQL · Primary persistence store for application data.
- yfinance · External source for live stock quotes and related market data.
Connections 32
- App bootstrap → Settings: loads · Application startup reads environment settings.
- App bootstrap → Dependencies: wires · Registers shared dependency helpers.
- App bootstrap → Auth routes: mounts · Adds authentication routes to the app.
- App bootstrap → Dashboard: mounts · Adds dashboard routes to the app.
- App bootstrap → Watchlist: mounts · Adds watchlist routes to the app.
- App bootstrap → Portfolio: mounts · Adds portfolio routes to the app.
- App bootstrap → Inflation: mounts · Adds inflation routes to the app.
- App bootstrap → Base layout: configures · Sets up template rendering for responses.
- Auth routes → Auth service: uses · Delegates authentication logic to the service layer.
- Auth routes → Login page: renders · Returns the login page.
- Auth routes → Register page: renders · Returns the registration page.
- Dashboard → Stock service: uses · Fetches live market data for summary calculations.
- Dashboard → Dashboard page: renders · Returns the dashboard page.
- Watchlist → Stock service: uses · Looks up current prices for tracked symbols.
- Watchlist → Watchlist page: renders · Returns the watchlist page.
- Portfolio → Stock service: uses · Uses quotes for valuation and trade simulation.
- Portfolio → Portfolio page: renders · Returns the portfolio page.
- Inflation → Inflation service: uses · Loads inflation analytics data.
- Inflation → Inflation page: renders · Returns the inflation page.
- Auth service → DB session: queries · Reads and writes authentication-related state.
- Dashboard → DB session: queries · Reads persisted portfolio and activity data.
- Watchlist → DB session: queries · Reads and updates watchlist entries.
- Portfolio → DB session: queries · Reads and updates portfolio and transaction records.
- Inflation service → DB session: optional read · May use persisted settings or cached analytics state.
- DB session → Domain models: maps to · ORM layer defines persisted entities.
- Stock service → yfinance: fetches from · Retrieves market data from the external provider.
- Dashboard page → Base layout: extends · Shares the common layout.
- Login page → Base layout: extends · Shares the common layout.
- Register page → Base layout: extends · Shares the common layout.
- Watchlist page → Base layout: extends · Shares the common layout.
- Portfolio page → Base layout: extends · Shares the common layout.
- Inflation page → Base layout: extends · Shares the common layout.