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)

The 10 Fixers

SmartDoctor includes 10 pluggable fixers, each responsible for a specific category of issues:

PriorityFixerWhat It Fixes
10PythonSyntaxFixercompile() errors, missing commas, syntax issues in .py files
20DependencyFixerMissing packages in requirements.txt and package.json
30ConfigScaffoldFixerMissing or broken next.config.js, tsconfig.json, tailwind.config
40TSXSanitizerTemplate placeholder markers ({{ var_name }}), malformed JSX attributes
45JSXTagFixerUnclosed HTML/JSX tags (<div> without </div>) — build-breaking
50ImportResolutionFixerBroken import paths, missing local modules
60EntryPointFixerMissing main.py, App.tsx, index.html, or layout.tsx
70TailwindFixerBroken Tailwind class syntax like "sm": "text"-5xl
80TypeScriptAIFixerComplex TypeScript errors that need AI-assisted repair
90BuildErrorFixerCatch-all for errors found during actual build validation

Fixers run in priority order — critical issues (syntax, dependencies) are fixed first.

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:

{ "health_score": 85, "status": "needs_attention", "issues": [ { "id": "jsx_unclosed_tag_Dashboard.tsx", "severity": "critical", "category": "syntax", "title": "Unclosed JSX Tag", "description": "Dashboard.tsx has unclosed <div> tags that will break the build", "affected_files": ["frontend/src/app/dashboard/page.tsx"], "auto_fixable": true } ], "summary": "⚠️ Found 1 critical issue that can be fixed with 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's PythonSyntaxFixer detects "Perhaps you forgot a comma?" errors and iteratively adds 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>

The JSXTagFixer counts opening and closing tags and appends the missing ones.

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.