- Break entity shim chain: brokerPositionApi, brokerOperationApi now use shared/api/client directly - Remove all 43 shim re-export files (api/, hooks/, context/, components/, pages/ flat shims, routes.tsx) - Remove entire pages/broker/ dead code directory - Remove api/broker.ts after breaking the shim chain - Switch auth consumers from AuthProvider (shim) to SessionProvider (FSD) - Fix api/screener.ts imports to use @/shared/api - Update frontend hooks.md and routes.md documentation - 2840 lines removed, 71 lines added
5.5 KiB
Frontend FSD Cleanup — план
Общий подход
7 последовательных шагов, каждый шаг верифицируется npm test -w apps/frontend.
После шага 1 (разрыв цепочки) удаляем файлы. После шагов 3-6 обновляем документацию.
Шаг 1. Разорвать цепочку entity shims к api/broker.ts
entities/broker-position/api/brokerPositionApi.ts— переписать на прямой вызовshared/api/cliententities/broker-operation/api/brokerOperationApi.ts— переписать на прямой вызовshared/api/client
Оба файла делают то же, что entities/broker-account/api/brokerAccountApi.ts уже делает:
импортируют apiClient из shared/api/client и типы из shared/api/responses.
После этого шага api/broker.ts перестаёт быть нужен.
Шаг 2. Переключить потребителей shim на FSD-импорты
Три группы потребителей:
-
pages/broker/BrokerPages.test.tsx— импортирует мокиuseBrokerAccountsиuseBrokerAccountPortfoliosиз../../hooks/. Переключить на импорт изentities/broker-account(черезvi.mock(entities/broker-account)). Сами файлы shim-хуков будут удалены на шаге 3, но пока их тесты нужно переключить. -
pages/broker/BrokerAccountsPage.test.tsx— импортируетBrokerAccountsPageиз./BrokerAccountsPage(который shim вpages/broker/). Переключить наpages/broker-accounts. После миграции тест будет жить при FSD-странице. -
Три файла импортируют
AuthProviderизcontext/AuthContext:test/test-utils.tsxhooks/useAuth.test.tsxentities/session/model/useSession.test.tsx
Заменить на импорт
SessionProviderизapp/providers/SessionProvider.AuthProvider— это просто alias.
Шаг 3. Удалить shim-файлы
api/ (кроме api/screener.ts)
api/auth.ts→ re-export изentities/session/api/sessionApiapi/client.ts→ re-export изshared/api/clientapi/portfolio.ts→ re-export изentities/portfolio/api/portfolioApiapi/responses.ts→ re-export изshared/api/responsesapi/types.ts→ re-export изshared/api/typesapi/broker.ts→ больше не нужен (шаг 1)api/broker.test.ts→ мёртвый код
hooks/ (кроме hooks/useScreener.ts)
Все 17 файлов — однострочные re-export.
context/
context/AuthContext.tsx— re-exportcontext/AuthContext.test.tsx— тест shim
components/ (кроме components/screener/ и components/portfolios/)
components/Layout.tsx→app/layouts/AppLayoutcomponents/ProtectedRoute.tsx→app/routing/ProtectedRoutecomponents/SearchBar.tsx→widgets/search-barcomponents/PriceChart.tsx→widgets/price-chartcomponents/StockDetails.tsx→widgets/stock-detailscomponents/BondDetails.tsx→widgets/bond-detailscomponents/SkeletonBlock.tsx→shared/ui/SkeletonBlockcomponents/TableSkeleton.tsx→shared/ui/TableSkeleton- Соответствующие
.test.tsxфайлы
pages/ flat shims
pages/HomePage.tsx→pages/homepages/StockPage.tsx→pages/stockpages/BondPage.tsx→pages/bond- Соответствующие
.test.tsxфайлы
pages/broker/ (весь каталог)
13 файлов — все shims.
Корень src/
routes.tsx→ re-export изapp/routing/AppRoutes
Шаг 4. Удалить тесты, привязанные к shim-файлам
После удаления shim-файлов их тесты тоже удаляются:
api/auth.test.ts,api/client.test.ts,api/broker.test.tshooks/useAuth.test.tsx,hooks/useBrokerAccountPortfolios.test.tsx,hooks/useBrokerAccounts.test.tsx,hooks/useSearch.test.tsxcontext/AuthContext.test.tsxcomponents/BondDetails.test.tsx,components/Layout.test.tsx,components/PriceChart.test.tsx,components/ProtectedRoute.test.tsx,components/SearchBar.test.tsx,components/StockDetails.test.tsxpages/HomePage.test.tsx,pages/StockPage.test.tsx,pages/BondPage.test.tsxpages/broker/BrokerPages.test.tsx,pages/broker/BrokerAccountsPage.test.tsx
Функциональность этих тестов уже покрыта тестами внутри FSD-слоёв.
Шаг 5. Удалить api/broker.ts
После шага 1 (разрыв цепочки) entity API прокси больше не ссылаются на api/broker.ts.
Осталось только удалить сам файл.
Шаг 6. Обновить документацию
apps/docs/docs/frontend/hooks.md— убрать секции про legacy shim-путиapps/docs/docs/frontend/routes.md— убрать упоминания shim-файлов
Шаг 7. Финальная верификация
npm test -w apps/frontend— PASSnpm run lint -w apps/frontend— PASSnpm run build -w apps/frontend— PASSnpm run build -w apps/docs— PASS- Deep import verification:
rg -n "@/api/|@/hooks/|@/context/|@/components/(?!screener|portfolios)" apps/frontend/src— no matches