Move service-dependent helper wrappers from app.utils to app.helpers and update config router activation/rollback to use explicit AppState dependency.
4.8 KiB
BanGUI — Task List
This document breaks the entire BanGUI project into development stages, ordered so that each stage builds on the previous one. Every task is described in prose with enough detail for a developer to begin work. References point to the relevant documentation.
Reference: Docs/Refactoring.md for full analysis of each issue.
Open Issues
Backend Architecture Review Findings
-
Status: done —
backend/app/routers/config.pynow uses explicit dependency injection for fail2ban settings and no longer readsrequest.app.state.settingsdirectly. -
Status: done —
backend/app/routers/config.pynow uses an explicitAppStatedependency for pending recovery and activation state instead of writingrequest.app.statedirectly. -
Status: done —
backend/app/routers/*often reads config directly fromrequest.app.state.settingsinstead of using dependency injection. This bypasses the dependency layer and creates hidden coupling between routers and application state.- Fix: replace direct
request.app.state.settingsaccess withSettingsDepor other explicit dependencies such asServerStatusDepandPendingRecoveryDepin router function signatures. - Expected outcome: routers become easier to unit test, composition is more explicit, and shared state access is only available through documented FastAPI dependencies.
- Fix: replace direct
-
Status: done — Several utility modules under
backend/app/utils/import service layer code (app.services.*). Utilities should remain low-level helpers and not depend on higher-level service logic.- Fix: move service-dependent helpers into
app/services/or extract shared logic into a newapp/helpers/layer, keepingapp/utils/purely independent. - Expected outcome: lower coupling between utility and service layers, cleaner dependency direction, and better maintainability.
- Fix: move service-dependent helpers into
-
Status: done — background task modules in
backend/app/tasks/no longer rely on the deadapp.state.dbfast-path and now open/close dedicated task-local DB connections usingapp.state.settings.database_path.- Fix: remove the unused
app.state.dbbranch and always open/close a dedicated task-local connection, or intentionally add a shared DB connection toapp.stateand manage its lifecycle. - Expected outcome: background jobs have predictable DB lifecycle, avoid hidden bugs from stale connection assumptions, and task code is simpler.
- Fix: remove the unused
-
backend/app/dependencies.pycontains an in-memory process-local session cache for auth tokens. This optimization is valid for a single-process server, but it is not cluster-safe for multi-worker or distributed deployments.- Fix: either document the single-process limitation clearly, or replace
_session_cachewith an external shared cache (Redis/Memcached) or eliminate it if eventual cluster support is required. - Expected outcome: authentication behavior is consistent across deployment modes, and session invalidation works correctly in multi-worker setups.
- Fix: either document the single-process limitation clearly, or replace
-
backend/app/main.pyuses local imports inside_lifespan()to avoid circular dependencies, indicating that startup logic is tightly coupled with services.- Fix: evaluate whether the startup initialization can be moved into a dedicated
startup.pyor split service initialization into smaller modules; keep import order simple and explicit. - Expected outcome: cleaner startup code with lower coupling, fewer hidden circular import risks, and easier maintenance.
- Fix: evaluate whether the startup initialization can be moved into a dedicated
Recommended refactors for an AI agent
- Status: done — Standardise dependency injection in routers by using
SettingsDep,ServerStatusDep,PendingRecoveryDep, and other dependency definitions frombackend/app/dependencies.py. - Refactor
backend/app/utils/so it does not import business-layer services. Move cross-layer helpers to the appropriate layer or introduce a shared helper package if needed. - Simplify background task DB management in
backend/app/tasks/: remove the deadapp.state.dblogic or implement a real shared connection and document its lifecycle. - Document auth cache semantics in the code and project docs. If cluster deployments are intended, replace the process-local cache with a shared cache or remove it.
- Inspect
backend/app/main.pystartup wiring and reduce local import usage by extracting startup responsibilities into clearer components.
Goals and expectations for the fix
- Preserve existing functionality while reducing hidden coupling.
- Improve testability of routers and background tasks by making dependencies explicit.
- Make the application startup and shared-state behavior easy to reason about.
- Ensure backend architecture is stable for future refactors, especially around authentication, config handling, and scheduled jobs.
- Provide enough detail so an AI agent can make the changes safely without altering business behavior.