Architecture

The codebase is organized by responsibility: API routes, reusable model definitions, task-specific train/inference code, and static UI.

Directory Layout

ai/
  models/        # GCN, SAGE, GIN, Loopy implementations
  registry.py    # model discovery/load/save
  degree/        # training + prediction for degree task
  min_cycle/     # training + prediction for cycle task
  cage/          # search + RL generator logic
  trained/       # saved info.json + weights.pt artifacts

backend/
  app.py         # Flask app and static serving
  routes/        # /api/degree, /api/min_cycle, /api/cage
  utils/         # graph parsing and generation helpers

frontend/
  index.html     # landing
  degree/        # degree UI
  min_cycle/     # min-cycle UI
  cage/          # cage generator UI

Model Registry Contract

Every trained model directory must include both info.json and weights.pt. Registry functions rely on this contract for listing and loading.

Cage Session Model

Cage generation uses session IDs and background threads, with abandonment timeout and queue limit enforcement.

Cage Queue Protection

MAX_PARALLEL_GENERATIONS = 3

if active >= MAX_PARALLEL_GENERATIONS:
    return jsonify({
        "error": "Generating queue is full.",
        "active_sessions": active,
        "max_parallel_generations": MAX_PARALLEL_GENERATIONS
    }), 429
Deployment note: frontend can be static-hosted, but backend requires a persistent Python runtime because of PyTorch and session threads.