Skip to content
benitmatumonaPublic

About

Status: Day 1–2 hand-coded baseline is complete and verified end-to-end. Phase 1 (AI agents), Phase 2 (security), and Phase 3 (deployment scaffolding) have now been added on top of it, per

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

UbuntuAI — South Africa's Autonomous Sustainability Intelligence Platform

Predict. Detect. Recommend. Measure.

Status: Day 1–2 hand-coded baseline is complete and verified end-to-end. Phase 1 (AI agents), Phase 2 (security), and Phase 3 (deployment scaffolding) have now been added on top of it, per docs/UbuntuAI_5Day_Sprint_Plan.md.

Phase 7 additions

  • POPIA-aware anonymization threshold: municipality zone data now suppresses any zone with fewer than POPIA_MIN_ZONE_SIZE (default 5) households instead of exposing an "average" that's really just one or two households' exact readings. Verified live: a 2-household zone was correctly withheld while a 6-household zone showed normally, with suppression counts surfaced to municipality staff (not silently dropped).
  • PETCO-aligned waste taxonomy: waste classification now uses real South African recycling categories (PET plastic, HDPE plastic, glass, paper/ cardboard, metal, organic) instead of a generic "recyclable" bucket, each with actionable disposal guidance.
  • Recycling locator: GET /households/{id}/nearest-recycling-point finds the nearest drop-off point, using OpenRouteService for real driving distance if ORS_API_KEY is set, straight-line distance otherwise. Sample drop-off points only — see backend/app/services/recycling_locator.py for what a real PETCO/municipal locator integration would need.
  • Mobile responsiveness: added a bottom tab bar for small screens (the previous nav would have overflowed below ~500px).
  • Municipal open-data portal scaffold: a generic CKAN client (backend/data/ingestion/municipal_portal_loader.py) for the team to register real municipal portals as they're onboarded — genuinely open-ended, no portals are pre-registered.

What's actually working right now

  • Full API: household usage, municipality KPIs, municipality zones (GeoJSON), and recommendation generation — all tested end-to-end against a real DB.
  • Full frontend: Home, Household Dashboard (usage charts + recommendations), Municipality Dashboard (live map), Recommendations, Settings — all wired to the API.
  • Prediction Agent: real linear-regression forecast with R²-based confidence (backend/app/agents/prediction_agent.py), replacing the Day 1-2 weighted-average stub.
  • Recommendation Agent: LLM-generated recommendation text via OpenAI/Azure OpenAI, with automatic fallback to the rule-based template if no API key is set or the call fails (backend/app/agents/recommendation_agent.py) — the demo never breaks because of a missing key or rate limit.
  • Computer Vision Agent + real upload pipeline: POST /waste/classify accepts a real photo upload (JPEG/PNG/WEBP, 8MB max), classifies it (YOLOv11 wrapper, falls back to a keyword classifier until the team trains/sources a model), stores the result, and feeds the household's most recent real classification into its waste recommendation — no more hardcoded demo item. Frontend has a working upload widget on the Household Dashboard. Verified end-to-end with a real image upload.
  • Research Agent: now runs on an actual schedule (in-process APScheduler, configurable via RESEARCH_REFRESH_INTERVAL_HOURS), not just on-demand, and logs every run's status/row-count/error to ingestion_runs so failures are visible in the DB, not just server logs (backend/app/agents/research_agent.py, backend/app/scheduler.py). Added a 4th real source: OpenAQ (air quality), and gave Eskom an optional live-API path (EskomSePush) alongside its sample fallback. Open-Meteo remains the only source that's live by default with no key.
  • Knowledge Agent: real pgvector-backed retrieval — recommendations now cite actual Eskom/NERSA/weather evidence instead of only "your last N readings" (backend/app/agents/knowledge_agent.py). Verified end-to-end against a real Postgres+pgvector instance: 118 chunks embedded and retrieved correctly.
  • LangGraph orchestration: recommendation generation now runs through a real StateGraph (Knowledge -> Prediction -> Recommendation nodes) instead of plain sequential function calls, with a visible execution trace logged per request (backend/app/agents/orchestration.py). Verified live end-to-end.
  • Auth + RBAC: JWT-based register/login, applied to every data endpoint. Household users can only access their own household (auto-claimed on first login for the seeded demo data); municipality users can only access aggregated municipality endpoints. Verified live: 8/8 access-control test cases pass (no-token 401s, cross-user 403s, cross-role 403s, correct 200s).
  • Audit logging middleware: logs method/path/status/timing, not request bodies (POPIA-aware) — backend/app/middleware/audit_log.py.
  • Deployment: Dockerfiles for both services, a full-stack docker-compose.full.yml, and a GitHub Actions workflow that tests then deploys to Azure App Service.

