Every one of the top five hotspots in virattt/ai-hedge-fund sits in the frontend layer — concentrated across app/frontend/src/services/ and app/frontend/src/components/settings/models/ollama.tsx — and all five fall in the “debt” quadrant, meaning this is accumulated structural complexity that hasn’t been recently touched, not an active churn problem. When that next development push arrives, these functions carry a high blast radius: OllamaSettings alone scores a cyclomatic complexity of 56 with a fan-out of 73. Across 1,306 total functions, 150 are rated critical — an 11% critical rate that signals the frontend surface area deserves immediate architectural attention before the next feature cycle.
The table below ranks functions by activity-weighted risk — a score that multiplies structural complexity by recent commit frequency. A function that is both hard to understand (high cyclomatic complexity) and actively changing is a higher priority than one that is complex but untouched. CC = cyclomatic complexity (independent execution paths); ND = max nesting depth; FO = fan-out (distinct callees).
Top 5 Hotspots
| Function | File | Risk | CC | ND | FO |
|---|---|---|---|---|---|
OllamaSettings | app/frontend/src/components/settings/models/ollama.tsx | 20.0 | 56 | 12 | 73 |
<anonymous> | app/frontend/src/services/backtest-api.ts | 18.8 | 47 | 10 | 20 |
<anonymous> | app/frontend/src/services/api.ts | 18.6 | 39 | 8 | 21 |
<anonymous> | app/frontend/src/components/settings/models/ollama.tsx | 18.1 | 28 | 12 | 21 |
<anonymous> | app/frontend/src/services/backtest-api.ts | 17.8 | 19 | 10 | 26 |
Hotspot Analysis
OllamaSettings — app/frontend/src/components/settings/models/ollama.tsx
Based on its name and path, OllamaSettings is almost certainly the React component responsible for rendering and managing the configuration UI for Ollama model integrations. The metrics tell a striking story: a cyclomatic complexity of 56 means there are 56 independent execution paths through this single component — each one a required test case and a potential bug surface — while a max nesting depth of 12 means logic is buried inside at least a dozen levels of nested control structures. Most alarming is the fan-out of 73: this component calls 73 distinct functions, making it a god function with an extraordinarily wide coupling surface. It hasn’t been recently active, but its blast radius when next changed is enormous — any future work on Ollama configuration will have to navigate all of that complexity at once.
Recommendation: Before touching this component again, write characterization tests that exercise its major branches, then apply extract-component and extract-hook refactoring to pull distinct responsibilities (state management, API calls, validation logic, sub-sections of the UI) into smaller, independently testable units. The fan-out of 73 is the primary signal: identify which of those 73 callees belong in child components versus custom hooks and separate them accordingly.
<anonymous> — app/frontend/src/services/backtest-api.ts
The top-ranked anonymous function in backtest-api.ts — likely a large request handler or service orchestration closure given the file’s name and its god-function classification — carries a cyclomatic complexity of 47, a max nesting depth of 10, and a fan-out of 20. CC 47 is well into high territory, meaning nearly 50 distinct logical paths flow through a single unnamed function; the exit-heavy pattern flag reinforces that many of those paths terminate with separate return or throw statements, each of which needs its own test coverage. Like all top hotspots here, it represents accumulated structural complexity that is overdue for refactoring before the next development push on backtesting features.
Recommendation: Give this function an explicit name immediately — anonymous functions with this level of complexity are extremely difficult to trace in stack traces and profiling output. Then apply extract-method refactoring to isolate each major branching group (likely corresponding to different API response scenarios or backtest configurations) into named, separately testable functions.
<anonymous> — app/frontend/src/services/api.ts
The large anonymous function in api.ts — likely the central API service layer handling request dispatch, response parsing, and error routing for the application — scores a cyclomatic complexity of 39 and a max nesting depth of 8, the threshold at which the deeply-nested pattern flag fires. Fan-out of 21 combined with the god-function classification means this single closure coordinates a wide surface of downstream calls. At ND 8, even an experienced engineer reading this code cold will need to hold a significant amount of context in working memory to trace any single path. It is structural debt waiting to be triggered — the next time API handling needs to change, all of this complexity becomes a live liability.
Recommendation: Map the fan-out of 21 callees to identify which ones represent distinct concerns (authentication, serialization, error normalization, request construction) and extract each concern into a dedicated module or utility function. Add integration-level characterization tests against the current behavior before making any structural changes.
Patterns Found
Antipatterns detected across the top functions in this snapshot:
| Pattern | Occurrences |
|---|---|
exit_heavy | 9 |
god_function | 8 |
long_function | 7 |
complex_branching | 6 |
deeply_nested | 5 |
stale_complex | 5 |
These labels belong to two tiers — Tier 1 (structural): complex_branching, deeply_nested, exit_heavy, long_function, god_function. Tier 2 (relational/temporal): hub_function, cyclic_hub, middle_man, neighbor_risk, stale_complex, churn_magnet, shotgun_target, volatile_god.
Key Takeaways
OllamaSettingsinollama.tsxhas a fan-out of 73 and cyclomatic complexity of 56 — map its 73 callees before touching it, or any change risks unexpected regressions across the entire Ollama configuration surface.- All five critical hotspots are in the ‘debt’ quadrant, meaning the structural risk is currently dormant — prioritize refactoring them before the next feature push to the frontend rather than treating them as an emergency today.
- The anonymous function pattern across
backtest-api.tsandapi.ts(CC 47 and CC 39 respectively) makes debugging and test attribution harder than it needs to be — naming these functions is the cheapest first step before deeper refactoring.
Reproduce This Analysis
git clone https://github.com/virattt/ai-hedge-fund
cd ai-hedge-fund
git checkout 359cce737377b512d95a4c789d63cfc443652b02
hotspots analyze . --mode snapshot --explain-patterns --force
To run the same analysis on your own codebase, run hotspots analyze . --mode snapshot in any local git repo — no configuration required.
Hotspots highlights structural and activity risk — not “bad code.” Findings are a prioritization aid, not a bug predictor. Editorial policy →