How sayan112207/ai_tracker works
1. Repository shape
This is a single-machine MVP with two top-level applications: a Python backend and a React frontend. The backend owns all capture, processing, storage, and analytics logic; the frontend is a thin dashboard that reads from the backend API.
2. Primary end-to-end flow
The core pipeline is: user triggers a capture in the dashboard → FastAPI enqueues/runs capture jobs → provider adapters collect live AI responses → raw artifacts are written to local storage → processing extracts entities/mentions/citations and sentiment/framing → ranking/aggregation computes visibility metrics → analytics API serves read models back to the dashboard.
3. Backend boundary: API vs. worker-like orchestration
backend/main.py and backend/api/* expose the HTTP surface. The API is not just read-only; it also initiates captures, reprocessing, and project actions. The capture pipeline behaves like an embedded worker/orchestrator rather than a separate service.
4. Capture layer and provider adapters
backend/capture/orchestrator.py coordinates capture batches across providers in backend/providers/*. There are two provider styles:
- Browser providers: ChatGPT, Gemini, Perplexity using Playwright/patchright-style automation and stealth handling.
- Search/API providers: Google AI Overview and Google AI Mode via SerpAPI.
The provider boundary matters because browser providers produce DOM/screenshot artifacts, while SerpAPI providers return structured result data without browser state.
5. Local artifact storage
backend/storage/* writes an immutable raw JSON record per run plus associated HTML and screenshot files under storage/raw, storage/processed, storage/html, and storage/screenshots. This makes raw capture replayable and allows reprocessing without scraping again. Cleanup is a separate concern handled by backend/storage/cleanup.py and the scripts/cleanup.py utility.
6. Processing pipeline
backend/processing/pipeline.py chains the analysis stages: normalization, NER, and sentiment. normalizer.py and ner.py extract and canonicalize brand mentions and citations; sentiment.py adds optional local brand-intelligence signals. The important architectural boundary is that this stage consumes saved artifacts and produces derived data, rather than re-contacting providers.
7. Ranking and analytics
backend/ranking/engine.py turns processed mentions/citations into a visibility score and related metrics. backend/analytics/service.py exposes read-oriented views for trends, provider breakdowns, competitor analysis, and run histories. This keeps scoring logic separate from presentation, and analytics separate from raw capture semantics.
8. Persistence model
The backend uses SQLite via SQLAlchemy (backend/database/session.py, backend/models/db_models.py). The database stores the durable structured records: projects, runs, mentions, competitors, and derived analytics state. The local JSON artifacts remain the source of truth for capture evidence, while SQLite holds queryable summary data for the dashboard.
9. LLM-assisted features
backend/llm/* and backend/providers/gemini/* support optional Gemini-powered features such as prompt suggestions and competitor auto-detection. These are additive and non-critical: if the Gemini key is absent, the capture/processing pipeline still works. This creates a clear separation between core deterministic pipeline and optional enrichment.
10. Frontend role
The frontend in frontend/src/* is a Vite/React dashboard with charts and operational views. It does not compute visibility itself; it polls or fetches API endpoints for overview metrics, prompt runs, competitors, providers, history, and live capture progress. The CaptureProgress and orchestration views mirror backend job state.
11. Operational concerns baked into the architecture
The repo includes built-in support for caching, rate limiting, retries, and a circuit breaker around provider execution. These are important to diagram because they sit between the orchestrator and provider adapters, protecting the system from repeated failures and reducing unnecessary scraping.
12. Supporting scripts and bootstrap
scripts/init_db.py, scripts/seed_example.py, and scripts/login_provider.py are environment/bootstrap utilities rather than runtime subsystems. They initialize SQLite, seed demo content, and optionally persist browser session cookies for signed-in provider use.
13. What to emphasize in an architecture diagram
The most important boundaries are:
- UI vs backend
- API/orchestrator vs provider adapters
- raw immutable artifacts vs processed/queryable data
- capture-time computation vs analytics/read models
- core pipeline vs optional Gemini enrichment
That separation is the main design characteristic of this repo.
Main entry points: orchestrator.py Orchestrator · pipeline.py Pipeline · routes.py Routes · App.jsx Dashboard
Components 23
Frontend
React dashboard and API client
- Dashboard · Main UI shell for the dashboard
frontend/src/App.jsx - API Client · Frontend data access layer
frontend/src/services/api.js - Overview · Primary metrics and summary view
frontend/src/pages/Overview.jsx - Progress · Live capture and orchestration status
frontend/src/components/CaptureProgress.jsx - Charts · Metrics and trend visualizations
frontend/src/charts/Charts.jsx
API Layer
HTTP entrypoint and orchestration surface
- Backend App · Application bootstrap and server startup
backend/main.py - Routes · Read and action endpoints for projects, runs, and capture
backend/api/routes.py - Analytics API · Trend, provider, competitor, and history views
backend/analytics/service.py
Capture
Provider orchestration and collection
- Orchestrator · Coordinates capture batches and provider execution
backend/capture/orchestrator.py - Provider API · Common provider contract and execution surface
backend/providers/base.py - Browser Providers · ChatGPT, Gemini, and Perplexity browser automation
backend/providers/chatgpt/provider.py - Search Providers · Google AI Overview and AI Mode via SerpAPI
backend/providers/google_ai/provider.py
Processing
Artifact-based normalization and analysis
- Pipeline · Normalization, NER, and sentiment stages
backend/processing/pipeline.py - Normalizer · Canonicalizes brands, mentions, and citations
backend/processing/normalizer.py - NER · Extracts entities and references from artifacts
backend/processing/ner.py - Sentiment · Optional framing and brand-intelligence signals
backend/processing/sentiment.py - Visibility Engine · Computes visibility score and related metrics
backend/ranking/engine.py
Data
Persistence and storage boundaries
- Raw Store · Immutable raw JSON, HTML, and screenshot artifacts
backend/storage/raw_store.py - DB Models · Projects, runs, mentions, competitors, and derived state
backend/models/db_models.py - SQLite Session · SQLAlchemy-backed SQLite connection management
backend/database/session.py
Optional Enrichment
Non-critical Gemini-assisted features
- LLM Service · Prompt suggestions and competitor auto-detection
backend/llm/service.py - Gemini Helper · Gemini-backed optional features
backend/llm/gemini.py
Operations
Maintenance and bootstrap utilities
- Cleanup · Artifact and storage cleanup utilities
backend/storage/cleanup.py
Connections 26
- Dashboard → API Client: fetches · UI reads data through the API client
- Dashboard → Overview: renders · Dashboard shell hosts overview and operational views
- Dashboard → Progress: shows · Displays live capture state
- Dashboard → Charts: visualizes · Charts present metrics and trends
- API Client → Routes: HTTP · Frontend calls backend endpoints
- Backend App → Routes: mounts · Server exposes route layer
- Routes → Orchestrator: starts jobs · API initiates capture and reprocessing actions
- Routes → Analytics API: serves reads · API exposes query-oriented views
- Orchestrator → Provider API: uses contract · Orchestration executes through provider abstraction
- Orchestrator → Browser Providers: collects · Browser-based capture adapters
- Orchestrator → Search Providers: collects · SerpAPI-based adapters
- Orchestrator → Raw Store: writes artifacts · Persist immutable capture evidence
- Raw Store → Pipeline: feeds · Saved artifacts are reprocessed offline
- Pipeline → Normalizer: stage · Normalize extracted content
- Pipeline → NER: stage · Extract entities and citations
- Pipeline → Sentiment: stage · Add optional sentiment/framing signals
- Pipeline → Visibility Engine: outputs to · Derived mentions and citations drive scoring
- Visibility Engine → SQLite Session: persists · Scores and summaries are stored in SQLite
- SQLite Session → DB Models: maps · SQLAlchemy persistence model layer
- Analytics API → DB Models: queries · Read models are built from durable records
- Analytics API → Visibility Engine: depends on · Analytics surfaces visibility metrics
- LLM Service → Gemini Helper: delegates · Optional Gemini-backed enrichment
- LLM Service → Orchestrator: enriches · Adds non-critical assistance to capture workflows
- Cleanup → Raw Store: prunes · Maintenance removes stale artifacts
- Cleanup → SQLite Session: cleans · May also reconcile durable records
- Progress → Routes: polls · Progress view tracks orchestration state