How agrimgarg08/drishti works
1. Overall shape
- DRISHTI is a Python-based monitoring platform with three main layers: a Streamlit dashboard, a FastAPI backend, and a Supabase-hosted PostgreSQL/auth layer.
- The intended architecture is “UI → API/ML → database/auth,” but the README notes that the backend is not fully wired in yet, so the frontend currently bypasses parts of that path in places.
2. Primary user-facing entrypoint
- streamlit_app.py is the top-level app entrypoint.
- frontend/app.py contains the dashboard UI logic: charts, readings, alerts, simulation views, and issue workflows.
- This is the operational interface users interact with directly.
3. Backend service boundary
- backend/main.py is the FastAPI service boundary and likely exposes REST endpoints for sensors, readings, alerts, issues, prediction, and simulation.
- backend/models.py defines the data model, while backend/db.py handles database connectivity/session setup.
- backend/auth.py encapsulates authentication integration and protected access behavior.
4. Machine learning subsystem
- backend/ml.py contains the anomaly detection and prediction logic.
- The README identifies two distinct ML behaviors: an IsolationForest-based anomaly detector for abnormal water-quality patterns, and a lightweight regression-based risk/simulation layer for short-term projection and scenario comparison.
- This ML layer sits between incoming readings and alert generation.
5. Data and auth platform
- supabase_client.py indicates direct Supabase access from the application layer.
- Supabase is the hosted data/auth boundary: PostgreSQL for persistent state and Supabase Auth for sign-in/sign-up and protected workflows.
- This is a key architectural point because it explains how the app persists operational data and manages authenticated actions.
6. Persistence and schema management
- migrations/initial.sql defines the baseline schema.
- scripts/init_db.py and scripts/apply_migrations.py support local/bootstrap database setup.
- dev.db suggests there is also a local development database artifact, likely for offline or simplified development.
7. Data generation and test tooling
- scripts/generate_data.py seeds sample sensor/operational data.
- scripts/test_api.py and scripts/test_ml.py exercise the backend endpoints and ML behavior separately.
- These scripts indicate that API, database, and ML are treated as distinct testable subsystems.
8. Operational workflow
- The application’s business flow is: ingest sensor or sample data, persist it, run anomaly/risk logic, surface alerts in the dashboard, and track follow-up issues.
- Alerts and issues are not just outputs; they form the response-management loop that closes the monitor/detect/predict/respond cycle.
9. Deployment and runtime
- Procfile suggests the repo is designed for platform-style deployment.
- .github/workflows/ci.yml provides CI coverage, and .devcontainer/devcontainer.json supports a reproducible development environment.
- requirements.txt shows the project is fully Python-managed rather than split across multiple runtime stacks.
10. Important architectural boundary to capture
- There are effectively two data paths: a “preferred” backend/API path and a currently practical frontend-to-Supabase path.
- For an architecture diagram, treat FastAPI, ML, and database as distinct backend services, but note that the Streamlit UI may directly consume Supabase data today because the backend is still partial.
Main entry points: main.py API service · app.py Dashboard UI · db.py DB layer · ml.py ML engine
Components 18
UI
User-facing dashboard and app entrypoints
- Streamlit app · Top-level Streamlit entrypoint for the dashboard
streamlit_app.py - Dashboard UI · Main dashboard logic for charts, readings, alerts, simulation, and issues
frontend/app.py
Backend
API, ML, auth, and persistence boundary
- API service · FastAPI boundary exposing backend workflows and endpoints
backend/main.py - ML engine · Anomaly detection and short-term prediction/simulation logic
backend/ml.py - DB layer · Database connectivity and session setup
backend/db.py - Auth layer · Authentication integration and protected access behavior
backend/auth.py - Data models · Shared application models and domain objects
backend/models.py
Data
Schema, local database, and Supabase access
- Supabase client · Direct application access to Supabase services
supabase_client.py - Initial schema · Baseline database schema and tables
migrations/initial.sql - Dev database · Local development database artifact
dev.db
Ops
Deployment, CI, and bootstrap tooling
- Init DB · Local database initialization script
scripts/init_db.py - Migrations · Applies schema migrations to the database
scripts/apply_migrations.py - Seed data · Generates sample sensor and operational data
scripts/generate_data.py - API tests · Exercises backend endpoints and service flows
scripts/test_api.py - ML tests · Exercises anomaly and prediction behavior
scripts/test_ml.py - Procfile · Process definition for platform deployment
Procfile - CI workflow · Continuous integration pipeline
.github/workflows/ci.yml - Dev container · Reproducible development environment definition
.devcontainer/devcontainer.json
Connections 21
- Streamlit app → Dashboard UI: loads UI · Top-level app launches the dashboard UI
- Dashboard UI → Supabase client: reads/writes · Frontend may directly access Supabase-backed data paths
- Dashboard UI → API service: preferred API path · Intended UI-to-backend flow for operational actions
- API service → Data models: uses · API layer depends on shared domain models
- API service → DB layer: persists via · API uses database connectivity/session management
- API service → Auth layer: protects with · API gates protected workflows through auth
- API service → ML engine: invokes · API delegates anomaly detection and prediction to ML layer
- ML engine → Data models: consumes · ML operates on shared reading and alert-shaped data
- DB layer → Initial schema: schema source · Database layer is backed by the base schema definition
- DB layer → Dev database: local store · Development runs can use a local database artifact
- Auth layer → Supabase client: integrates with · Authentication relies on Supabase services
- Supabase client → Dev database: backs data path · Application data path can terminate in local or hosted storage
- Init DB → Initial schema: bootstraps · Initialization script applies the base schema
- Migrations → Initial schema: applies · Migration script manages schema evolution from baseline SQL
- Seed data → Dev database: seeds · Sample data generation populates the development database
- API tests → API service: tests · API test script exercises backend endpoints
- ML tests → ML engine: tests · ML test script exercises anomaly and simulation behavior
- Procfile → API service: runs · Deployment process can start the backend service
- CI workflow → API tests: runs · CI validates backend behavior through API tests
- CI workflow → ML tests: runs · CI validates ML behavior through ML tests
- Dev container → Init DB: supports · Development container supports local setup workflows