🌟 Nova: Add autumn graph for Mermaid.js route visualization#1808
🌟 Nova: Add autumn graph for Mermaid.js route visualization#1808madmax983 wants to merge 1 commit into
autumn graph for Mermaid.js route visualization#1808Conversation
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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
- 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 Report❌ Patch coverage is ❌ 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@@ 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:
|
💡 The Spark: Users need a visual way to understand the routing and middleware architecture of their Autumn applications.
⚠️ Risk: Low. Purely additive CLI tool command that safely reuses existing route dumping logic.
🚀 The Feature: Introduced the
autumn graphsubcommand 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.
PR created automatically by Jules for task 5623932763910706854 started by @madmax983