forge icon indicating copy to clipboard operation
forge copied to clipboard

refactor: modularize router.rs into domain-specific route modules

Open jmanhype opened this issue 3 weeks ago • 6 comments

Splits the 62KB monolithic router.rs file into modular domain-specific route files for better maintainability and faster compilation.

Changes

  • Create routes/ directory with mod.rs
    • Extract routes into domain modules: tasks, attempts, config, projects, omni, agents, frontend, state
    • Keep router.rs as thin composition layer that imports and composes modules
    • Update lib.rs to expose new routes module

Benefits

  • Faster compilation (changes to one domain don't recompile others)
    • Better code organization
    • Easier onboarding for new contributors
    • Clear ownership of route handlers

Testing

  • Verified build compiles successfully with cargo build -p forge-app

jmanhype avatar Nov 28 '25 13:11 jmanhype

Summary of Changes

Hello @jmanhype, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant architectural refactoring by modularizing the application's routing layer. The primary goal is to break down a large, single routing file into smaller, more manageable, and domain-focused modules. This change is expected to enhance code clarity, reduce compilation times for isolated changes, and streamline the onboarding process for new contributors by providing clearer ownership and separation of concerns within the API endpoints.

Highlights

  • Modularization of Router: The monolithic router.rs file, previously 62KB, has been refactored into several smaller, domain-specific modules located under a new routes/ directory. This significantly improves code organization and maintainability.
  • New Route Modules: Dedicated modules have been created for tasks, attempts, config, projects, omni, agents, frontend, and state. Each module now encapsulates its specific routing logic and handlers.
  • Thin Router Composition: The original router.rs now acts as a thin composition layer, importing and merging routers from the new domain-specific modules, rather than containing all the handler implementations directly.
  • Dependency Updates: The Cargo.lock file has been updated, bumping the versions of forge-app, forge-config, and forge-omni from 0.6.1 to 0.6.2.
  • Frontend Build Helper: A new build.rs file has been added to forge-app. This script ensures that a dummy frontend/dist directory and index.html are created if they don't exist, preventing compilation issues when the frontend is not yet built.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot] avatar Nov 28 '25 13:11 gemini-code-assist[bot]

Summary of Changes

Hello @jmanhype, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the architecture of the application's routing layer by breaking down a large, single router file into smaller, more manageable, and domain-focused modules. This refactoring aims to enhance code organization, reduce compilation times for incremental changes, and make the codebase easier for new contributors to understand and navigate. The core functionality of the API remains unchanged, but its internal structure is now more modular and scalable.

Highlights

  • Router Modularization: The monolithic router.rs file (previously 62KB) has been refactored into a new routes/ directory, containing domain-specific modules for better organization and maintainability. router.rs now acts as a thin composition layer.
  • New Route Modules: New modules have been created under forge-app/src/routes/ for agents, attempts, config, frontend, omni, projects, state, and tasks, each encapsulating related API endpoints and logic.
  • Frontend Build Script: A new build.rs script has been added to forge-app to automatically create a dummy frontend/dist directory and index.html if they don't exist. This ensures the application can compile even if the frontend assets haven't been built yet.
  • Version Bumps: The Cargo.lock file reflects minor version bumps for forge-app, forge-config, and forge-omni from 0.6.1 to 0.6.2.
  • ForgeAppState Centralization: The ForgeAppState definition and its FromRef implementations have been moved from router.rs to a dedicated forge-app/src/routes/state.rs module, centralizing state management for routes.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot] avatar Nov 28 '25 13:11 gemini-code-assist[bot]

@codex review this pr

namastex888 avatar Nov 28 '25 23:11 namastex888

Codex Review Feedback - Minor Code Smell (Non-blocking)

Finding: Semantic confusion with state types in router.rs

Location: forge-app/src/router.rs:107-135 (various .with_state() calls)

Issue: The code passes DeploymentImpl (via dep_clone) where semantically ForgeAppState is expected:

router.merge(containers::router(deployment).with_state::<ForgeAppState>(dep_clone.clone()))

Current Status:

  • ✅ Code compiles and works correctly
  • ✅ Type-safe via Axum's FromRef<ForgeAppState> for DeploymentImpl trait
  • ⚠️ Semantically confusing - appears to pass wrong type

Why it works: The FromRef trait implementation in state.rs:34-38 allows Axum to extract DeploymentImpl from ForgeAppState automatically.

Optional Improvement: Consider refactoring to make state flow more explicit (pass full ForgeAppState instead of relying on type conversion). This would make the code easier to understand for future contributors.

Verdict: Not blocking merge - this is a common Axum pattern and the refactoring is already a major improvement. Just noting for team awareness.


Note: This PR successfully modularizes a 62KB monolith into clean domain modules - excellent work! 🎉

jmanhype avatar Nov 29 '25 06:11 jmanhype

@codex do you agree that this is a code smell?

jmanhype avatar Nov 29 '25 06:11 jmanhype