Skip to content

🌟 Nova: Add autumn graph for Mermaid.js route visualization#1808

Open
madmax983 wants to merge 1 commit into
trunk-devfrom
nova-graph-feature-5623932763910706854
Open

🌟 Nova: Add autumn graph for Mermaid.js route visualization#1808
madmax983 wants to merge 1 commit into
trunk-devfrom
nova-graph-feature-5623932763910706854

Conversation

@madmax983

Copy link
Copy Markdown
Owner

💡 The Spark: Users need a visual way to understand the routing and middleware architecture of their Autumn applications.
🚀 The Feature: Introduced the autumn graph subcommand that exports routes and middleware as a Mermaid.js diagram (graph TD), leveraging the existing route introspection.
🔭 The Potential: Can be used to automatically generate visual documentation (e.g., embedded in READMEs or Notion) for the application's API architecture.
⚠️ Risk: Low. Purely additive CLI tool command that safely reuses existing route dumping logic.


PR created automatically by Jules for task 5623932763910706854 started by @madmax983

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new graph subcommand to the CLI, which compiles and runs the application binary to dump routes and generate a Mermaid.js graph of the routes and middleware. The review feedback suggests optimizing the string generation in generate_mermaid_graph by pre-allocating the string capacity and using push_str instead of writeln! to avoid formatting overhead.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread autumn-cli/src/graph.rs
Comment on lines +43 to +77
pub fn generate_mermaid_graph(routes: &[RouteInfo]) -> String {
use std::fmt::Write;
let mut out = String::new();
out.push_str("graph TD\n");
out.push_str(" Client((Client))\n");

// Simple hierarchy approach: just connect Client to Paths to Handlers.
for (i, route) in routes.iter().enumerate() {
let route_node = format!("R{i}");
let handler_node = format!("H{i}");

// Sanitize path for Mermaid
let clean_path = route.path.replace('"', "\\\"");
// Sanitize handler for Mermaid
let clean_handler = route.handler.replace('"', "\\\"");

let middleware_label = if route.middleware.is_empty() {
" ".to_owned()
} else {
format!("|{}| ", route.middleware.join(", "))
};

let _ = writeln!(
out,
" Client -- \"{}\" --> {route_node}(\"{clean_path}\")",
route.method
);
let _ = writeln!(
out,
" {route_node} -->{middleware_label}{handler_node}(\"{clean_handler}\")"
);
}

out
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve performance and avoid the overhead of dynamic formatting via the write!/writeln! macros inside a loop, we should pre-allocate the String with an estimated capacity using String::with_capacity and append to it using push_str.

pub fn generate_mermaid_graph(routes: &[RouteInfo]) -> String {
    let mut out = String::with_capacity(routes.len() * 128 + 32);
    out.push_str("graph TD\n");
    out.push_str("    Client((Client))\n");

    // Simple hierarchy approach: just connect Client to Paths to Handlers.
    for (i, route) in routes.iter().enumerate() {
        let route_node = format!("R{i}");
        let handler_node = format!("H{i}");

        // Sanitize path for Mermaid
        let clean_path = route.path.replace('"', "\\\"");
        // Sanitize handler for Mermaid
        let clean_handler = route.handler.replace('"', "\\\"");

        let middleware_label = if route.middleware.is_empty() {
            " ".to_owned()
        } else {
            format!("|{}| ", route.middleware.join(", "))
        };

        out.push_str("    Client -- \"");
        out.push_str(&route.method);
        out.push_str("\" --> ");
        out.push_str(&route_node);
        out.push_str("(\"");
        out.push_str(&clean_path);
        out.push_str("\")\n");

        out.push_str("    ");
        out.push_str(&route_node);
        out.push_str(" -->");
        out.push_str(&middleware_label);
        out.push_str(&handler_node);
        out.push_str("(\"");
        out.push_str(&clean_handler);
        out.push_str("\")\n");
    }

    out
}
References
  1. When building a string by appending in a loop, prefer pre-allocating with String::with_capacity and using push_str over the write! macro for simple appends to improve performance by avoiding formatting overhead.

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.25641% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.81%. Comparing base (14e6518) to head (cec6c90).
⚠️ Report is 1 commits behind head on trunk-dev.

❌ Your patch check has failed because the patch coverage (60.25%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##           trunk-dev    #1808      +/-   ##
=============================================
- Coverage      86.82%   86.81%   -0.02%     
=============================================
  Files            273      274       +1     
  Lines         202424   202502      +78     
=============================================
+ Hits          175761   175808      +47     
- Misses         26663    26694      +31     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant