All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 33s
3.9 KiB
3.9 KiB
SchoolCompare.co.uk - Project Context
Overview
SchoolCompare is a web application for comparing UK primary school (KS2) performance data. It allows users to:
- Search and browse schools by name, location (postcode), or local authority
- Compare multiple schools side-by-side with charts and tables
- View school rankings by various KS2 metrics
- See historical performance trends across years
Architecture
Backend (Python/FastAPI)
- Framework: FastAPI with uvicorn
- Database: PostgreSQL with SQLAlchemy ORM
- Data Source: UK Government "Compare School Performance" CSV downloads
Key files:
backend/app.py- Main FastAPI application, API routesbackend/config.py- Configuration via pydantic-settings (env vars, .env file)backend/database.py- SQLAlchemy engine, session managementbackend/models.py- Database models (School, SchoolResult)backend/data_loader.py- Data queries, geocoding, legacy DataFrame compatibilitybackend/schemas.py- Column mappings, metric definitions, LA code mappings
Frontend (Vanilla JS)
- Single-page application with hash-based routing
- Chart.js for data visualization
- No build step required
Key files:
frontend/index.html- Main HTML structurefrontend/app.js- All application logic, API calls, renderingfrontend/styles.css- Styling (CSS variables, responsive design)
Database Schema
schools school_results
├── id (PK) ├── id (PK)
├── urn (unique, indexed) ├── school_id (FK → schools.id)
├── school_name ├── year (indexed)
├── local_authority ├── rwm_expected_pct
├── school_type ├── reading_expected_pct
├── postcode ├── ... (all KS2 metrics)
├── latitude, longitude └── unique(school_id, year)
└── results → SchoolResult[]
Configuration
Environment variables (or .env file):
DATABASE_URL- PostgreSQL connection string (default:postgresql://schoolcompare:schoolcompare@localhost:5432/schoolcompare)HOST,PORT- Server binding (default:0.0.0.0:80)ALLOWED_ORIGINS- CORS origins
Running Locally
-
Start PostgreSQL:
docker compose up -d db -
Run migration to import CSV data:
python scripts/migrate_csv_to_db.py --drop # Add --geocode to geocode postcodes (slower, adds lat/long) -
Start the app:
uvicorn backend.app:app --host 0.0.0.0 --port 8000
Docker Deployment
docker compose up -d
This starts:
db- PostgreSQL 16 with persistent volumeapp- FastAPI application on port 80
Data
- Source: UK Government Compare School Performance downloads
- Location:
data/directory with year folders (e.g.,2023-2024/england_ks2final.csv) - The
scripts/download_data.pycan fetch data from the government website
Key Features
- Location Search: Enter postcode to find nearby schools (uses postcodes.io API)
- Multi-school Comparison: Select multiple schools, view metrics across years
- Rankings: Top schools by any KS2 metric, filterable by local authority
- Variability Analysis: Shows standard deviation of scores across years
API Endpoints
GET /api/schools- List/search schools (supports pagination, location search)GET /api/schools/{urn}- School details with all yearly dataGET /api/compare?urns=123,456- Compare multiple schoolsGET /api/rankings- School rankings by metricGET /api/filters- Available filter options (LAs, types, years)GET /api/metrics- Metric definitions (single source of truth)GET /api/data-info- Database stats
Recent Changes
- Migrated from CSV file storage to PostgreSQL database
- Added location-based search using postcode geocoding
- Added local authority filter to rankings
- Improved frontend with featured schools, loading states, API caching