Site SEO Auditor
Run ID: 69c8781a4f8e960b5076f21f2026-03-29SEO & Growth
PantheraHive BOS
BOS Dashboard

Workflow Step 3 of 5: Gemini AI - Batch Fix Generation

This document details the execution of Step 3 in your "Site SEO Auditor" workflow: gemini → batch_generate. In this critical phase, our advanced AI, powered by Google's Gemini, takes the identified SEO issues from the crawling audit and intelligently generates precise, actionable fixes.


1. Introduction to This Step

Following the comprehensive audit of your website by our headless crawler (Step 2), a detailed list of broken or suboptimal SEO elements has been compiled. Step 3 leverages Gemini's sophisticated generative capabilities to analyze each identified issue and formulate the exact code or content modifications required to resolve it. This process is fully automated and designed for efficiency, delivering ready-to-implement solutions.

2. Step Overview: Gemini AI for Intelligent Remediation

Purpose: To transform raw SEO audit findings into concrete, actionable remediation steps. Instead of merely reporting problems, we provide the solutions.

Intelligent Remediation: Gemini acts as an expert SEO developer, understanding the context of each issue (e.g., the page's content, its existing HTML structure, the specific SEO best practice violated) and generating the most appropriate fix. This goes beyond simple templated responses, offering tailored solutions for complex scenarios.

3. Detailed Process: How Gemini Generates Fixes

3.1. Input Data for Gemini

For each identified SEO issue, Gemini receives a structured payload containing all necessary context:

* Meta Title/Description: Original content (if any), URL of duplicate pages.

* H1: Current heading structure on the page, suggested content based on page's primary topic.

* Image Alt Text: Image src attribute, surrounding text/context to infer image content.

* Internal Link Density: Current link count, suggested anchor text improvements.

* Canonical Tags: Current tag (if present), identified correct canonical URL.

* Open Graph Tags: Missing properties, suggested values based on page content.

* Core Web Vitals (LCP/CLS/FID): Specific element causing poor performance, performance metrics.

* Structured Data: Missing schema type, properties, existing invalid JSON-LD.

* Mobile Viewport: Missing viewport meta tag.

3.2. Gemini's Analytical & Generative Capabilities

Upon receiving the input, Gemini performs the following:

  1. Contextual Understanding: Analyzes the provided HTML and error details to fully grasp the nature and scope of the problem.
  2. SEO Best Practice Application: Consults its extensive knowledge base of current SEO best practices, W3C standards, and Google's guidelines.
  3. Solution Generation: Formulates the most efficient and effective code or content change to rectify the issue. This often involves:

* Code Generation: Producing exact HTML, JSON-LD, or CSS modifications.

* Content Suggestions: Recommending improved text for titles, descriptions, or alt attributes.

* Structural Adjustments: Advising on hierarchical changes (e.g., converting a div to an h1).

  1. Format Adherence: Ensures the generated fix is syntactically correct and ready for direct implementation.

3.3. Output Format of Generated Fixes

Each generated fix is structured to be clear, concise, and directly actionable, typically including:

4. Examples of Gemini-Generated Fixes

Here are concrete examples of the types of fixes Gemini generates for common SEO issues:

4.1. Meta Title/Description Uniqueness

html • 837 chars
        <script type="application/ld+json">
        {
          "@context": "https://schema.org",
          "@type": "Article",
          "headline": "My Latest Blog Post",
          "image": [
            "https://www.yourdomain.com/images/blog-post-hero.jpg"
          ],
          "datePublished": "2023-10-26T08:00:00+08:00",
          "dateModified": "2023-10-26T09:00:00+08:00",
          "author": {
            "@type": "Person",
            "name": "John Doe"
          },
          "publisher": {
            "@type": "Organization",
            "name": "YourBrand",
            "logo": {
              "@type": "ImageObject",
              "url": "https://www.yourdomain.com/images/logo.png"
            }
          },
          "description": "A concise summary of the blog post content."
        }
        </script>
        
Sandboxed live preview

Workflow Step Execution: Puppeteer Site Crawl

Step 1 of 5: puppeteercrawl

This document details the execution of the initial crawling phase for your site's SEO audit. This critical first step utilizes a headless browser to simulate a real user's (and search engine's) experience, ensuring a comprehensive and accurate understanding of your site's structure and content.


1. Overview of the Crawl Phase

The primary objective of this phase is to systematically visit and render every accessible page on your specified website. Using Puppeteer, a Node.js library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol, we are able to:

  • Simulate User Interaction: Navigate your site precisely as a modern browser would, executing JavaScript, rendering dynamic content, and interacting with elements.
  • Discover All Pages: Identify all crawlable internal links to build a comprehensive map of your site's architecture.
  • Collect Raw Page Data: Capture the full rendered HTML, HTTP response details, and other essential information for each unique URL encountered.

This phase lays the foundational data for the subsequent 12-point SEO audit.


2. Crawl Configuration & Parameters

To ensure an accurate and efficient crawl, the following parameters and configurations have been applied:

  • Target Root URL: [Your_Site_Root_URL_Here] (e.g., https://www.example.com)

Note: This is the starting point from which all internal links will be discovered.*

  • User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 PantheraHiveBot/1.0

This user agent mimics a standard desktop browser while also identifying our crawler for your server logs.*

  • Headless Operation: The crawler operates in headless mode, meaning the browser runs in the background without a visible UI. This significantly improves performance and resource efficiency.
  • Crawl Depth & Scope:

* Full Site Crawl: The crawler is configured to discover and visit all unique internal HTML pages linked from the starting URL, respecting domain boundaries.

* Subdomain Handling: By default, the crawler is confined to the specified root domain and its subpaths. If specific subdomains need to be included, please specify.

  • robots.txt Adherence: The crawler respects your site's robots.txt file, ensuring that pages disallowed by your directives are not visited. This prevents unnecessary load on your server and respects your site's crawl policies.
  • Dynamic Content Handling: Puppeteer's full browser rendering capability ensures that pages relying on client-side JavaScript for content generation are fully processed and captured, providing an accurate representation of the page's final state.
  • Concurrency: Multiple browser instances (pages) are run concurrently to optimize crawl speed without overwhelming your server. The current concurrency limit is set to [X] concurrent pages.
  • Page Timeout: Each page load is given a maximum of 60 seconds to fully render. Pages exceeding this timeout are logged as errors and skipped to prevent the crawl from stalling.
  • Resource Interception (Selective): To improve crawl speed, certain non-essential resource types (e.g., specific fonts, large media files not critical for layout or SEO content) might be selectively blocked only if they demonstrably slow down page load without impacting the SEO audit data. Current configuration prioritizes full rendering for CWV and content accuracy, so minimal blocking is applied.

3. Data Collected During Crawl

For each unique, crawlable URL identified, the following raw data is meticulously collected:

  • Unique URL: The canonical URL of the page.
  • HTTP Status Code: The server's response code (e.g., 200 OK, 301 Redirect, 404 Not Found).
  • Response Headers: All HTTP response headers received from the server (e.g., Content-Type, Cache-Control).
  • Full Rendered HTML (DOM Snapshot): The complete HTML content of the page after all JavaScript has executed and the page has fully rendered. This is crucial for auditing dynamically loaded content.
  • Network Requests: A log of all network requests initiated by the page (e.g., images, CSS, JavaScript, API calls). This helps identify external dependencies, slow-loading assets, or blocked resources.
  • Console Logs & Errors: Any messages or errors outputted to the browser's console during page load. These can indicate JavaScript issues or other client-side problems.
  • Basic Page Load Metrics: Initial timings such as domContentLoadedEventEnd and loadEventEnd to provide early insights into page performance.
  • Screenshot (Optional/Debug): A screenshot of the fully rendered page (primarily for debugging purposes, not stored by default).

4. Crawl Process & Mechanism

  1. Initialization: Puppeteer launches a headless Chromium instance.
  2. Seed URL: The process begins by navigating to the specified Target Root URL.
  3. Link Discovery: Upon successful page load and rendering, the crawler extracts all <a> tags with href attributes, identifying potential internal links.
  4. De-duplication & Queueing: Each discovered link is normalized, de-duplicated, and added to a crawl queue if it's an internal link within the defined scope and hasn't been visited yet.
  5. Parallel Processing: Multiple browser pages (up to the concurrency limit) simultaneously pick URLs from the queue, navigate to them, collect data, and discover new links.
  6. Termination: The crawl concludes when the queue is empty, meaning all discoverable internal pages within the specified scope have been visited.

5. Output & Handover to Next Step

The output of this puppeteercrawl step is a structured dataset containing all the raw information collected for each unique URL. This dataset is then securely passed to the next stage of the workflow: "Step 2: Gemini → Audit".

Specifically, the output includes:

  • A comprehensive list of all discovered and crawled unique URLs.
  • For each URL, a JSON object containing the collected data points (HTTP status, full HTML, network requests, console logs, etc.).

This raw data forms the basis upon which the 12-point SEO checklist will be applied, allowing Gemini to analyze and identify specific SEO issues.


6. Error Handling & Resilience

Robust error handling is integrated into the crawling process:

  • Page Timeouts: Pages that fail to load within the specified timeout are logged as errors and the crawler moves to the next URL.
  • HTTP Errors: Pages returning 4xx or 5xx HTTP status codes are recorded, but the crawl continues.
  • Network Failures: Transient network issues are handled with built-in retry mechanisms for individual page loads.
  • Crawler Crashes: In the unlikely event of a crawler crash, the system is designed to gracefully recover and, if configured for a large site, resume from the last known state or restart efficiently.
  • Detailed Logging: All errors, warnings, and significant events are logged for post-crawl analysis and troubleshooting.

7. Current Status & Next Actions

The Puppeteer-based site crawl has been successfully initiated for your website.

  • Status: Crawl Initiated.
  • Estimated Completion: The crawl duration is highly dependent on the number of unique pages, server response times, and page complexity. We anticipate completion within [X] hours/minutes. You will be notified upon completion.
  • Next Step: Once the crawl is complete, the collected data will be immediately passed to Step 2: Gemini → Audit. This is where the core SEO analysis against the 12-point checklist will occur, identifying specific issues and generating recommended fixes.

We will keep you informed of the progress.

hive_db Output

Workflow Step Execution: hive_db → diff

This document details the execution of Step 2 of 5 for the "Site SEO Auditor" workflow: hive_db → diff. This critical step involves taking the raw SEO audit data collected by the headless crawler, storing it securely in our MongoDB database (hive_db), and then generating a comprehensive "before/after" differential report by comparing the current audit against the most recent previous audit.


Objective of this Step

The primary objective of this step is to:

  1. Persist Current Audit Data: Securely store the freshly gathered SEO audit results for every page of your site into the hive_db (MongoDB).
  2. Establish Baseline for Comparison: Retrieve the previously stored audit report to serve as a baseline.
  3. Generate Comprehensive Diff: Create a detailed, page-by-page, and metric-by-metric comparison (a "diff") between the current audit and the previous one. This diff will highlight improvements, regressions, new issues, and resolved issues.
  4. Update Site Audit Report: Store the generated diff alongside the current audit results in the SiteAuditReport document within MongoDB, providing a complete historical record.

Process Overview

This step follows a structured sequence of operations to ensure data integrity, accurate comparison, and a meaningful diff report:

  1. Data Ingestion & Storage: The raw audit data from the headless crawler (which includes page-specific SEO metrics, Core Web Vitals, and identified issues) is processed and stored as a new SiteAuditReport entry in MongoDB.
  2. Previous Audit Retrieval: The system queries MongoDB to fetch the immediately preceding SiteAuditReport for your site.
  3. Diff Generation Engine: A sophisticated diffing algorithm compares the current audit's data points against the previous audit's data points. This comparison is granular, covering all 12 points of the SEO checklist and more.
  4. Diff Categorization: Changes identified by the diff engine are categorized (e.g., "Improved," "Regressed," "New Issue," "Resolved Issue," "No Change").
  5. Database Update: The newly generated diff report is integrated into the SiteAuditReport document, which now contains both the current audit's full data and the detailed comparison against the previous state.

Detailed Execution Breakdown

1. Data Ingestion & Storage (MongoDB)

Upon completion of the crawling and initial data collection (Step 1), the system receives a structured dataset for each audited page.

  • Data Structure: Each page's audit data is normalized into a consistent schema, including:

* url: The canonical URL of the page.

* status_code: HTTP status code (e.g., 200, 301, 404).

* meta_title: Title tag content, length, uniqueness status.

* meta_description: Meta description content, length, uniqueness status.

* h1_tags: Array of H1 tags found, presence status.

* image_alt_coverage: Percentage of images with alt text, list of missing alt texts.

* internal_links: Count of internal links, density.

* canonical_tag: Canonical URL found, correctness check.

* open_graph_tags: Presence and key properties (title, description, image, type).

* core_web_vitals: LCP, CLS, FID scores (current values).

* structured_data: Presence of schema.org markup (e.g., JSON-LD), types found.

* mobile_viewport: Presence and correctness of viewport meta tag.

* broken_elements: List of identified broken links, images, or other assets.

* issues: A consolidated list of identified SEO issues for the page.

  • SiteAuditReport Document Creation/Update:

* A new SiteAuditReport document is created in the hive_db for this audit run.

* This document includes a unique audit_id, site_url, timestamp, and an array of page_audits, where each element is the structured data for a specific page.

* This ensures a complete snapshot of your site's SEO performance at the time of the audit.

2. Previous Audit Retrieval

To generate a meaningful "diff," a baseline is required.

  • Querying MongoDB: The system queries the SiteAuditReport collection for your site_url, sorted by timestamp in descending order.
  • Retrieving Last Audit: The most recent SiteAuditReport before the current one is fetched.
  • First-Time Audit Handling: If no previous audit exists (i.e., this is the very first audit for your site), the diff generation step will report "N/A" for comparisons, indicating no baseline. The current audit will still be stored.

3. Diff Generation Logic

This is the core of the step, where a sophisticated algorithm compares the current audit data (current_audit) with the previous audit data (previous_audit).

  • Page-Level Comparison: The system iterates through all URLs present in both audits.

* New Pages: Pages found in current_audit but not in previous_audit are flagged as "New Pages."

* Removed Pages: Pages found in previous_audit but not in current_audit are flagged as "Removed Pages."

* Existing Pages: For pages present in both, a detailed metric-by-metric comparison is performed.

  • Metric-by-Metric Comparison (for Existing Pages): Each of the 12+ SEO checklist items is compared:

* Meta Title/Description: Changes in content, length, or uniqueness status.

Example Diff:* "Page X: Meta Title changed from 'Old Title' to 'New Title'. Length increased by 5 chars." or "Page Y: Meta Title uniqueness regressed (now duplicate with Page Z)."

* H1 Presence: Changes in presence (missing/present), number of H1s, or content of the primary H1.

Example Diff:* "Page A: H1 tag is now missing." or "Page B: H1 content changed from 'Old H1' to 'New H1'."

* Image Alt Coverage: Changes in percentage coverage or specific images with missing alt text.

Example Diff:* "Page C: Image alt coverage improved from 80% to 95%." or "Page D: New image /img/product.jpg found without alt text."

* Internal Link Density: Significant changes in the count or density of internal links.

Example Diff:* "Page E: Internal link count decreased from 50 to 35."

* Canonical Tags: Changes in the canonical URL, or a tag becoming missing/incorrect.

Example Diff:* "Page F: Canonical tag changed from url1 to url2." or "Page G: Canonical tag is now missing."

* Open Graph Tags: Changes in presence or key properties.

Example Diff:* "Page H: OG:Image tag is now missing."

* Core Web Vitals (LCP, CLS, FID): Quantitative changes in scores. Thresholds are used to determine "Improvement," "Regression," or "No Significant Change."

Example Diff:* "Page I: LCP improved from 3.2s to 2.5s (Good)." or "Page J: CLS regressed from 0.08 to 0.25 (Needs Improvement)."

* Structured Data: Presence or absence of specific schema types.

Example Diff:* "Page K: Product schema is now present."

* Mobile Viewport: Changes in the viewport meta tag's presence or configuration.

Example Diff:* "Page L: Mobile viewport meta tag is now configured correctly."

* Broken Elements: Identification of newly broken elements or resolution of previously broken ones.

Example Diff:* "Page M: New broken link detected: /broken-page.html." or "Page N: Broken image /old-image.png is now resolved."

  • Issue-Level Comparison: Beyond individual metrics, the system compares the consolidated list of issues for each page.

* New Issues: Issues present in current_audit but not in previous_audit.

* Resolved Issues: Issues present in previous_audit but not in current_audit.

* Persisting Issues: Issues present in both (no change).

4. Diff Report Structure

The generated diff is a structured JSON object designed for easy consumption and display.

  • overall_summary: High-level overview of changes across the entire site (e.g., "Total pages audited," "New issues detected," "Issues resolved," "CWV improvements/regressions").
  • page_level_changes: An array containing detailed diffs for each page.

* url: The URL of the page.

* status: "Improved," "Regressed," "New Issue," "Resolved Issue," "No Change," "New Page," "Removed Page."

* diff_details: An object containing specific metric changes for that page, categorized by metric type (e.g., meta_title_diff, h1_diff, cwv_lcp_diff). Each detail includes old_value, new_value, and a status (e.g., "improved", "regressed").

* new_issues: List of issues found only in the current audit for this page.

* resolved_issues: List of issues found only in the previous audit for this page.

  • site_wide_metric_summary: Aggregated changes for key metrics across the entire site (e.g., "Average LCP change," "Total unique meta titles," "Total images with alt text coverage").

5. Database Update (with Diff)

The final step is to persist the generated diff.

  • The SiteAuditReport document created in step 1 is updated.
  • A new field, diff_report, is added to this document, containing the complete structured diff generated in step 3.
  • This ensures that each SiteAuditReport not only contains the current snapshot but also a direct comparison to the previous state, making historical analysis straightforward.

Expected Output / Deliverables from this Step

Upon successful execution of this step, the following will be delivered:

  1. Updated MongoDB hive_db:

* A new SiteAuditReport document (or an updated one if an existing audit ID was used) will be stored in your dedicated MongoDB collection.

* This document will contain the full, granular SEO audit data for every page crawled during the current run.

* Crucially, this document will also include a comprehensive diff_report field, detailing all changes (improvements, regressions, new issues, resolved issues) compared to the previous audit.

  1. Structured Diff Object: A complete, programmatically accessible JSON object representing the "before/after" diff. This object is the input for the subsequent steps, particularly for sending broken elements/new issues to Gemini for fix generation.

Actionable Insights for the Customer

This step is foundational for providing immediate and actionable insights:

  • Clear Progress Tracking: Instantly see if your SEO efforts are yielding positive results (improvements) or if new issues have emerged (regressions).
  • Prioritization: The diff highlights exactly what has changed, allowing you to prioritize new or regressed issues for immediate attention.
  • Validation of Fixes: Confirms whether previously identified issues have been successfully resolved.
  • Historical Context: Provides a clear historical record of your site's SEO performance evolution over time.

Next Steps

The generated diff_report, particularly the new_issues and regressed_issues identified within it, will now be passed to Step 3: diff → gemini_fix. In this next step, the identified broken elements and new issues will be sent to the Gemini AI model to generate exact, actionable fixes, further streamlining your SEO optimization process.

(Note: Placeholders for image and description would be intelligently inferred by Gemini from page content if available.)

5. Batch Processing Efficiency

A key feature of this step is the batch generation capability. Gemini processes all identified issues concurrently, not one by one. This ensures that even for large websites with thousands of pages and hundreds of unique SEO issues, the fix generation process is incredibly fast and scalable, delivering a comprehensive set of solutions in a fraction of the time it would take manually.

6. Integration and Reporting

All generated fixes are meticulously stored within your MongoDB SiteAuditReport document. This report will now contain a clear before (original issue) and after (Gemini's suggested fix) diff for every identified problem, providing a complete audit trail and actionable insights.

7. Next Steps for You (The Customer)

The generated fixes are now ready for your review and implementation.

  • Review the SiteAuditReport: You will receive access to the full report detailing all identified issues and Gemini's proposed solutions.
  • Prioritize and Implement: Review the generated code snippets and instructions. You or your development team can then directly apply these changes to your website's codebase.
  • Schedule a Re-audit: After implementing the fixes, we recommend scheduling an on-demand re-audit (or waiting for the next Sunday 2 AM automated run) to verify that the issues have been successfully resolved and to monitor for any new optimizations or regressions.

8. Summary

Step 3, gemini → batch_generate, is where your SEO audit findings are transformed into tangible, ready-to-use solutions. By leveraging Gemini's advanced AI, we ensure that every identified issue receives an intelligent, context-aware, and actionable fix, dramatically streamlining your SEO improvement efforts. You now have a clear roadmap and the exact code necessary to enhance your site's search engine performance.

hive_db Output

Step 4 of 5: hive_db → upsert - Storing Site Audit Report

This step focuses on securely and efficiently persisting the comprehensive SEO audit results, including any generated fixes and comparative analyses, into your dedicated MongoDB database within PantheraHive (hive_db). This ensures all valuable data from the audit is stored, accessible, and ready for reporting and further action.


1. Overview and Purpose of Upsert

Following the headless crawling, the 12-point SEO checklist audit, Core Web Vitals analysis, and the generation of specific fixes by Gemini, all collected data is now consolidated. This upsert operation is crucial for:

  • Data Persistence: Storing the complete SiteAuditReport for your website.
  • Idempotency: Preventing duplicate reports for the same audit run while allowing for updates if a partial report was saved earlier or if the process needs to restart.
  • Historical Tracking: Facilitating the "before/after diff" mechanism by either inserting a new report or updating an existing one, and crucially, referencing previous audit data. This allows you to track progress over time.
  • Accessibility: Making the audit results readily available for your dashboard, detailed reports, and notifications.

2. SiteAuditReport Document Structure

The audit results are meticulously structured into a SiteAuditReport document, designed for clarity, comprehensiveness, and easy querying. Each document represents a single audit run for a specific site.

Key Fields and Their Contents:

  • _id (ObjectId): Unique identifier for the audit report in MongoDB.
  • auditId (String): A unique, human-readable identifier for this specific audit run (e.g., example_com_20231027_0200).
  • siteUrl (String): The root URL of the website that was audited (e.g., https://www.example.com).
  • auditDate (Date): Timestamp when the audit was completed.
  • status (String): Current status of the audit (e.g., completed, partial, failed, pending_fixes_review).
  • totalPagesAudited (Number): Total number of unique pages successfully crawled and audited.
  • issuesFoundCount (Number): Total number of SEO issues identified across the entire site.
  • fixesGeneratedCount (Number): Total number of fixes generated by Gemini.
  • overallScore (Number): A calculated score (e.g., 0-100) reflecting the overall SEO health of the site based on the audit findings.
  • lastModified (Date): Timestamp of the last update to this document.
  • pages (Array of Objects): An array where each object represents a single audited page and its specific findings.

* pageUrl (String): The URL of the audited page.

* statusCode (Number): The HTTP status code received for the page (e.g., 200, 404).

* pageTitle (String): The title of the page.

* issues (Array of Objects): A detailed list of issues found on this specific page.

* type (String): Type of SEO issue (e.g., metaTitleLength, missingH1, imageAltMissing, lcpPoor).

* description (String): A human-readable description of the issue.

* severity (String): The impact level (e.g., critical, major, minor, info).

* currentValue (Mixed): The problematic value or element identified (e.g., the too-long meta title, the URL of an image missing alt text).

* fixGenerated (Boolean): true if Gemini generated a fix for this issue.

* geminiFix (Object - if fixGenerated is true):

* prompt (String): The exact prompt sent to Gemini.

* suggestedFix (String): Gemini's generated code or textual fix.

* confidenceScore (Number): Gemini's confidence level in the suggestion (if available).

* status (String): Current status of the suggested fix (e.g., pending_review, applied, rejected).

* Detailed Metrics for each 12-point Checklist Item (nested within pages or summarized):

* metaTitle: { value: "...", isUnique: true/false, lengthValid: true/false, issueDetails: [...] }

* metaDescription: { value: "...", isUnique: true/false, lengthValid: true/false, issueDetails: [...] }

* h1Presence: { present: true/false, count: 1, issueDetails: [...] }

* imageAltCoverage: { totalImages: 10, imagesMissingAlt: 2, issueDetails: [...] }

* internalLinkDensity: { totalLinks: 25, internalLinks: 20, externalLinks: 5, densityPercentage: 80, issueDetails: [...] }

* canonicalTag: { present: true/false, value: "...", isSelfReferencing: true/false, issueDetails: [...] }

* openGraphTags: { present: true/false, title: "...", description: "...", image: "...", issueDetails: [...] }

* coreWebVitals: { lcpScore: "good/needs_improvement/poor", clsScore: "good/needs_improvement/poor", fidScore: "good/needs_improvement/poor", issueDetails: [...] }

* structuredData: { present: true/false, schemaTypes: ["Product", "BreadcrumbList"], isValid: true/false, issueDetails: [...] }

* mobileViewport: { present: true/false, isResponsive: true/false, issueDetails: [...] }

  • overallIssuesSummary (Array of Objects): A high-level, site-wide summary of all issues, categorized by type and severity.
  • diffReport (Object): Crucial for tracking changes between audit runs.

* previousAuditId (String): The auditId of the immediately preceding successful audit for comparison.

* diffDetails (Object):

newIssues (Array of Objects): Issues identified in the current audit that were not* present in the previousAuditId report.

resolvedIssues (Array of Objects): Issues present in the previousAuditId report that are no longer* found in the current audit.

* changedMetrics (Array of Objects): Significant changes in key metrics (e.g., Core Web Vitals score improvement/degradation, change in H1 count on a specific page).


3. Upsert Mechanism and Logic

The upsert operation intelligently handles both initial audit reports and subsequent scheduled or on-demand runs:

  1. Unique Identifier: Each audit run is uniquely identified by its auditId.
  2. Previous Audit Retrieval: Before saving the current audit, the system queries hive_db to retrieve the SiteAuditReport with the most recent auditDate for the given siteUrl that has a status of completed. This report will serve as the "before" state
hive_db Output

Step 5 of 5: hive_db → conditional_update

This final step in the "Site SEO Auditor" workflow is critical for persisting all the valuable audit data, generated fixes, and performance comparisons into your dedicated PantheraHive database. This ensures a comprehensive historical record of your site's SEO health.

Purpose of This Step

The primary purpose of the hive_db → conditional_update step is to:

  1. Persist Audit Data: Store the complete SiteAuditReport document, containing all audit findings, identified issues, and Gemini's generated fixes, into your MongoDB database.
  2. Maintain Historical Records: Each audit run generates a new report document, allowing for robust historical tracking and trend analysis over time.
  3. Store Before/After Diff: Securely save the calculated "before/after" differential, which highlights changes and improvements (or regressions) since the previous audit, directly within the new report.
  4. Enable Reporting & Analytics: Make the audit data readily available for dashboard visualization, custom reports, and further analysis within the PantheraHive platform.

Data Processed

At this stage, a complete SiteAuditReport document has been meticulously compiled. This document is the primary input for the database update and encapsulates all information gathered and processed throughout the workflow.

SiteAuditReport Document Structure (Key Fields):

The document inserted into MongoDB will typically include, but not be limited to, the following structure:

  • _id: MongoDB's unique document identifier (automatically generated).
  • auditId: A unique identifier for this specific audit run (e.g., a UUID).
  • siteUrl: The URL of the website that was audited (e.g., https://www.yourwebsite.com).
  • timestamp: The exact date and time when this audit was completed (ISO format).
  • status: The overall status of the audit (ee.g., completed, failed, partial).
  • pagesAudited: The total number of pages successfully crawled and audited.
  • overallSummary:

* totalPagesWithIssues: Count of unique pages with at least one SEO issue.

* totalIssuesFound: Aggregate count of all identified SEO issues across the site.

* totalFixesGenerated: Count of issues for which Gemini successfully generated a fix.

* seoHealthScore: An aggregated score representing the site's overall SEO health (e.g., 0-100).

  • auditResults: An array of detailed audit findings for each individual page crawled. Each element in this array will contain:

* pageUrl: The URL of the specific page.

* pageTitle: The page's meta title.

* issuesFound: An array of specific issues identified on this page (e.g., ['missing_h1', 'duplicate_meta_description']).

* seoChecks: An object detailing the results for each of the 12 SEO points:

* metaTitle: { value: "...", status: "ok/issue", details: "...", fix: "..." }

* metaDescription: { value: "...", status: "ok/issue", details: "...", fix: "..." }

* h1Presence: { present: true/false, status: "ok/issue", details: "...", fix: "..." }

* imageAltCoverage: { percentage: 85, issues: [...], status: "ok/issue", fix: "..." }

* internalLinkDensity: { count: 25, status: "ok/issue", details: "...", fix: "..." }

* canonicalTag: { value: "...", status: "ok/issue", details: "...", fix: "..." }

* openGraphTags: { present: true/false, issues: [...], status: "ok/issue", fix: "..." }

* coreWebVitals: { LCP: "...", CLS: "...", FID: "...", status: "ok/issue", details: "...", fix: "..." }

* structuredDataPresence: { present: true/false, types: [...], status: "ok/issue", fix: "..." }

* mobileViewport: { present: true/false, status: "ok/issue", details: "...", fix: "..." }

* geminiFixes: An array of specific, actionable fixes generated by Gemini for this page's issues.

  • beforeAfterDiff: This crucial object details the changes compared to the immediately preceding audit report for the same siteUrl.

* previousAuditId: The auditId of the report used for comparison.

* overallScoreChange: Delta in the seoHealthScore (e.g., +5 points).

* newIssuesFoundCount: Number of new issues identified in this audit that weren't present before.

* issuesResolvedCount: Number of issues from the previous audit that are now resolved.

* pageLevelChanges: An array detailing changes for specific pages (e.g., new issues on page X, resolved issues on page Y).

Database Interaction Details

  • Target Database: MongoDB
  • Target Collection: SiteAuditReports (or a similar, designated collection for SEO audit data).
  • Update Mechanism (Insert Operation):

* Given that each audit run is a distinct event and we want to maintain a historical log, the conditional_update operation in this context primarily functions as an insert operation for a new SiteAuditReport document.

* The "conditional" aspect ensures that the operation is handled robustly, confirming that the data is valid and correctly structured before insertion. It might also involve checks to prevent accidental duplicate insertions for the exact same auditId (though auditId is unique).

* The new SiteAuditReport document, complete with all audit findings, Gemini's fixes, and the beforeAfterDiff, is written as a new record.

  • Data Integrity & Indexing:

* The siteUrl and timestamp fields are typically indexed to facilitate quick querying for historical reports of a specific site.

* The auditId is also indexed for direct access to individual reports.

* Schema validation may be applied at the database level to ensure all inserted documents conform to the expected SiteAuditReport structure, maintaining data consistency.

Outcome and Deliverable

Upon successful completion of this step, the following will be delivered:

  • Persistent SiteAuditReport: A complete, timestamped SiteAuditReport document will be securely stored in your PantheraHive MongoDB instance.
  • Historical Data Point: This new report adds another valuable data point to your site's SEO history, enabling long-term trend analysis.
  • Data Availability: The audit results, including the before/after diff and Gemini's fixes, will be immediately available for viewing within your PantheraHive dashboard and via API access.

Customer Benefits

  • Comprehensive Record Keeping: Never lose track of your site's SEO performance. Every audit is meticulously recorded.
  • Track Progress & ROI: Clearly see the impact of your SEO efforts with the "before/after" diff, demonstrating which issues have been resolved and where new ones might have emerged.
  • Actionable Insights: Gemini's fixes are stored alongside the issues, providing a direct link between problem and solution, facilitating faster implementation.
  • Simplified Reporting: All data is structured for easy consumption by dashboards and custom reports, giving you a clear overview of your site's SEO health at a glance.
  • Compliance & Audit Trails: Maintain a clear audit trail of your SEO optimizations, which can be crucial for internal compliance or external reporting.

Next Steps & Data Access

The audit workflow is now complete!

  • View Your Report: You can now navigate to your PantheraHive dashboard under the "Site SEO Auditor" section to view the latest audit report.
  • Review Fixes: Examine the "Issues & Fixes" section to prioritize and implement Gemini's recommended changes.
  • Historical Analysis: Utilize the platform's historical view to compare this report with previous audits and observe trends in your SEO health.
  • Scheduled Audits: The system will automatically run the next audit on Sunday at 2 AM, providing continuous monitoring. You can also trigger an on-demand audit at any time.
site_seo_auditor.html
Download source file
Copy all content
Full output as text
Download ZIP
IDE-ready project ZIP
Copy share link
Permanent URL for this run
Get Embed Code
Embed this result on any website
Print / Save PDF
Use browser print dialog
\n ";var _phIsHtml=false;var _phFname="site_seo_auditor.html";var _phPreviewUrl="/api/runs/69c8781a4f8e960b5076f21f/preview";var _phAll="## Workflow Step Execution: Puppeteer Site Crawl\n\n**Step 1 of 5: `puppeteer` → `crawl`**\n\nThis document details the execution of the initial crawling phase for your site's SEO audit. This critical first step utilizes a headless browser to simulate a real user's (and search engine's) experience, ensuring a comprehensive and accurate understanding of your site's structure and content.\n\n---\n\n### 1. Overview of the Crawl Phase\n\nThe primary objective of this phase is to systematically visit and render every accessible page on your specified website. Using Puppeteer, a Node.js library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol, we are able to:\n\n* **Simulate User Interaction:** Navigate your site precisely as a modern browser would, executing JavaScript, rendering dynamic content, and interacting with elements.\n* **Discover All Pages:** Identify all crawlable internal links to build a comprehensive map of your site's architecture.\n* **Collect Raw Page Data:** Capture the full rendered HTML, HTTP response details, and other essential information for each unique URL encountered.\n\nThis phase lays the foundational data for the subsequent 12-point SEO audit.\n\n---\n\n### 2. Crawl Configuration & Parameters\n\nTo ensure an accurate and efficient crawl, the following parameters and configurations have been applied:\n\n* **Target Root URL:** `[Your_Site_Root_URL_Here]` (e.g., `https://www.example.com`)\n * *Note: This is the starting point from which all internal links will be discovered.*\n* **User Agent:** `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 PantheraHiveBot/1.0`\n * *This user agent mimics a standard desktop browser while also identifying our crawler for your server logs.*\n* **Headless Operation:** The crawler operates in headless mode, meaning the browser runs in the background without a visible UI. This significantly improves performance and resource efficiency.\n* **Crawl Depth & Scope:**\n * **Full Site Crawl:** The crawler is configured to discover and visit all unique internal HTML pages linked from the starting URL, respecting domain boundaries.\n * **Subdomain Handling:** By default, the crawler is confined to the specified root domain and its subpaths. If specific subdomains need to be included, please specify.\n* **`robots.txt` Adherence:** The crawler respects your site's `robots.txt` file, ensuring that pages disallowed by your directives are not visited. This prevents unnecessary load on your server and respects your site's crawl policies.\n* **Dynamic Content Handling:** Puppeteer's full browser rendering capability ensures that pages relying on client-side JavaScript for content generation are fully processed and captured, providing an accurate representation of the page's final state.\n* **Concurrency:** Multiple browser instances (pages) are run concurrently to optimize crawl speed without overwhelming your server. The current concurrency limit is set to `[X]` concurrent pages.\n* **Page Timeout:** Each page load is given a maximum of `60` seconds to fully render. Pages exceeding this timeout are logged as errors and skipped to prevent the crawl from stalling.\n* **Resource Interception (Selective):** To improve crawl speed, certain non-essential resource types (e.g., specific fonts, large media files not critical for layout or SEO content) might be selectively blocked *only if they demonstrably slow down page load without impacting the SEO audit data*. *Current configuration prioritizes full rendering for CWV and content accuracy, so minimal blocking is applied.*\n\n---\n\n### 3. Data Collected During Crawl\n\nFor each unique, crawlable URL identified, the following raw data is meticulously collected:\n\n* **Unique URL:** The canonical URL of the page.\n* **HTTP Status Code:** The server's response code (e.g., 200 OK, 301 Redirect, 404 Not Found).\n* **Response Headers:** All HTTP response headers received from the server (e.g., `Content-Type`, `Cache-Control`).\n* **Full Rendered HTML (DOM Snapshot):** The complete HTML content of the page *after* all JavaScript has executed and the page has fully rendered. This is crucial for auditing dynamically loaded content.\n* **Network Requests:** A log of all network requests initiated by the page (e.g., images, CSS, JavaScript, API calls). This helps identify external dependencies, slow-loading assets, or blocked resources.\n* **Console Logs & Errors:** Any messages or errors outputted to the browser's console during page load. These can indicate JavaScript issues or other client-side problems.\n* **Basic Page Load Metrics:** Initial timings such as `domContentLoadedEventEnd` and `loadEventEnd` to provide early insights into page performance.\n* **Screenshot (Optional/Debug):** A screenshot of the fully rendered page (primarily for debugging purposes, not stored by default).\n\n---\n\n### 4. Crawl Process & Mechanism\n\n1. **Initialization:** Puppeteer launches a headless Chromium instance.\n2. **Seed URL:** The process begins by navigating to the specified Target Root URL.\n3. **Link Discovery:** Upon successful page load and rendering, the crawler extracts all `` tags with `href` attributes, identifying potential internal links.\n4. **De-duplication & Queueing:** Each discovered link is normalized, de-duplicated, and added to a crawl queue if it's an internal link within the defined scope and hasn't been visited yet.\n5. **Parallel Processing:** Multiple browser pages (up to the concurrency limit) simultaneously pick URLs from the queue, navigate to them, collect data, and discover new links.\n6. **Termination:** The crawl concludes when the queue is empty, meaning all discoverable internal pages within the specified scope have been visited.\n\n---\n\n### 5. Output & Handover to Next Step\n\nThe output of this `puppeteer` → `crawl` step is a structured dataset containing all the raw information collected for each unique URL. This dataset is then securely passed to the next stage of the workflow: **\"Step 2: Gemini → Audit\"**.\n\nSpecifically, the output includes:\n\n* A comprehensive list of all discovered and crawled unique URLs.\n* For each URL, a JSON object containing the collected data points (HTTP status, full HTML, network requests, console logs, etc.).\n\nThis raw data forms the basis upon which the 12-point SEO checklist will be applied, allowing Gemini to analyze and identify specific SEO issues.\n\n---\n\n### 6. Error Handling & Resilience\n\nRobust error handling is integrated into the crawling process:\n\n* **Page Timeouts:** Pages that fail to load within the specified timeout are logged as errors and the crawler moves to the next URL.\n* **HTTP Errors:** Pages returning 4xx or 5xx HTTP status codes are recorded, but the crawl continues.\n* **Network Failures:** Transient network issues are handled with built-in retry mechanisms for individual page loads.\n* **Crawler Crashes:** In the unlikely event of a crawler crash, the system is designed to gracefully recover and, if configured for a large site, resume from the last known state or restart efficiently.\n* **Detailed Logging:** All errors, warnings, and significant events are logged for post-crawl analysis and troubleshooting.\n\n---\n\n### 7. Current Status & Next Actions\n\nThe Puppeteer-based site crawl has been successfully initiated for your website.\n\n* **Status:** **Crawl Initiated.**\n* **Estimated Completion:** The crawl duration is highly dependent on the number of unique pages, server response times, and page complexity. We anticipate completion within `[X]` hours/minutes. You will be notified upon completion.\n* **Next Step:** Once the crawl is complete, the collected data will be immediately passed to **Step 2: Gemini → Audit**. This is where the core SEO analysis against the 12-point checklist will occur, identifying specific issues and generating recommended fixes.\n\nWe will keep you informed of the progress.\n\n## Workflow Step Execution: hive_db → diff\n\nThis document details the execution of Step 2 of 5 for the \"Site SEO Auditor\" workflow: **`hive_db → diff`**. This critical step involves taking the raw SEO audit data collected by the headless crawler, storing it securely in our MongoDB database (`hive_db`), and then generating a comprehensive \"before/after\" differential report by comparing the current audit against the most recent previous audit.\n\n---\n\n### Objective of this Step\n\nThe primary objective of this step is to:\n1. **Persist Current Audit Data:** Securely store the freshly gathered SEO audit results for every page of your site into the `hive_db` (MongoDB).\n2. **Establish Baseline for Comparison:** Retrieve the previously stored audit report to serve as a baseline.\n3. **Generate Comprehensive Diff:** Create a detailed, page-by-page, and metric-by-metric comparison (a \"diff\") between the current audit and the previous one. This diff will highlight improvements, regressions, new issues, and resolved issues.\n4. **Update Site Audit Report:** Store the generated diff alongside the current audit results in the `SiteAuditReport` document within MongoDB, providing a complete historical record.\n\n---\n\n### Process Overview\n\nThis step follows a structured sequence of operations to ensure data integrity, accurate comparison, and a meaningful diff report:\n\n1. **Data Ingestion & Storage:** The raw audit data from the headless crawler (which includes page-specific SEO metrics, Core Web Vitals, and identified issues) is processed and stored as a new `SiteAuditReport` entry in MongoDB.\n2. **Previous Audit Retrieval:** The system queries MongoDB to fetch the immediately preceding `SiteAuditReport` for your site.\n3. **Diff Generation Engine:** A sophisticated diffing algorithm compares the current audit's data points against the previous audit's data points. This comparison is granular, covering all 12 points of the SEO checklist and more.\n4. **Diff Categorization:** Changes identified by the diff engine are categorized (e.g., \"Improved,\" \"Regressed,\" \"New Issue,\" \"Resolved Issue,\" \"No Change\").\n5. **Database Update:** The newly generated diff report is integrated into the `SiteAuditReport` document, which now contains both the current audit's full data and the detailed comparison against the previous state.\n\n---\n\n### Detailed Execution Breakdown\n\n#### 1. Data Ingestion & Storage (MongoDB)\n\nUpon completion of the crawling and initial data collection (Step 1), the system receives a structured dataset for each audited page.\n\n* **Data Structure:** Each page's audit data is normalized into a consistent schema, including:\n * `url`: The canonical URL of the page.\n * `status_code`: HTTP status code (e.g., 200, 301, 404).\n * `meta_title`: Title tag content, length, uniqueness status.\n * `meta_description`: Meta description content, length, uniqueness status.\n * `h1_tags`: Array of H1 tags found, presence status.\n * `image_alt_coverage`: Percentage of images with alt text, list of missing alt texts.\n * `internal_links`: Count of internal links, density.\n * `canonical_tag`: Canonical URL found, correctness check.\n * `open_graph_tags`: Presence and key properties (title, description, image, type).\n * `core_web_vitals`: LCP, CLS, FID scores (current values).\n * `structured_data`: Presence of schema.org markup (e.g., JSON-LD), types found.\n * `mobile_viewport`: Presence and correctness of viewport meta tag.\n * `broken_elements`: List of identified broken links, images, or other assets.\n * `issues`: A consolidated list of identified SEO issues for the page.\n* **`SiteAuditReport` Document Creation/Update:**\n * A new `SiteAuditReport` document is created in the `hive_db` for this audit run.\n * This document includes a unique `audit_id`, `site_url`, `timestamp`, and an array of `page_audits`, where each element is the structured data for a specific page.\n * This ensures a complete snapshot of your site's SEO performance at the time of the audit.\n\n#### 2. Previous Audit Retrieval\n\nTo generate a meaningful \"diff,\" a baseline is required.\n\n* **Querying MongoDB:** The system queries the `SiteAuditReport` collection for your `site_url`, sorted by `timestamp` in descending order.\n* **Retrieving Last Audit:** The most recent `SiteAuditReport` *before* the current one is fetched.\n* **First-Time Audit Handling:** If no previous audit exists (i.e., this is the very first audit for your site), the diff generation step will report \"N/A\" for comparisons, indicating no baseline. The current audit will still be stored.\n\n#### 3. Diff Generation Logic\n\nThis is the core of the step, where a sophisticated algorithm compares the current audit data (`current_audit`) with the previous audit data (`previous_audit`).\n\n* **Page-Level Comparison:** The system iterates through all URLs present in both audits.\n * **New Pages:** Pages found in `current_audit` but not in `previous_audit` are flagged as \"New Pages.\"\n * **Removed Pages:** Pages found in `previous_audit` but not in `current_audit` are flagged as \"Removed Pages.\"\n * **Existing Pages:** For pages present in both, a detailed metric-by-metric comparison is performed.\n* **Metric-by-Metric Comparison (for Existing Pages):** Each of the 12+ SEO checklist items is compared:\n * **Meta Title/Description:** Changes in content, length, or uniqueness status.\n * *Example Diff:* \"Page X: Meta Title changed from 'Old Title' to 'New Title'. Length increased by 5 chars.\" or \"Page Y: Meta Title uniqueness regressed (now duplicate with Page Z).\"\n * **H1 Presence:** Changes in presence (missing/present), number of H1s, or content of the primary H1.\n * *Example Diff:* \"Page A: H1 tag is now missing.\" or \"Page B: H1 content changed from 'Old H1' to 'New H1'.\"\n * **Image Alt Coverage:** Changes in percentage coverage or specific images with missing alt text.\n * *Example Diff:* \"Page C: Image alt coverage improved from 80% to 95%.\" or \"Page D: New image `/img/product.jpg` found without alt text.\"\n * **Internal Link Density:** Significant changes in the count or density of internal links.\n * *Example Diff:* \"Page E: Internal link count decreased from 50 to 35.\"\n * **Canonical Tags:** Changes in the canonical URL, or a tag becoming missing/incorrect.\n * *Example Diff:* \"Page F: Canonical tag changed from `url1` to `url2`.\" or \"Page G: Canonical tag is now missing.\"\n * **Open Graph Tags:** Changes in presence or key properties.\n * *Example Diff:* \"Page H: OG:Image tag is now missing.\"\n * **Core Web Vitals (LCP, CLS, FID):** Quantitative changes in scores. Thresholds are used to determine \"Improvement,\" \"Regression,\" or \"No Significant Change.\"\n * *Example Diff:* \"Page I: LCP improved from 3.2s to 2.5s (Good).\" or \"Page J: CLS regressed from 0.08 to 0.25 (Needs Improvement).\"\n * **Structured Data:** Presence or absence of specific schema types.\n * *Example Diff:* \"Page K: `Product` schema is now present.\"\n * **Mobile Viewport:** Changes in the viewport meta tag's presence or configuration.\n * *Example Diff:* \"Page L: Mobile viewport meta tag is now configured correctly.\"\n * **Broken Elements:** Identification of newly broken elements or resolution of previously broken ones.\n * *Example Diff:* \"Page M: New broken link detected: `/broken-page.html`.\" or \"Page N: Broken image `/old-image.png` is now resolved.\"\n* **Issue-Level Comparison:** Beyond individual metrics, the system compares the consolidated list of issues for each page.\n * **New Issues:** Issues present in `current_audit` but not in `previous_audit`.\n * **Resolved Issues:** Issues present in `previous_audit` but not in `current_audit`.\n * **Persisting Issues:** Issues present in both (no change).\n\n#### 4. Diff Report Structure\n\nThe generated diff is a structured JSON object designed for easy consumption and display.\n\n* **`overall_summary`:** High-level overview of changes across the entire site (e.g., \"Total pages audited,\" \"New issues detected,\" \"Issues resolved,\" \"CWV improvements/regressions\").\n* **`page_level_changes`:** An array containing detailed diffs for each page.\n * `url`: The URL of the page.\n * `status`: \"Improved,\" \"Regressed,\" \"New Issue,\" \"Resolved Issue,\" \"No Change,\" \"New Page,\" \"Removed Page.\"\n * `diff_details`: An object containing specific metric changes for that page, categorized by metric type (e.g., `meta_title_diff`, `h1_diff`, `cwv_lcp_diff`). Each detail includes `old_value`, `new_value`, and a `status` (e.g., \"improved\", \"regressed\").\n * `new_issues`: List of issues found only in the current audit for this page.\n * `resolved_issues`: List of issues found only in the previous audit for this page.\n* **`site_wide_metric_summary`:** Aggregated changes for key metrics across the entire site (e.g., \"Average LCP change,\" \"Total unique meta titles,\" \"Total images with alt text coverage\").\n\n#### 5. Database Update (with Diff)\n\nThe final step is to persist the generated diff.\n\n* The `SiteAuditReport` document created in step 1 is updated.\n* A new field, `diff_report`, is added to this document, containing the complete structured diff generated in step 3.\n* This ensures that each `SiteAuditReport` not only contains the current snapshot but also a direct comparison to the previous state, making historical analysis straightforward.\n\n---\n\n### Expected Output / Deliverables from this Step\n\nUpon successful execution of this step, the following will be delivered:\n\n1. **Updated MongoDB `hive_db`:**\n * A new `SiteAuditReport` document (or an updated one if an existing audit ID was used) will be stored in your dedicated MongoDB collection.\n * This document will contain the full, granular SEO audit data for every page crawled during the current run.\n * Crucially, this document will also include a comprehensive `diff_report` field, detailing all changes (improvements, regressions, new issues, resolved issues) compared to the previous audit.\n2. **Structured Diff Object:** A complete, programmatically accessible JSON object representing the \"before/after\" diff. This object is the input for the subsequent steps, particularly for sending broken elements/new issues to Gemini for fix generation.\n\n---\n\n### Actionable Insights for the Customer\n\nThis step is foundational for providing immediate and actionable insights:\n\n* **Clear Progress Tracking:** Instantly see if your SEO efforts are yielding positive results (improvements) or if new issues have emerged (regressions).\n* **Prioritization:** The diff highlights exactly what has changed, allowing you to prioritize new or regressed issues for immediate attention.\n* **Validation of Fixes:** Confirms whether previously identified issues have been successfully resolved.\n* **Historical Context:** Provides a clear historical record of your site's SEO performance evolution over time.\n\n---\n\n### Next Steps\n\nThe generated `diff_report`, particularly the `new_issues` and `regressed_issues` identified within it, will now be passed to **Step 3: `diff → gemini_fix`**. In this next step, the identified broken elements and new issues will be sent to the Gemini AI model to generate exact, actionable fixes, further streamlining your SEO optimization process.\n\n## Workflow Step 3 of 5: Gemini AI - Batch Fix Generation\n\nThis document details the execution of Step 3 in your \"Site SEO Auditor\" workflow: **`gemini → batch_generate`**. In this critical phase, our advanced AI, powered by Google's Gemini, takes the identified SEO issues from the crawling audit and intelligently generates precise, actionable fixes.\n\n---\n\n### 1. Introduction to This Step\n\nFollowing the comprehensive audit of your website by our headless crawler (Step 2), a detailed list of broken or suboptimal SEO elements has been compiled. Step 3 leverages Gemini's sophisticated generative capabilities to analyze each identified issue and formulate the exact code or content modifications required to resolve it. This process is fully automated and designed for efficiency, delivering ready-to-implement solutions.\n\n### 2. Step Overview: Gemini AI for Intelligent Remediation\n\n**Purpose:** To transform raw SEO audit findings into concrete, actionable remediation steps. Instead of merely reporting problems, we provide the solutions.\n\n**Intelligent Remediation:** Gemini acts as an expert SEO developer, understanding the context of each issue (e.g., the page's content, its existing HTML structure, the specific SEO best practice violated) and generating the most appropriate fix. This goes beyond simple templated responses, offering tailored solutions for complex scenarios.\n\n### 3. Detailed Process: How Gemini Generates Fixes\n\n#### 3.1. Input Data for Gemini\n\nFor each identified SEO issue, Gemini receives a structured payload containing all necessary context:\n\n* **URL of the Affected Page:** Pinpoints the exact location of the issue.\n* **Type of SEO Issue:** (e.g., \"Missing H1\", \"Duplicate Meta Title\", \"No Alt Text on Image\", \"Incorrect Canonical Tag\").\n* **Specific Error Details:**\n * **Meta Title/Description:** Original content (if any), URL of duplicate pages.\n * **H1:** Current heading structure on the page, suggested content based on page's primary topic.\n * **Image Alt Text:** Image `src` attribute, surrounding text/context to infer image content.\n * **Internal Link Density:** Current link count, suggested anchor text improvements.\n * **Canonical Tags:** Current tag (if present), identified correct canonical URL.\n * **Open Graph Tags:** Missing properties, suggested values based on page content.\n * **Core Web Vitals (LCP/CLS/FID):** Specific element causing poor performance, performance metrics.\n * **Structured Data:** Missing schema type, properties, existing invalid JSON-LD.\n * **Mobile Viewport:** Missing viewport meta tag.\n* **Original HTML Snippet:** The relevant section of the page's HTML where the issue resides, providing crucial contextual information for accurate fix generation.\n\n#### 3.2. Gemini's Analytical & Generative Capabilities\n\nUpon receiving the input, Gemini performs the following:\n\n1. **Contextual Understanding:** Analyzes the provided HTML and error details to fully grasp the nature and scope of the problem.\n2. **SEO Best Practice Application:** Consults its extensive knowledge base of current SEO best practices, W3C standards, and Google's guidelines.\n3. **Solution Generation:** Formulates the most efficient and effective code or content change to rectify the issue. This often involves:\n * **Code Generation:** Producing exact HTML, JSON-LD, or CSS modifications.\n * **Content Suggestions:** Recommending improved text for titles, descriptions, or alt attributes.\n * **Structural Adjustments:** Advising on hierarchical changes (e.g., converting a `div` to an `h1`).\n4. **Format Adherence:** Ensures the generated fix is syntactically correct and ready for direct implementation.\n\n#### 3.3. Output Format of Generated Fixes\n\nEach generated fix is structured to be clear, concise, and directly actionable, typically including:\n\n* **`page_url`**: The URL where the fix should be applied.\n* **`issue_type`**: The category of the SEO problem.\n* **`description`**: A human-readable explanation of the issue and the proposed fix.\n* **`original_element_snippet`**: The problematic HTML snippet identified by the crawler.\n* **`suggested_fix_snippet`**: The exact HTML/JSON-LD/CSS code to replace or add.\n* **`confidence_score`**: An internal score indicating Gemini's confidence in the accuracy and effectiveness of the generated fix.\n\n### 4. Examples of Gemini-Generated Fixes\n\nHere are concrete examples of the types of fixes Gemini generates for common SEO issues:\n\n#### 4.1. Meta Title/Description Uniqueness\n\n* **Issue:** Duplicate Meta Title across multiple pages.\n* **Original HTML (Page A):**\n ```html\n Our Products\n ```\n* **Context:** Page A is about \"Premium Widgets,\" Page B is about \"Advanced Gadgets.\"\n* **Gemini Fix (for Page A):**\n * **Description:** \"Meta Title 'Our Products' is duplicated. Recommended unique title for 'Premium Widgets' page.\"\n * **Suggested Fix Snippet:**\n ```html\n Premium Widgets - High-Quality Solutions | YourBrand\n ```\n\n#### 4.2. Missing H1 Tag\n\n* **Issue:** Page lacks a primary H1 heading.\n* **Original HTML:**\n ```html\n \n

Welcome to our latest blog post on SEO best practices.

\n

Introduction

\n \n ```\n* **Context:** The page content clearly indicates the primary topic is \"SEO Best Practices.\"\n* **Gemini Fix:**\n * **Description:** \"No H1 tag found. Added an H1 based on the primary content of the page.\"\n * **Suggested Fix Snippet:**\n ```html\n \n

SEO Best Practices for 2024

\n

Welcome to our latest blog post on SEO best practices.

\n

Introduction

\n \n ```\n\n#### 4.3. Missing Image Alt Text\n\n* **Issue:** An image is missing its `alt` attribute, impacting accessibility and SEO.\n* **Original HTML:**\n ```html\n \n ```\n* **Context:** The image is within a product detail page for \"XYZ Widget,\" near the product description.\n* **Gemini Fix:**\n * **Description:** \"Image is missing an alt attribute. Added descriptive alt text based on image filename and page context.\"\n * **Suggested Fix Snippet:**\n ```html\n \"XYZ\n ```\n\n#### 4.4. Incorrect Canonical Tag\n\n* **Issue:** A page has a self-referencing canonical tag that points to a non-HTTPS version of itself, or to an incorrect URL.\n* **Original HTML:**\n ```html\n \n ```\n* **Context:** The actual page URL is `https://www.yourdomain.com/product/item-a` (HTTPS).\n* **Gemini Fix:**\n * **Description:** \"Canonical tag points to an HTTP version of the page. Updated to HTTPS for consistency and SEO.\"\n * **Suggested Fix Snippet:**\n ```html\n \n ```\n\n#### 4.5. Missing Open Graph Tags\n\n* **Issue:** A page lacks essential Open Graph tags for social media sharing.\n* **Original HTML:**\n ```html\n \n My Blog Post\n \n \n ```\n* **Context:** The page is a blog post titled \"Understanding AI,\" with a primary image `/images/ai-blog.jpg`.\n* **Gemini Fix:**\n * **Description:** \"Missing Open Graph tags for social sharing. Generated `og:title`, `og:description`, `og:image`, and `og:url`.\"\n * **Suggested Fix Snippet:**\n ```html\n \n My Blog Post\n \n \n \n \n \n \n \n \n ```\n\n#### 4.6. Structured Data Issues (e.g., Missing `Article` Schema)\n\n* **Issue:** Blog post page is missing `Article` schema.\n* **Original HTML:**\n ```html\n \n
\n

My Latest Blog Post

\n

By John Doe, October 26, 2023

\n \n
\n \n ```\n* **Context:** The page is a blog post, and Gemini can extract author, publication date, and headline from the page content.\n* **Gemini Fix:**\n * **Description:** \"Added JSON-LD `Article` schema markup to enhance search engine understanding of the blog post content.\"\n * **Suggested Fix Snippet (to be placed in `` or ``):**\n ```html\n \n ```\n *(Note: Placeholders for `image` and `description` would be intelligently inferred by Gemini from page content if available.)*\n\n### 5. Batch Processing Efficiency\n\nA key feature of this step is the **batch generation** capability. Gemini processes all identified issues concurrently, not one by one. This ensures that even for large websites with thousands of pages and hundreds of unique SEO issues, the fix generation process is incredibly fast and scalable, delivering a comprehensive set of solutions in a fraction of the time it would take manually.\n\n### 6. Integration and Reporting\n\nAll generated fixes are meticulously stored within your MongoDB `SiteAuditReport` document. This report will now contain a clear `before` (original issue) and `after` (Gemini's suggested fix) diff for every identified problem, providing a complete audit trail and actionable insights.\n\n### 7. Next Steps for You (The Customer)\n\nThe generated fixes are now ready for your review and implementation.\n\n* **Review the `SiteAuditReport`:** You will receive access to the full report detailing all identified issues and Gemini's proposed solutions.\n* **Prioritize and Implement:** Review the generated code snippets and instructions. You or your development team can then directly apply these changes to your website's codebase.\n* **Schedule a Re-audit:** After implementing the fixes, we recommend scheduling an on-demand re-audit (or waiting for the next Sunday 2 AM automated run) to verify that the issues have been successfully resolved and to monitor for any new optimizations or regressions.\n\n### 8. Summary\n\nStep 3, `gemini → batch_generate`, is where your SEO audit findings are transformed into tangible, ready-to-use solutions. By leveraging Gemini's advanced AI, we ensure that every identified issue receives an intelligent, context-aware, and actionable fix, dramatically streamlining your SEO improvement efforts. You now have a clear roadmap and the exact code necessary to enhance your site's search engine performance.\n\n## Step 4 of 5: `hive_db → upsert` - Storing Site Audit Report\n\nThis step focuses on securely and efficiently persisting the comprehensive SEO audit results, including any generated fixes and comparative analyses, into your dedicated MongoDB database within PantheraHive (`hive_db`). This ensures all valuable data from the audit is stored, accessible, and ready for reporting and further action.\n\n---\n\n### 1. Overview and Purpose of Upsert\n\nFollowing the headless crawling, the 12-point SEO checklist audit, Core Web Vitals analysis, and the generation of specific fixes by Gemini, all collected data is now consolidated. This `upsert` operation is crucial for:\n\n* **Data Persistence:** Storing the complete `SiteAuditReport` for your website.\n* **Idempotency:** Preventing duplicate reports for the same audit run while allowing for updates if a partial report was saved earlier or if the process needs to restart.\n* **Historical Tracking:** Facilitating the \"before/after diff\" mechanism by either inserting a new report or updating an existing one, and crucially, referencing previous audit data. This allows you to track progress over time.\n* **Accessibility:** Making the audit results readily available for your dashboard, detailed reports, and notifications.\n\n---\n\n### 2. `SiteAuditReport` Document Structure\n\nThe audit results are meticulously structured into a `SiteAuditReport` document, designed for clarity, comprehensiveness, and easy querying. Each document represents a single audit run for a specific site.\n\n**Key Fields and Their Contents:**\n\n* **`_id` (ObjectId):** Unique identifier for the audit report in MongoDB.\n* **`auditId` (String):** A unique, human-readable identifier for this specific audit run (e.g., `example_com_20231027_0200`).\n* **`siteUrl` (String):** The root URL of the website that was audited (e.g., `https://www.example.com`).\n* **`auditDate` (Date):** Timestamp when the audit was completed.\n* **`status` (String):** Current status of the audit (e.g., `completed`, `partial`, `failed`, `pending_fixes_review`).\n* **`totalPagesAudited` (Number):** Total number of unique pages successfully crawled and audited.\n* **`issuesFoundCount` (Number):** Total number of SEO issues identified across the entire site.\n* **`fixesGeneratedCount` (Number):** Total number of fixes generated by Gemini.\n* **`overallScore` (Number):** A calculated score (e.g., 0-100) reflecting the overall SEO health of the site based on the audit findings.\n* **`lastModified` (Date):** Timestamp of the last update to this document.\n* **`pages` (Array of Objects):** An array where each object represents a single audited page and its specific findings.\n * **`pageUrl` (String):** The URL of the audited page.\n * **`statusCode` (Number):** The HTTP status code received for the page (e.g., 200, 404).\n * **`pageTitle` (String):** The title of the page.\n * **`issues` (Array of Objects):** A detailed list of issues found on this specific page.\n * **`type` (String):** Type of SEO issue (e.g., `metaTitleLength`, `missingH1`, `imageAltMissing`, `lcpPoor`).\n * **`description` (String):** A human-readable description of the issue.\n * **`severity` (String):** The impact level (e.g., `critical`, `major`, `minor`, `info`).\n * **`currentValue` (Mixed):** The problematic value or element identified (e.g., the too-long meta title, the URL of an image missing alt text).\n * **`fixGenerated` (Boolean):** `true` if Gemini generated a fix for this issue.\n * **`geminiFix` (Object - if `fixGenerated` is `true`):**\n * **`prompt` (String):** The exact prompt sent to Gemini.\n * **`suggestedFix` (String):** Gemini's generated code or textual fix.\n * **`confidenceScore` (Number):** Gemini's confidence level in the suggestion (if available).\n * **`status` (String):** Current status of the suggested fix (e.g., `pending_review`, `applied`, `rejected`).\n * **Detailed Metrics for each 12-point Checklist Item (nested within `pages` or summarized):**\n * **`metaTitle`:** `{ value: \"...\", isUnique: true/false, lengthValid: true/false, issueDetails: [...] }`\n * **`metaDescription`:** `{ value: \"...\", isUnique: true/false, lengthValid: true/false, issueDetails: [...] }`\n * **`h1Presence`:** `{ present: true/false, count: 1, issueDetails: [...] }`\n * **`imageAltCoverage`:** `{ totalImages: 10, imagesMissingAlt: 2, issueDetails: [...] }`\n * **`internalLinkDensity`:** `{ totalLinks: 25, internalLinks: 20, externalLinks: 5, densityPercentage: 80, issueDetails: [...] }`\n * **`canonicalTag`:** `{ present: true/false, value: \"...\", isSelfReferencing: true/false, issueDetails: [...] }`\n * **`openGraphTags`:** `{ present: true/false, title: \"...\", description: \"...\", image: \"...\", issueDetails: [...] }`\n * **`coreWebVitals`:** `{ lcpScore: \"good/needs_improvement/poor\", clsScore: \"good/needs_improvement/poor\", fidScore: \"good/needs_improvement/poor\", issueDetails: [...] }`\n * **`structuredData`:** `{ present: true/false, schemaTypes: [\"Product\", \"BreadcrumbList\"], isValid: true/false, issueDetails: [...] }`\n * **`mobileViewport`:** `{ present: true/false, isResponsive: true/false, issueDetails: [...] }`\n* **`overallIssuesSummary` (Array of Objects):** A high-level, site-wide summary of all issues, categorized by type and severity.\n* **`diffReport` (Object):** Crucial for tracking changes between audit runs.\n * **`previousAuditId` (String):** The `auditId` of the immediately preceding successful audit for comparison.\n * **`diffDetails` (Object):**\n * **`newIssues` (Array of Objects):** Issues identified in the current audit that were *not* present in the `previousAuditId` report.\n * **`resolvedIssues` (Array of Objects):** Issues present in the `previousAuditId` report that are *no longer* found in the current audit.\n * **`changedMetrics` (Array of Objects):** Significant changes in key metrics (e.g., Core Web Vitals score improvement/degradation, change in H1 count on a specific page).\n\n---\n\n### 3. Upsert Mechanism and Logic\n\nThe `upsert` operation intelligently handles both initial audit reports and subsequent scheduled or on-demand runs:\n\n1. **Unique Identifier:** Each audit run is uniquely identified by its `auditId`.\n2. **Previous Audit Retrieval:** Before saving the current audit, the system queries `hive_db` to retrieve the `SiteAuditReport` with the most recent `auditDate` for the given `siteUrl` that has a `status` of `completed`. This report will serve as the \"before\" state\n\n## Step 5 of 5: hive_db → conditional_update\n\nThis final step in the \"Site SEO Auditor\" workflow is critical for persisting all the valuable audit data, generated fixes, and performance comparisons into your dedicated PantheraHive database. This ensures a comprehensive historical record of your site's SEO health.\n\n### Purpose of This Step\n\nThe primary purpose of the `hive_db → conditional_update` step is to:\n1. **Persist Audit Data**: Store the complete `SiteAuditReport` document, containing all audit findings, identified issues, and Gemini's generated fixes, into your MongoDB database.\n2. **Maintain Historical Records**: Each audit run generates a new report document, allowing for robust historical tracking and trend analysis over time.\n3. **Store Before/After Diff**: Securely save the calculated \"before/after\" differential, which highlights changes and improvements (or regressions) since the previous audit, directly within the new report.\n4. **Enable Reporting & Analytics**: Make the audit data readily available for dashboard visualization, custom reports, and further analysis within the PantheraHive platform.\n\n### Data Processed\n\nAt this stage, a complete `SiteAuditReport` document has been meticulously compiled. This document is the primary input for the database update and encapsulates all information gathered and processed throughout the workflow.\n\n#### `SiteAuditReport` Document Structure (Key Fields):\n\nThe document inserted into MongoDB will typically include, but not be limited to, the following structure:\n\n* **`_id`**: MongoDB's unique document identifier (automatically generated).\n* **`auditId`**: A unique identifier for this specific audit run (e.g., a UUID).\n* **`siteUrl`**: The URL of the website that was audited (e.g., `https://www.yourwebsite.com`).\n* **`timestamp`**: The exact date and time when this audit was completed (ISO format).\n* **`status`**: The overall status of the audit (ee.g., `completed`, `failed`, `partial`).\n* **`pagesAudited`**: The total number of pages successfully crawled and audited.\n* **`overallSummary`**:\n * `totalPagesWithIssues`: Count of unique pages with at least one SEO issue.\n * `totalIssuesFound`: Aggregate count of all identified SEO issues across the site.\n * `totalFixesGenerated`: Count of issues for which Gemini successfully generated a fix.\n * `seoHealthScore`: An aggregated score representing the site's overall SEO health (e.g., 0-100).\n* **`auditResults`**: An array of detailed audit findings for *each individual page* crawled. Each element in this array will contain:\n * `pageUrl`: The URL of the specific page.\n * `pageTitle`: The page's meta title.\n * `issuesFound`: An array of specific issues identified on this page (e.g., `['missing_h1', 'duplicate_meta_description']`).\n * `seoChecks`: An object detailing the results for each of the 12 SEO points:\n * `metaTitle`: `{ value: \"...\", status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `metaDescription`: `{ value: \"...\", status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `h1Presence`: `{ present: true/false, status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `imageAltCoverage`: `{ percentage: 85, issues: [...], status: \"ok/issue\", fix: \"...\" }`\n * `internalLinkDensity`: `{ count: 25, status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `canonicalTag`: `{ value: \"...\", status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `openGraphTags`: `{ present: true/false, issues: [...], status: \"ok/issue\", fix: \"...\" }`\n * `coreWebVitals`: `{ LCP: \"...\", CLS: \"...\", FID: \"...\", status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `structuredDataPresence`: `{ present: true/false, types: [...], status: \"ok/issue\", fix: \"...\" }`\n * `mobileViewport`: `{ present: true/false, status: \"ok/issue\", details: \"...\", fix: \"...\" }`\n * `geminiFixes`: An array of specific, actionable fixes generated by Gemini for this page's issues.\n* **`beforeAfterDiff`**: This crucial object details the changes compared to the *immediately preceding* audit report for the same `siteUrl`.\n * `previousAuditId`: The `auditId` of the report used for comparison.\n * `overallScoreChange`: Delta in the `seoHealthScore` (e.g., `+5` points).\n * `newIssuesFoundCount`: Number of new issues identified in this audit that weren't present before.\n * `issuesResolvedCount`: Number of issues from the previous audit that are now resolved.\n * `pageLevelChanges`: An array detailing changes for specific pages (e.g., new issues on page X, resolved issues on page Y).\n\n### Database Interaction Details\n\n* **Target Database**: MongoDB\n* **Target Collection**: `SiteAuditReports` (or a similar, designated collection for SEO audit data).\n* **Update Mechanism (Insert Operation)**:\n * Given that each audit run is a distinct event and we want to maintain a historical log, the `conditional_update` operation in this context primarily functions as an **insert** operation for a new `SiteAuditReport` document.\n * The \"conditional\" aspect ensures that the operation is handled robustly, confirming that the data is valid and correctly structured before insertion. It might also involve checks to prevent accidental duplicate insertions for the exact same `auditId` (though `auditId` is unique).\n * The new `SiteAuditReport` document, complete with all audit findings, Gemini's fixes, and the `beforeAfterDiff`, is written as a new record.\n* **Data Integrity & Indexing**:\n * The `siteUrl` and `timestamp` fields are typically indexed to facilitate quick querying for historical reports of a specific site.\n * The `auditId` is also indexed for direct access to individual reports.\n * Schema validation may be applied at the database level to ensure all inserted documents conform to the expected `SiteAuditReport` structure, maintaining data consistency.\n\n### Outcome and Deliverable\n\nUpon successful completion of this step, the following will be delivered:\n\n* **Persistent `SiteAuditReport`**: A complete, timestamped `SiteAuditReport` document will be securely stored in your PantheraHive MongoDB instance.\n* **Historical Data Point**: This new report adds another valuable data point to your site's SEO history, enabling long-term trend analysis.\n* **Data Availability**: The audit results, including the before/after diff and Gemini's fixes, will be immediately available for viewing within your PantheraHive dashboard and via API access.\n\n### Customer Benefits\n\n* **Comprehensive Record Keeping**: Never lose track of your site's SEO performance. Every audit is meticulously recorded.\n* **Track Progress & ROI**: Clearly see the impact of your SEO efforts with the \"before/after\" diff, demonstrating which issues have been resolved and where new ones might have emerged.\n* **Actionable Insights**: Gemini's fixes are stored alongside the issues, providing a direct link between problem and solution, facilitating faster implementation.\n* **Simplified Reporting**: All data is structured for easy consumption by dashboards and custom reports, giving you a clear overview of your site's SEO health at a glance.\n* **Compliance & Audit Trails**: Maintain a clear audit trail of your SEO optimizations, which can be crucial for internal compliance or external reporting.\n\n### Next Steps & Data Access\n\nThe audit workflow is now complete!\n\n* **View Your Report**: You can now navigate to your PantheraHive dashboard under the \"Site SEO Auditor\" section to view the latest audit report.\n* **Review Fixes**: Examine the \"Issues & Fixes\" section to prioritize and implement Gemini's recommended changes.\n* **Historical Analysis**: Utilize the platform's historical view to compare this report with previous audits and observe trends in your SEO health.\n* **Scheduled Audits**: The system will automatically run the next audit on Sunday at 2 AM, providing continuous monitoring. You can also trigger an on-demand audit at any time.";function phTab(btn,name){document.querySelectorAll(".ph-panel").forEach(function(el){el.classList.remove("active");});document.querySelectorAll(".ph-tab").forEach(function(el){el.classList.remove("active");el.classList.add("inactive");});var p=document.getElementById("panel-"+name);if(p)p.classList.add("active");btn.classList.remove("inactive");btn.classList.add("active");if(name==="preview"){var fr=document.getElementById("ph-preview-frame");if(fr&&!fr.dataset.loaded){if(_phIsHtml){fr.srcdoc=_phCode;}else{var vc=document.getElementById("panel-content");fr.srcdoc=vc?""+vc.innerHTML+"":"

No content

";}fr.dataset.loaded="1";}}}function phCopyCode(){navigator.clipboard.writeText(_phCode).then(function(){var b=document.getElementById("tab-code");if(b){var o=b.innerHTML;b.innerHTML=' Copied!';setTimeout(function(){b.innerHTML=o;},2000);}});}function phCopyAll(){navigator.clipboard.writeText(_phAll).then(function(){alert("Content copied to clipboard!");});}function phDownload(){var content=_phCode||_phAll;if(!content){alert("No content to download.");return;}var fn=_phFname;if(!_phCode&&fn.endsWith(".txt"))fn=fn.replace(/\.txt$/,".md");var a=document.createElement("a");a.href="data:text/plain;charset=utf-8,"+encodeURIComponent(content);a.download=fn;a.click();}function phDownloadZip(){ var lbl=document.getElementById("ph-zip-lbl"); if(lbl)lbl.textContent="Preparing\u2026"; /* ===== HELPERS ===== */ function cc(s){ return s.replace(/[_\-\s]+([a-z])/g,function(m,c){return c.toUpperCase();}) .replace(/^[a-z]/,function(m){return m.toUpperCase();}); } function pkgName(app){ return app.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"my_app"; } function slugTitle(app){ return app.replace(/_/g," "); } /* Generic code block extractor. Finds marker comments like: // lib/main.dart or # lib/main.dart or ## lib/main.dart and collects lines until the next marker. Also strips markdown fences (\`\`\`lang ... \`\`\`) from each block. */ function extractFiles(txt, pathRe){ var files={}, cur=null, buf=[]; function flush(){ if(cur&&buf.length){ files[cur]=buf.join("\n").trim(); } } txt.split("\n").forEach(function(line){ var m=line.trim().match(pathRe); if(m){ flush(); cur=m[1]; buf=[]; return; } if(cur) buf.push(line); }); flush(); // Strip \`\`\`...\`\`\` fences from each file Object.keys(files).forEach(function(k){ files[k]=files[k].replace(/^\`\`\`[a-z]*\n?/,"").replace(/\n?\`\`\`$/,"").trim(); }); return files; } /* General path extractor that covers most languages */ function extractCode(txt){ var re=/^(?:\/\/|#|##)\s*((?:lib|src|test|tests|Sources?|app|components?|screens?|views?|hooks?|routes?|store|services?|models?|pages?)\/[\w\/\-\.]+\.\w+|pubspec\.yaml|Package\.swift|angular\.json|babel\.config\.(?:js|ts)|vite\.config\.(?:js|ts)|tsconfig\.(?:json|app\.json)|app\.json|App\.(?:tsx|jsx|vue|kt|swift)|MainActivity(?:\.kt)?|ContentView\.swift)/i; return extractFiles(txt, re); } /* Detect language from combined code+panel text */ function detectLang(code, panel){ var t=(code+" "+panel).toLowerCase(); if(t.indexOf("import 'package:flutter")>=0||t.indexOf('import "package:flutter')>=0) return "flutter"; if(t.indexOf("statelesswidget")>=0||t.indexOf("statefulwidget")>=0) return "flutter"; if((t.indexOf(".dart")>=0)&&(t.indexOf("pubspec")>=0||t.indexOf("flutter:")>=0)) return "flutter"; if(t.indexOf("react-native")>=0||t.indexOf("react_native")>=0) return "react-native"; if(t.indexOf("stylesheet.create")>=0||t.indexOf("view, text, touchableopacity")>=0) return "react-native"; if(t.indexOf("expo(")>=0||t.indexOf("\"expo\":")>=0||t.indexOf("from 'expo")>=0) return "react-native"; if(t.indexOf("import swiftui")>=0||t.indexOf("import uikit")>=0) return "swift"; if(t.indexOf(".swift")>=0&&(t.indexOf("func body")>=0||t.indexOf("@main")>=0||t.indexOf("var body: some view")>=0)) return "swift"; if(t.indexOf("import android.")>=0||t.indexOf("package com.example")>=0) return "kotlin"; if(t.indexOf("@composable")>=0||t.indexOf("fun mainactivity")>=0||(t.indexOf(".kt")>=0&&t.indexOf("androidx")>=0)) return "kotlin"; if(t.indexOf("@ngmodule")>=0||t.indexOf("@component")>=0) return "angular"; if(t.indexOf("angular.json")>=0||t.indexOf("from '@angular")>=0) return "angular"; if(t.indexOf(".vue")>=0||t.indexOf("