ai-hedge-fund's frontend layer carries the highest activity risk — 3 files to address first

Hotspots analysis of virattt/ai-hedge-fund (commit 359cce7) finds that the top structural debt is concentrated in two service files and the Ollama settings component, with cyclomatic complexity reaching 56 and nesting depth hitting 12.

Stephen Collins ·
oss python refactoring code-health

Antipatterns Detected

exit_heavy9god_function8long_function7complex_branching6deeply_nested5stale_complex5

Key Points

What is a god function and why does it matter in ai-hedge-fund?

A god function is a single function that takes on too many responsibilities — calling a large number of other functions and encoding a wide range of logic that ideally belongs in separate, focused units. In ai-hedge-fund, 8 of the top hotspot functions carry this classification, with `OllamaSettings` calling 73 distinct functions from a single component. That level of coupling means a change to any one of those 73 dependencies — or to the orchestration logic itself — can produce unexpected side effects that ripple across the entire settings and configuration surface.

How do I reduce cyclomatic complexity in Python and TypeScript frontends?

The most direct technique is extract-method (or extract-function/extract-component in React): identify groups of related branches or conditions, move them into a named function with a single clear responsibility, and replace the original logic with a call to that function. Each extracted unit reduces the path count in the original function and becomes independently testable.

Is ai-hedge-fund actively maintained?

The structural complexity in the codebase is real and significant — 150 of 1,306 functions are rated critical — but all five of the top-ranked hotspots fall in the 'debt' quadrant, meaning none of them show high recent commit activity at this snapshot (commit 359cce7). The risk here is structural rather than a sign of active churn; the complexity has accumulated and is waiting to become a problem when those files are next developed.

How do I reproduce this analysis?

Run the Hotspots CLI against the virattt/ai-hedge-fund repository at commit 359cce7 to reproduce the exact scores and rankings shown here.

What does activity-weighted risk mean?

Complexity × recent commit frequency — functions that are hard to understand AND actively changing are the highest priority for refactoring.

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

FunctionFileRiskCCNDFO
OllamaSettingsapp/frontend/src/components/settings/models/ollama.tsx20.0561273
<anonymous>app/frontend/src/services/backtest-api.ts18.8471020
<anonymous>app/frontend/src/services/api.ts18.639821
<anonymous>app/frontend/src/components/settings/models/ollama.tsx18.1281221
<anonymous>app/frontend/src/services/backtest-api.ts17.8191026

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:

PatternOccurrences
exit_heavy9
god_function8
long_function7
complex_branching6
deeply_nested5
stale_complex5

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

  • OllamaSettings in ollama.tsx has 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.ts and api.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 →

Run this on your own codebase

Hotspots runs locally in under a minute — no account, no data leaves your machine.

macOS
$ brew install Stephen-Collins-tech/tap/hotspots
Linux / cargo
$ cargo install hotspots-cli
Run in any repo
$ hotspots analyze .
★ Star on GitHub

Related Analyses