What's still open (be upfront about this with judges)

  • Recommendation Agent needs a real OPENAI_API_KEY (or Azure endpoint) in backend/.env to generate LLM text — without one it silently uses the rule-based fallback, which still demos fine.
  • CV Agent has no trained model yet — WASTE_MODEL_PATH is unset, so it falls back to a keyword classifier applied to the uploaded filename. The upload pipeline (auth, storage, ownership checks, recommendation integration) is real and image- based; only the actual vision model is still a placeholder.
  • Browser Agent (live-site verification via browser-use + Playwright) is not built yet — see the note at the bottom of backend/app/agents/research_agent.py.
  • NERSA tariffs are still sample data — no stable public API exists, tariffs are published as PDFs/tables. Treat as a manual quarterly update for now.
  • Eskom and OpenAQ use real live APIs if you set ESKOM_API_KEY / OPENAQ_API_KEY in .env — without keys, both fall back to sample data.
  • In this sandboxed test environment, api.open-meteo.com isn't reachable (network egress restrictions), so Open-Meteo always falls back to whatever CSV is already on disk here. It's a genuine live API call in a normal environment — test it in yours to confirm.
  • Found and fixed a real config bug while testing this phase: pydantic-settings was rejecting any .env variable not explicitly declared as a Settings field (e.g. adding RESEARCH_AUTO_REFRESH=true to .env would crash the app on boot). Fixed in backend/app/config.py.
  • Without a real OPENAI_API_KEY, the Knowledge Agent still runs (storage + retrieval both work), but uses a deterministic non-semantic fallback embedding instead of a real one — so retrieval quality will be arbitrary rather than meaning-based until a key is set.
  • docker-compose.yml and docker-compose.full.yml now build Postgres from backend/Dockerfile.postgres (pgvector included) instead of the plain image — first build will take a few minutes longer since it compiles the extension.

Structure

UbuntuAI/
├── docs/                      Sprint plan + API contract (finalized)
├── frontend/                  React + TS + Vite + Tailwind + shadcn/ui + MapLibre
│   └── Dockerfile             Production build → nginx
├── backend/                   FastAPI + PostgreSQL (PostGIS, pgvector-ready)
│   ├── app/agents/            Phase 1 AI agents (prediction, recommendation, CV, research)
│   ├── app/auth/               Phase 2 JWT auth + RBAC
│   ├── app/middleware/         Phase 2 audit logging
│   └── Dockerfile              Production build
├── docker-compose.full.yml    Full local stack (frontend + backend + Postgres)
└── .github/workflows/deploy.yml   CI: test + build → CD: Azure App Service

Quick start (local dev, hot reload)

# Backend
cd backend
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt
cp .env.example .env        # add OPENAI_API_KEY if you want live LLM recommendations
docker compose up -d        # starts Postgres
uvicorn app.main:app --reload --port 8000

# Frontend (separate terminal)
cd frontend
npm install
cp .env.example .env
npm run dev

Full-stack test (what will actually run in production)

cp backend/.env.example backend/.env   # fill in real values
docker compose -f docker-compose.full.yml up --build
# frontend: http://localhost:5173  backend: http://localhost:8000/docs

Deploying to Azure

  1. Create two Azure App Service instances (Linux, container-based) — one for backend, one for frontend — plus an Azure Database for PostgreSQL (flexible server, with PostGIS enabled).
  2. In GitHub → Settings → Secrets, add: AZURE_BACKEND_APP_NAME, AZURE_BACKEND_PUBLISH_PROFILE, AZURE_FRONTEND_APP_NAME, AZURE_FRONTEND_PUBLISH_PROFILE (download publish profiles from the Azure portal).
  3. Set backend DATABASE_URL, SECRET_KEY, and OPENAI_API_KEY as Azure App Service Application Settings (never commit real secrets to .env).
  4. Push to main — .github/workflows/deploy.yml runs tests, builds both services, and deploys automatically.

Full hour-by-hour sprint breakdown: docs/UbuntuAI_5Day_Sprint_Plan.md Finalized API shapes: docs/api-contract.md

About

Status: Day 1–2 hand-coded baseline is complete and verified end-to-end. Phase 1 (AI agents), Phase 2 (security), and Phase 3 (deployment scaffolding) have now been added on top of it, per

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages