refactor: modularize router.rs into domain-specific route modules
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
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.rsfile, previously 62KB, has been refactored into several smaller, domain-specific modules located under a newroutes/directory. This significantly improves code organization and maintainability. - New Route Modules: Dedicated modules have been created for
tasks,attempts,config,projects,omni,agents,frontend, andstate. Each module now encapsulates its specific routing logic and handlers. - Thin Router Composition: The original
router.rsnow 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.lockfile has been updated, bumping the versions offorge-app,forge-config, andforge-omnifrom0.6.1to0.6.2. - Frontend Build Helper: A new
build.rsfile has been added toforge-app. This script ensures that a dummyfrontend/distdirectory andindex.htmlare 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.
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.rsfile (previously 62KB) has been refactored into a newroutes/directory, containing domain-specific modules for better organization and maintainability.router.rsnow acts as a thin composition layer. - New Route Modules: New modules have been created under
forge-app/src/routes/foragents,attempts,config,frontend,omni,projects,state, andtasks, each encapsulating related API endpoints and logic. - Frontend Build Script: A new
build.rsscript has been added toforge-appto automatically create a dummyfrontend/distdirectory andindex.htmlif they don't exist. This ensures the application can compile even if the frontend assets haven't been built yet. - Version Bumps: The
Cargo.lockfile reflects minor version bumps forforge-app,forge-config, andforge-omnifrom0.6.1to0.6.2. - ForgeAppState Centralization: The
ForgeAppStatedefinition and itsFromRefimplementations have been moved fromrouter.rsto a dedicatedforge-app/src/routes/state.rsmodule, 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.
@codex review this pr
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 DeploymentImpltrait - ⚠️ 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! 🎉
@codex do you agree that this is a code smell?
To use Codex here, create an environment for this repo.