SmartDoctor Self-Healing Engine

SmartDoctor is Autoflowly's automatic code repair system. It detects and fixes issues in generated MVPs — from Python syntax errors to broken JSX components — without manual intervention.

Overview

SmartDoctor runs automatically during MVP generation and is available on-demand via the Diagnose and Fix buttons in the editor.

How It Works

Detect → Fix → Verify → Repeat (up to 3 rounds)
  1. Detect — All 10 fixers scan the codebase for issues
  2. Fix — Each fixer applies targeted repairs to affected files
  3. Verify — Build validation confirms the fix worked
  4. Repeat — If issues remain, run another round (max 3 passes)

What It Fixes

SmartDoctor runs a pipeline of specialized checks, each responsible for one category of issue — critical problems (syntax, missing dependencies) are always resolved before anything downstream depends on them:

  • Python syntax — .py files that won't compile (missing commas, indentation, etc.)
  • Missing dependencies — packages your code imports but requirements.txt/package.json never declared
  • Build config — missing or broken next.config.js, tsconfig.json, Tailwind config
  • Broken JSX/TSX — unclosed tags, malformed attributes, stray template placeholders
  • Import paths — references to modules or files that don't exist where expected
  • Missing entry points — no main.py, root layout, or index page for the framework to boot
  • Tailwind syntax errors — malformed utility-class strings
  • Complex TypeScript errors — escalated to AI-assisted repair when a mechanical fix isn't safe
  • Build-time errors — anything else caught by an actual build attempt, as a final backstop

Using SmartDoctor

In the Editor

  1. Open your MVP in the editor
  2. Click "Diagnose" — SmartDoctor scans all files and reports issues
  3. Review the diagnostic report (severity, affected files, descriptions)
  4. Click "Fix All" — SmartDoctor applies all auto-fixable repairs
  5. The MVP is automatically redeployed with fixes applied

Diagnostic Report

The diagnose endpoint returns a structured report — a health score, a status, and a list of issues, each with severity, the affected files, a human-readable description, and whether it can be auto-fixed in one click.

Severity Levels

LevelMeaningImpact
criticalBuild-breakingMVP won't compile or start
errorFunctional issueFeature doesn't work correctly
warningQuality issueApp works but has problems
infoSuggestionImprovement opportunity

Python Comma Fixer

A common AI-generation artifact is missing commas in Python dictionaries and lists:

# Before (broken) config = { "key1": "value1" # ← missing comma "key2": "value2" # ← missing comma "key3": "value3" } # After (fixed) config = { "key1": "value1", "key2": "value2", "key3": "value3" }

SmartDoctor detects this class of syntax error and iteratively adds the missing commas until the file compiles clean.

JSX Tag Fixer

AI-generated React components sometimes have unclosed tags:

// Before (broken - missing closing tags) <div className="container"> <h1>Dashboard</h1> <div className="grid"> <Card title="Revenue" /> // After (fixed) <div className="container"> <h1>Dashboard</h1> <div className="grid"> <Card title="Revenue" /> </div> </div>

SmartDoctor counts opening and closing tags and appends whatever is missing.

API Endpoints

Diagnose

POST /api/conversational-mvp/editor/doctor/diagnose Content-Type: application/json { "session_id": "your-session-id", "mvp_id": "your-mvp-id" }

Fix All

POST /api/conversational-mvp/editor/doctor/fix Content-Type: application/json { "session_id": "your-session-id", "mvp_id": "your-mvp-id", "auto_redeploy": true, "create_snapshot": true }

The fix endpoint creates a snapshot before applying changes, so you can always roll back.

Automatic Healing

SmartDoctor also runs automatically:

  • During generation — after AI produces files, before deployment
  • On redeploy — when you push changes from the editor
  • On demand — via the Diagnose/Fix buttons

This multi-layered approach ensures MVPs are always in a deployable state.