Skip to content

codeforpakistan/watchtower-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›οΈ Watchtower API

Holding government institutions accountable through automated website performance and quality analysis.

Overview

Watchtower is a FastAPI-based service that monitors and evaluates government websites to ensure taxpayer money is being used effectively for digital services. The API automatically scans government websites, analyzes their performance using Google PageSpeed Insights, and critiques their design and content using AI-powered analysis.

🎯 Mission

Government websites should serve citizens effectively. Watchtower provides transparency by:

  • Performance Monitoring: Tracking load times, accessibility, and technical performance
  • AI-Powered Critique: Analyzing design quality, content clarity, and user experience
  • Public Accountability: Creating leaderboards to highlight best and worst performers
  • Data-Driven Insights: Providing actionable feedback for improvement

πŸ› οΈ Tech Stack

  • API Framework: FastAPI
  • Package Management: Poetry
  • Database: Supabase (PostgreSQL)
  • Performance Analysis: Google PageSpeed Insights API
  • Web Crawling: Playwright
  • AI Analysis: OpenAI/Anthropic APIs
  • Python Version: 3.11+

πŸš€ Features

Core Functionality

  • Website Registry: Maintain a database of government websites to monitor
  • Automated Scanning: Scheduled performance and quality assessments
  • Performance Metrics: PageSpeed Insights integration for Core Web Vitals
  • AI Content Analysis: Automated critique of design, accessibility, and content quality
  • Leaderboard System: Ranking websites from best to worst performers
  • Historical Tracking: Monitor improvements or degradation over time

API Endpoints

  • GET /websites - List all monitored government websites
  • POST /websites - Add new website to monitoring
  • GET /websites/{id}/reports - Get analysis reports for a specific website
  • GET /leaderboard - View ranked performance leaderboard
  • POST /scan/{id} - Trigger manual scan of a website
  • GET /metrics - Overall system metrics and statistics

πŸ“Š Analysis Criteria

Performance Metrics

  • Core Web Vitals: LCP, FID, CLS scores
  • PageSpeed Score: Overall performance rating
  • Accessibility: WCAG compliance assessment
  • Best Practices: Security and modern web standards

AI Quality Assessment

  • Design Quality: Visual hierarchy, modern design principles
  • Content Clarity: Language accessibility, information architecture
  • User Experience: Navigation, mobile responsiveness
  • Accessibility: Screen reader compatibility, color contrast
  • Government Standards: Compliance with digital service standards

πŸ—οΈ Project Structure

watchtower-api/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ endpoints/
β”‚   β”‚   β”‚   β”œβ”€β”€ websites.py
β”‚   β”‚   β”‚   β”œβ”€β”€ reports.py
β”‚   β”‚   β”‚   └── leaderboard.py
β”‚   β”‚   └── deps.py
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ config.py
β”‚   β”‚   β”œβ”€β”€ security.py
β”‚   β”‚   └── database.py
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ website.py
β”‚   β”‚   β”œβ”€β”€ report.py
β”‚   β”‚   └── analysis.py
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ pagespeed.py
β”‚   β”‚   β”œβ”€β”€ crawler.py
β”‚   β”‚   β”œβ”€β”€ ai_analyzer.py
β”‚   β”‚   └── scheduler.py
β”‚   └── main.py
β”œβ”€β”€ tests/
β”œβ”€β”€ scripts/
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ README.md
└── .env.example

πŸ”§ Installation & Setup

Prerequisites

  • Python 3.11+
  • Poetry
  • Supabase account
  • Google PageSpeed Insights API key
  • OpenAI/Anthropic API key

Installation

  1. Clone the repository

    git clone https://github.com/codeforpakistan/watchtower-api.git
    cd watchtower-api
  2. Install dependencies

    poetry install
  3. Environment setup

    cp .env.example .env
    # Edit .env with your configuration
  4. Database setup

    poetry run python scripts/init_db.py
  5. Run the application

    poetry run uvicorn app.main:app --reload

βš™οΈ Configuration

Environment Variables

# Database
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_anon_key

# APIs
GOOGLE_PAGESPEED_API_KEY=your_pagespeed_api_key
OPENAI_API_KEY=your_openai_api_key

# Application
API_V1_STR=/api/v1
PROJECT_NAME=Watchtower API
DEBUG=False

# Scheduling
SCAN_INTERVAL_HOURS=24
MAX_CONCURRENT_SCANS=5

πŸ“Š Database Schema

Tables

websites

  • id (UUID, Primary Key)
  • name (Text) - Website/Agency name
  • url (Text) - Website URL
  • government_level (Enum) - Federal, State, Local
  • agency_type (Text) - Department, Municipality, etc.
  • created_at (Timestamp)
  • last_scanned (Timestamp)

reports

  • id (UUID, Primary Key)
  • website_id (UUID, Foreign Key)
  • scan_date (Timestamp)
  • pagespeed_score (Integer)
  • core_web_vitals (JSONB)
  • ai_analysis (JSONB)
  • overall_score (Float)

πŸ€– AI Analysis Framework

The AI analysis evaluates websites across multiple dimensions:

  1. Accessibility Score (0-100)

    • Color contrast ratios
    • Alt text presence
    • Keyboard navigation
    • Screen reader compatibility
  2. Design Quality Score (0-100)

    • Visual hierarchy
    • Modern design principles
    • Consistency
    • Professional appearance
  3. Content Quality Score (0-100)

    • Language clarity
    • Information findability
    • Content organization
    • Citizen-focused messaging
  4. Overall Usability Score (0-100)

    • Combined weighted score
    • Benchmarked against best practices

πŸ“ˆ API Usage Examples

Adding a new website to monitor

import requests

response = requests.post(
    "http://localhost:8000/api/v1/websites",
    json={
        "name": "Department of Motor Vehicles",
        "url": "https://dmv.example.gov",
        "government_level": "state",
        "agency_type": "department"
    }
)

Getting the leaderboard

leaderboard = requests.get("http://localhost:8000/api/v1/leaderboard")
print(leaderboard.json())

πŸ”„ Deployment

Docker Deployment

docker build -t watchtower-api .
docker run -p 8000:8000 --env-file .env watchtower-api

Production Considerations

  • Set up proper logging and monitoring
  • Configure rate limiting for external APIs
  • Implement caching for frequently accessed data
  • Set up automated backups for Supabase
  • Use environment-specific configurations

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

🎯 Roadmap

  • Phase 1: Core API with basic scanning
  • Phase 2: AI analysis integration
  • Phase 3: Public dashboard and leaderboards
  • Phase 4: Automated reporting and alerts
  • Phase 5: Historical trend analysis
  • Phase 6: Cost-effectiveness analysis

πŸ“ž Support

For questions, suggestions, or issues:


Empowering citizens through government website transparency and accountability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages