Skip to content

nirukk52/ScreenGraph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

343 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScreenGraph

Autonomous UX Mapping, Drift Detection & AI-Driven QA

AI agents crawl mobile apps, discover screens/transitions, and build a navigable knowledge graph.

What It Does

  • Autonomous exploration via UI actions
  • Real-time UX map generation
  • Visual/structural diff detection
  • Competitor UX mapping
  • Test gap identification
  • Analytics overlay on graph
  • AI agent context for RAG/planning

Who It's For

  • QA: Regression detection, exploratory testing
  • Product: UX analysis, journey mapping
  • Design: Flow consistency validation
  • Founders: Competitive benchmarking
  • Engineering: Visual bug replay

Core Concepts

  • ScreenGraph: Screens (nodes) + actions (edges)
  • Flows: Reusable step sequences
  • Perceptual Hashing: Screen uniqueness detection
  • Policies: Exploration strategies
  • Artifacts: Screenshots, XMLs, OCR, traces

🏗️ Architecture

┌─────────────────┐         ┌─────────────────┐
│   SvelteKit     │────────▶│   Encore Backend│
│   Frontend      │  REST   │   Services      │
│   (Vercel)      │  +SSE   │   (Encore Cloud)│
└─────────────────┘         └─────────────────┘
                                       │
                                       ▼
                              ┌─────────────────┐
                              │   PostgreSQL    │
                              │   + Event Store │
                              └─────────────────┘

Stack:

  • Backend: Encore.ts microservices
  • Frontend: SvelteKit 2 (Svelte 5)
  • Agent: XState-driven orchestration
  • Database: PostgreSQL with event sourcing
  • Logging: Structured logs (module/actor)

📊 ScreenGraph Storage

Single-Sink Architecture:

  • Agent writes events to run_events (append-only log)
  • Graph projection service derives screen graph
  • No dual-writes

Screen Deduplication:

  • Identified by structural layout (XML) + visual appearance (perceptual hash)
  • Same screen across runs → single canonical record
  • Tracks: first seen, last seen, visit count

Navigation Edges:

  • Captures: Screen A → Action → Screen B
  • Evidence-based traversal counts
  • Enables pathfinding + reachability analysis

API Endpoints (Planned):

  • GET /graph/:app_id - Full graph
  • GET /graph/screens/:screen_id - Screen details
  • GET /graph/:app_id/paths - Pathfinding
  • GET /graph/:app_id/coverage - Coverage metrics
  • GET /graph/:app_id/stream - Real-time SSE

🚀 Prerequisites

Install Bun:

curl -fsSL https://bun.sh/install | bash

Install Encore CLI:

# macOS
brew install encoredev/tap/encore

# Linux
curl -L https://encore.dev/install.sh | bash

📦 Setup

Clone:

git clone <repository-url>
cd ScreenGraph

Install Dependencies:

bun install
cd frontend && bun install

Environment (.env):

# Backend: Managed by Encore (encore secret set)
# Frontend: Create frontend/.env
PUBLIC_API_BASE=http://localhost:4000  # local
# PUBLIC_API_BASE=https://steering-wheel-documentation-65b2.encr.app  # prod

Run

Backend

cd backend && encore run
  • API: http://localhost:4000
  • Dashboard: http://localhost:9400

Frontend

cd frontend && bun run dev
  • UI: http://localhost:5173

Test

Backend

cd backend && encore test

Specific test:

cd backend && encore test agent/tests/determinism.test.ts

Frontend

cd frontend && bun test

🌐 Key API Endpoints

Run Management:

  • POST /run - Start agent run
  • GET /run/:id/stream - SSE event stream
  • POST /run/:id/cancel - Cancel run
  • GET /health - Health check

Event Types:

  • agent.* - Agent state transitions
  • screen.discovered - New screen found
  • screen.mapped - Screen added to graph
  • edge.created - New navigation edge
  • edge.reinforced - Existing edge traversed

📁 Project Structure

ScreenGraph/
├── backend/
│   ├── agent/              # Agent orchestration
│   │   ├── orchestrator/   # XState machine + worker
│   │   ├── nodes/          # Setup/Main/Policy/Recovery/Terminal
│   │   ├── ports/          # Interfaces
│   │   └── adapters/       # Implementations
│   ├── run/                # Run API endpoints
│   ├── graph/              # Graph projection
│   ├── artifacts/          # Screenshot/XML storage
│   └── db/migrations/      # Schema migrations
├── frontend/
│   ├── src/routes/         # SvelteKit routes
│   └── src/lib/            # Components + Encore client
├── .cursor/
│   ├── commands/           # Task automation
│   └── rules/              # Coding standards
└── vibes/                  # Engineering personas

🔧 Database

Migrations:

cd backend && encore db reset --all    # Reset dev cluster
cd backend && encore db shell db       # Shell access
cd backend && encore db migrate        # Run migrations

Test Cluster:

cd backend && encore db reset --all --test
cd backend && encore db shell db --test

🐛 Troubleshooting

Port conflicts:

lsof -ti:4000 | xargs kill    # Backend
lsof -ti:5173 | xargs kill    # Frontend

Database issues:

cd backend && encore db reset --all

Frontend sync errors:

cd frontend
rm -rf .svelte-kit node_modules
bun install
bunx svelte-kit sync
bun run dev

📤 Deployment

Backend (Encore Cloud):

encore auth login
git push encore main

Dashboard: https://app.encore.cloud/steering-wheel-documentation-65b2

Frontend (Vercel):

cd frontend && vercel --prod

Set env: PUBLIC_API_BASE=https://steering-wheel-documentation-65b2.encr.app


🔐 Secrets

Backend:

encore secret set --type prod SecretName
encore secret list

Frontend: Vercel Dashboard → Settings → Environment Variables


📊 Monitoring

Backend:

Frontend:


🎯 Status

✅ Completed:

  • Agent orchestration (XState machine)
  • Structured logging (module/actor)
  • Type-safe APIs (Encore generated clients)
  • Event sourcing + snapshots
  • Run lifecycle (start/cancel/stream)

🟡 In Progress:

  • Node handler implementation
  • Main loop (Perceive → Act → Verify)
  • Graph projection service

⏳ Upcoming:

  • LLM integration for action selection
  • Graph visualization UI
  • Multi-policy exploration
  • Analytics overlay

📚 Resources

Framework Docs:

Project Docs:

  • CLAUDE.md - Commands + quick reference
  • .cursor/rules/ - Coding standards
  • backend/agent/CLAUDE.md - Agent architecture
  • backend/graph/README.md - Graph implementation
  • backend/API_DOCUMENTATION.md - Complete API reference

External:


🤝 Contributing

Git Workflow:

git checkout -b feature/my-feature
# ... make changes ...
git commit -m "feat: description"
git push origin feature/my-feature

Standards:

  • Backend: Encore.ts conventions
  • Frontend: Svelte 5 runes ($state, $derived, $effect)
  • TypeScript: Strict mode, no any
  • Testing: All tests passing before PR

📝 License

[Your License Here]


ScreenGraph - Autonomous UX mapping for mobile apps.

For detailed commands: CLAUDE.md
For coding standards: .cursor/rules/founder_rules.mdc