How mo-ri-ch/marketpulseai works
1. Top-level shape
- This repo is a two-tier application: a FastAPI backend in backend/ and a Next.js + TypeScript frontend in frontend/.
- docker-compose.yml and the two Dockerfiles indicate the system is designed to run as separate containers with a clear API/UI boundary.
2. User-facing UI
- The frontend uses the Next.js App Router (frontend/src/app) with a login page and a main dashboard page.
- The dashboard is composed from focused panels: WatchlistPanel, BreakingNews, AISummaryPanel, MarketSummary, SentimentPanel, AlertsPanel, and StockAnalysisModal.
- This strongly suggests a single-screen information dashboard where each panel is fed by backend data rather than client-side computation.
3. Backend API layer
- backend/main.py is the FastAPI entrypoint; backend/routers/watchlist.py is the only explicit router in the tree, so the exposed API surface is centered on watchlist operations.
- backend/auth.py provides authentication support, while backend/schemas.py and backend/models.py define the request/response and persistence shapes shared across endpoints.
- The backend is therefore organized as a classic API service: route handlers on top, schema validation in the middle, ORM models underneath.
4. Persistence and migrations
- backend/database.py likely owns the SQLAlchemy engine/session setup, and backend/alembic/ contains migration support.
- The presence of alembic/versions/9a07dd54f78b_initial_schema.py indicates a versioned relational schema, with SQLite used locally and PostgreSQL expected in production per the README.
- This is the durable state boundary for users, watchlists, and any stored analysis metadata.
5. Authentication and personalization
- The README describes JWT-based auth and user-linked watchlists; the code layout supports that via auth.py, models.py, and routers/watchlist.py.
- Personalization is a backend concern: a user authenticates, then the dashboard can query/update that user’s watchlists and related alerts.
- This is the main tenant boundary in the system: data is not just global market data, but also account-scoped settings.
6. Crawler subsystem
- backend/crawlers/ is a dedicated ingestion layer with base.py, primary.py, secondary.py, extractor.py, sources.py, and agent.py.
- The structure implies source-specific collectors, a shared extraction contract, and a source registry or configuration layer.
- Based on the README, this subsystem gathers articles/posts from financial news, official filings, and community sources before any AI processing happens.
7. Normalization and deduplication
- The crawler output is not used raw; backend/ai/deduplicator.py and the README’s “merge identical stories” behavior indicate a normalization step that groups the same event from multiple publishers.
- This is an important architectural boundary because it converts noisy, source-specific items into a unified story entity with multiple source links.
- For diagramming, treat this as the pivot point between ingestion and analysis.
8. AI analysis pipeline
- backend/ai/pipeline.py is the orchestration layer for downstream analysis, with separate modules for summarizer.py, sentiment.py, and alerts_evaluator.py.
- The README also references Gemini integration plus heuristic fallback behavior, so AI analysis is an external-service-backed capability with a local fallback path.
- The analysis flow appears to be: grouped articles in, summary/sentiment/alert signals out.
9. Data products exposed to the UI
- The frontend component names map directly to backend-derived products: breaking news, watchlist changes, sentiment scores, alert states, and stock-specific analysis.
- The dashboard is therefore fed by several logically distinct backend outputs: raw or grouped news, aggregated sentiment, watchlist state, and ticker-focused prediction/summary results.
- For architecture diagrams, these should be shown as separate read models even if they originate from the same crawl pipeline.
10. Operational and runtime concerns
- backend/requirements.txt plus backend/requirements_crawl.txt suggest the backend has a core API runtime and an additional crawling/analysis dependency set.
- logger_config.py indicates centralized logging, which matters for tracing crawl and AI pipeline failures.
- backend/.env.example implies environment-driven configuration for database, JWT secrets, Gemini API key, and email/SMTP alerts.
11. Deployment boundary
- Each side is containerized independently, and the README points to Railway/Render/AWS ECS for backend deployment and Vercel for the frontend.
- This means the frontend and backend can be scaled and deployed separately, with the browser talking to the backend over HTTP rather than through server-side coupling.
12. Best way to draw the diagram
- Draw four main boxes: Frontend UI, FastAPI API/Auth, Crawler + AI processing, and Relational DB.
- Put Gemini API / external source websites / SMTP outside the system boundary as external dependencies.
- Show the main flow as: sources → crawlers/extractor → deduplication → AI analysis → persisted records/API responses → dashboard panels, with auth/watchlist requests flowing directly between frontend and backend.
Main entry points: main.py API App · ai Analysis Modules · models.py Models · database.py Database
Components 19
Frontend UI
Next.js App Router dashboard and login experience
- App Router · Frontend shell and route composition
frontend/src/app - Login Page · Authentication screen
frontend/src/app/login/page.tsx - Dashboard · Main information dashboard
frontend/src/app/page.tsx - Dashboard Panels · Watchlist, news, summary, sentiment, alerts, and stock analysis panels
frontend/src/components
Backend Service
FastAPI API, auth, persistence, and watchlist endpoints
- API App · Application startup and router wiring
backend/main.py - Auth · Authentication and user session support
backend/auth.py - Watchlist API · User watchlist operations
backend/routers/watchlist.py - Schemas · Request and response shapes
backend/schemas.py - Models · Persistent domain entities
backend/models.py - Database · Engine and session management
backend/database.py - Migrations · Versioned relational schema
backend/alembic
Processing Pipeline
Crawler ingestion, deduplication, and AI analysis
- Source Registry · Primary and secondary source definitions
backend/crawlers/sources.py - Crawlers · Source-specific collectors and extraction flow
backend/crawlers - Deduplicator · Merges identical stories into unified events
backend/ai/deduplicator.py - AI Pipeline · Coordinates summarization, sentiment, and alerts
backend/ai/pipeline.py - Analysis Modules · Summaries, sentiment, and alert evaluation
backend/ai
External Dependencies
Outside services and data sources
- News Sources · Financial news, filings, and community sources
- Gemini API · Hosted LLM used for analysis with fallback behavior
- Email/SMTP · Alert delivery integration
Connections 20
- Login Page → Auth: sign in · User authentication requests
- Dashboard → Dashboard Panels: renders · Dashboard page is composed from focused panels
- Dashboard Panels → API App: fetches data · Panels consume backend read models and API responses
- App Router → API App: API client · Frontend talks to the backend over HTTP
- API App → Auth: uses · API entrypoint wires authentication support
- API App → Watchlist API: mounts · Watchlist router is exposed through the API
- API App → Schemas: validates · Request and response payloads are shaped by schemas
- Watchlist API → Models: persists · Watchlist endpoints operate on ORM entities
- Models → Database: stores in · ORM models are backed by the database layer
- Database → Migrations: managed by · Schema changes are versioned with Alembic
- Source Registry → News Sources: reads from · Crawler source definitions point at outside publishers
- Crawlers → Source Registry: targets · Collectors use the configured source registry
- Crawlers → Deduplicator: feeds · Raw extracted items are normalized and merged
- Deduplicator → AI Pipeline: prepares · Grouped stories are handed to analysis orchestration
- AI Pipeline → Analysis Modules: runs · Pipeline executes summarization, sentiment, and alerts
- Analysis Modules → Gemini API: calls · LLM-backed analysis uses Gemini when available
- Analysis Modules → Email/SMTP: sends alerts · Alert results can be delivered via email
- Analysis Modules → Models: writes results · Analysis output becomes persisted application data
- API App → Database: queries · API reads and writes application state
- API App → Analysis Modules: serves insights · API exposes derived news, sentiment, and alert data