This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Anomstack is an open-source anomaly detection system built on Dagster and FastHTML. It provides ML-powered anomaly detection for metrics from various data sources (BigQuery, Snowflake, ClickHouse, DuckDB, SQLite, etc.) with built-in alerting via email/Slack.
make local- Start Dagster locally with dev setupmake dashboard- Start FastHTML dashboard locally (port 5003)make dashboard-uvicorn- Start dashboard with uvicorn (hot reload)make dashboard-local-dev- Start dashboard with seeded test datamake dev- Setup local development environment and install dependencies
make docker- Start all services with Docker Composemake docker-dev- Start with local development imagesmake docker-smart- Build fresh images and start containersmake docker-build- Build all images locallymake docker-logs- View logs for all containersmake docker-logs-<service>- View logs for specific service (code, dagit, dashboard, daemon)make docker-shell-<service>- Get shell access to running containersmake docker-restart- Restart all containers (useful for .env changes)make docker-stop- Stop all containers
pytestormake tests- Run test suite (includes documentation link checking)make test-examples- Run only example ingest function testsmake coverage- Run tests with coverage reportmake pre-commit- Run pre-commit hooks (ruff linting)
make docsormake docs-start- Start Docusaurus dev server with live reloadmake docs-build- Build static documentation site (includes broken link checking)make docs-test- Test documentation for broken linksmake docs-serve- Serve built documentation locallymake docs-clear- Clear documentation build cachemake docs-install- Install documentation dependencies
make seed-local-db- Seed local DB with python_ingest_simple datamake seed-local-db-all- Seed with all example metric batchesmake seed-local-db-custom BATCHES='batch1,batch2' DB_PATH='path/to/db'make run-example EXAMPLE=<name>- Test individual example ingest functionsmake list-examples- List all 26+ available examples
make reload-config- Reload configuration without restarting containersmake enable-auto-reload- Enable automatic config reloadingmake enable-config-watcher- Enable smart config file watcher
make reset-interactive- Interactive reset with guided optionsmake reset-gentle- Rebuild containers (safest reset)make reset-medium- Remove containers, keep data volumesmake reset-nuclear- Remove everything including local datamake reset-full-nuclear- Nuclear + full docker system cleanup (maximum cleanup)make dagster-cleanup-status- Show current Dagster storage usagemake dagster-cleanup-minimal- Remove old logs only (safe)make dagster-cleanup-standard- Clean up old Dagster runs (older than 30 days)make dagster-cleanup-aggressive- Remove runs older than 7 daysmake kill-long-runs- Manually kill any Dagster runs exceeding configured timeout
make fly-preview- Preview environment variables that will be set as Fly secretsmake fly-deploy- Deploy to Fly.io (reads .env file automatically)make fly-deploy-demo- Deploy with demo profile (enables demo metric batches)make fly-deploy-production- Deploy with production profilemake fly-deploy-development- Deploy with development profile (all examples enabled)make fly-deploy-demo-fresh- Deploy with fresh build (clears Docker cache first)make fly-build-test- Test Fly.io build locally before deployingmake fly-docker-clean- Clean Docker cache for Fly buildsmake fly-cleanup- Run disk cleanup on Fly instance (requires SSH access)make fly-cleanup-preview- Preview cleanup on Fly instance (dry run)make fly-status- Check Fly.io app status (requires FLY_APP env var)make fly-logs- View Fly.io app logs (requires FLY_APP env var)make fly-ssh- SSH into Fly.io app (requires FLY_APP env var)
Anomstack uses a simplified 3-container Docker architecture:
- anomstack_webserver: Consolidated Dagster webserver with embedded user code (no separate gRPC server)
- anomstack_daemon: Dagster daemon for job scheduling and execution
- anomstack_dashboard: FastHTML dashboard for metrics visualization
This consolidated approach eliminates the previous gRPC code server, reducing network overhead and improving reliability through direct Python module loading.
- anomstack/: Main application code
main.py: Dagster definitions and job orchestrationconfig.py: Configuration managementjobs/: Dagster jobs (ingest, train, score, alert, plot)ml/: Machine learning components (PyOD models)external/: Database connectors (BigQuery, Snowflake, etc.)alerts/: Email/Slack alerting system
- dashboard/: FastHTML web dashboard with MonsterUI
- metrics/: Metric batch configurations (.yaml) and SQL queries (.sql)
defaults/: Default configuration parametersexamples/: Example metric batches for various data sources
Metrics are organized into "batches" - collections of related metrics with shared configuration. Each batch requires:
.yamlconfig file defining parameters (database, schedule, alert methods).sqlfile with query OR custom Python ingest function- Optional custom preprocessing functions
- Ingest: Run SQL/Python to collect metrics
- Train: Train PyOD anomaly detection models
- Score: Score new data points for anomalies
- Alert: Send email/Slack alerts for detected anomalies
- LLM Alert: LLM-based anomaly detection and alerting using anomaly-agent
- Plot: Generate visualizations in Dagster UI
- Change: Change detection for metrics
- Summary: Daily summary emails
- Delete: Delete old metrics
- Reload: Configuration hot-reload job
- Cleanup: Disk space management
- Retention: Custom retention for SQLite
Three key sensors monitor the system:
- email_on_run_failure: Sends email notifications when Dagster runs fail
- kill_long_running_runs: Automatically terminates runs exceeding configured timeout (default 15 minutes, configurable via
ANOMSTACK_KILL_RUN_AFTER_MINUTES) - config_file_watcher: Smart file watcher that detects configuration changes and triggers reloads (enabled via
ANOMSTACK_CONFIG_WATCHER=true)
All data stored in long-format "metrics" table with columns:
metric_timestamp,metric_batch,metric_name,metric_type,metric_valuemetric_typecan be: 'metric' (raw data), 'score' (anomaly score), 'alert' (alert flag)
.env: Main environment configurationprofiles/: Environment profiles for different deploymentslocal-dev.env: Local development with simple examplesdemo.env: Demo configuration for Fly.io deploymentproduction.env: Production settings
Environment variables can override metric batch config using pattern:
ANOMSTACK__<METRIC_BATCH>__<PARAM> (uppercase, underscores for dashes)
Example:
ANOMSTACK__PYTHON_INGEST_SIMPLE__DB=bigquery
ANOMSTACK__PYTHON_INGEST_SIMPLE__ALERT_METHODS=emaildagster.yaml: Dagster configurationmetrics/defaults/defaults.yaml: Default parameters for all metric batchespyproject.toml: Ruff linting configuration
anomstack/main.py: Main Dagster definitions (defines all jobs, schedules, and sensors)dashboard/app.py: FastHTML dashboard applicationanomstack/config.py: Configuration loading and environment variable override logic
anomstack/external/: Connectors for BigQuery, Snowflake, ClickHouse, DuckDB, SQLite
ALWAYS check the Makefile first when working on Anomstack! The project includes comprehensive Make commands for all common development tasks. Before running manual commands, review the available Makefile commands.
- Uses ruff for linting (line length: 100)
- Star imports allowed in dashboard modules (F403/F405 rules ignored)
- Pre-commit hooks enforce code quality
- Per-file lint ignores configured for dashboard routes and maintenance scripts
- Tests in
tests/directory - Test coverage tracking with badges in README
- See "Testing & Quality" section for test commands
- Local Python environment
- Docker Compose (recommended for development)
- Fly.io (production deployment)
- Dagster Cloud (serverless)
- GitHub Codespaces
The metrics/examples/ directory contains ready-to-use examples:
- HackerNews story metrics via API
- Weather data from Open Meteo
- Stock prices from Yahoo Finance (yfinance)
- System metrics from Netdata
- Simple Python-generated test metrics (python_ingest_simple)
- Earthquake data from USGS
- ISS location tracking
- PostHog analytics (requires credentials)
- Currency exchange rates
- And 26+ total examples
When adding new metrics, follow existing patterns in examples and ensure proper .yaml configuration with required fields like metric_batch, db, and cron schedules.
Use make run-example EXAMPLE=<name> to test individual examples or make list-examples to see all available examples.