Conversation
Greptile SummaryThis PR successfully refactors three monolithic files into well-organized modules without changing behavior: Key Improvements:
Import Updates: All affected files updated to use new module paths ( This refactoring significantly improves maintainability and code navigation without introducing functional changes. Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
subgraph Before["Before: Monolithic Structure"]
A1["main.rs<br/>(3,940 lines)<br/>• App setup<br/>• CLI parsing<br/>• Server startup<br/>• UI routes<br/>• All logic"]
A2["routes/api.rs<br/>(15,881 lines)<br/>• Chat handlers<br/>• Embeddings<br/>• Images<br/>• Audio<br/>• Files<br/>• Vector stores<br/>• Models"]
A3["middleware/<br/>• Combined middleware<br/>• File search (misplaced)"]
end
subgraph After["After: Modular Structure"]
B1["main.rs<br/>(49 lines)<br/>Entry point only"]
B2["app.rs<br/>(2,014 lines)<br/>App setup & routing"]
B3["cli/<br/>• mod.rs (289 lines)<br/>• server.rs<br/>• bootstrap.rs<br/>• migrate.rs<br/>• worker.rs<br/>• features.rs<br/>• init.rs<br/>• openapi.rs"]
B4["init.rs<br/>(385 lines)<br/>Init helpers"]
B5["routes/api/<br/>• mod.rs (shared)<br/>• chat.rs (2,323 lines)<br/>• embeddings.rs (312)<br/>• images.rs (874)<br/>• audio.rs (849)<br/>• files.rs (783)<br/>• vector_stores.rs (2,151)<br/>• models.rs (591)"]
B6["services/<br/>• file_search_tool.rs<br/>(moved from middleware)"]
B7["middleware/<br/>• Combined middleware<br/>• Internal helpers<br/>• Better docs"]
B1 --> B2
B1 --> B3
B1 --> B4
end
A1 -.->|"Extracted to"| B2
A1 -.->|"Extracted to"| B3
A1 -.->|"Extracted to"| B4
A2 -.->|"Split into"| B5
A3 -.->|"Reorganized"| B6
A3 -.->|"Cleaned up"| B7
style Before fill:#ffebee
style After fill:#e8f5e9
style A1 fill:#ffcdd2
style A2 fill:#ffcdd2
style B1 fill:#c8e6c9
style B5 fill:#c8e6c9
Last reviewed commit: 00d0d88 |
There was a problem hiding this comment.
Pull request overview
This PR refactors the gateway’s Rust code and SQL migrations to improve organization and maintainability, primarily by extracting functionality into more focused modules without intended behavioral changes.
Changes:
- Moved file-search tool interception types/helpers from
middlewareintoservicesand updated imports across routes/providers. - Split API handlers into dedicated route modules (e.g.,
routes/api/{models,embeddings,images,audio,files}.rs). - Added/expanded CLI subcommands and initialization helpers (
serve,worker,migrate,bootstrap,openapi,schema,features) and standardized migration section comments/ordering.
Reviewed changes
Copilot reviewed 30 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/services/mod.rs | Exposes new file_search_tool module and re-exports tool-related types/functions. |
| src/services/file_search_tool.rs | Updates module docs to reflect service/tool interception responsibilities. |
| src/services/file_search.rs | Updates imports to use services::FileSearchAuthContext after refactor. |
| src/routes/execution.rs | Switches preprocess_file_search_tools import from middleware to services. |
| src/routes/api/models.rs | New models endpoint module with provider aggregation and enrichment. |
| src/routes/api/embeddings.rs | New embeddings endpoint module (currently has a compile-scoping issue for json!). |
| src/routes/api/images.rs | New images endpoints module. |
| src/routes/api/audio.rs | New audio endpoints module. |
| src/routes/api/files.rs | New files endpoints module. |
| src/providers/{vertex,bedrock,anthropic}/convert.rs | Updates file-search tool argument imports to services. |
| src/middleware/mod.rs | Adds module-level docs and narrows exports; keeps internal helpers private. |
| src/middleware/combined.rs | Adjusts internal imports after middleware module re-organization. |
| src/init.rs | Adds shared provider instantiation + worker embedding/vector-store init helpers. |
| src/guardrails/audit.rs | Updates reference to new API module path. |
| src/config/features.rs | Small refactor in queue config validation (match guards). |
| src/cli/* | Adds modular CLI implementation (server/worker/migrate/bootstrap/openapi/schema/features). |
| migrations_sqlx/sqlite/20250101000000_initial.sql | Re-organizes comments/sections and column ordering for consistency. |
| migrations_sqlx/postgres/20250101000000_initial.sql | Re-organizes comments/sections and column ordering for consistency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| request_body( | ||
| content = api_types::CreateEmbeddingPayload, | ||
| examples( | ||
| ("Single text" = ( | ||
| summary = "Embed a single text string", | ||
| value = json!({ | ||
| "model": "openai/text-embedding-3-small", | ||
| "input": "Hello world" | ||
| }) | ||
| )), | ||
| ("Multiple texts" = ( | ||
| summary = "Embed multiple texts in one request", | ||
| value = json!({ | ||
| "model": "openai/text-embedding-3-large", |
There was a problem hiding this comment.
json! is used in the utoipa::path examples here, but this module doesn’t import the macro (use serde_json::json;) or qualify it (serde_json::json!). As written, this won’t compile because json! won’t be in scope for this module.
| fn create_default_config() -> Result<(PathBuf, bool), String> { | ||
| let config_dir = default_config_dir().ok_or("Could not determine config directory")?; | ||
| let config_path = config_dir.join("hadrian.toml"); | ||
| let data_dir = default_data_dir().ok_or("Could not determine data directory")?; | ||
|
|
There was a problem hiding this comment.
create_default_config() requires default_config_dir() / default_data_dir() to return Some(...), but in non-wizard builds those helpers return None, causing an error instead of creating a default config. This makes fresh installs unusable under profiles like --no-default-features --features tiny unless a config path is always provided.
Several key files have grown too large and lack consistent organization. This refactoring improves maintainability without changing behavior:
src/main.rs(3,940 lines) — monolithic entry point mixing app setup, CLI, and service initsrc/routes/api.rs(15,881 lines) — all API handlers in one filesrc/middleware/— mixes true middleware with utilities and servicesmigrations_sqlx/— inconsistent comment styles and column ordering