- 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
106 lines
5.5 KiB
Markdown
106 lines
5.5 KiB
Markdown
# 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/client`
|
||
- `entities/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-импорты
|
||
|
||
Три группы потребителей:
|
||
|
||
1. `pages/broker/BrokerPages.test.tsx` — импортирует моки `useBrokerAccounts` и `useBrokerAccountPortfolios` из `../../hooks/`. Переключить на импорт из `entities/broker-account` (через `vi.mock(entities/broker-account)`). Сами файлы shim-хуков будут удалены на шаге 3, но пока их тесты нужно переключить.
|
||
|
||
2. `pages/broker/BrokerAccountsPage.test.tsx` — импортирует `BrokerAccountsPage` из `./BrokerAccountsPage` (который shim в `pages/broker/`). Переключить на `pages/broker-accounts`. После миграции тест будет жить при FSD-странице.
|
||
|
||
3. Три файла импортируют `AuthProvider` из `context/AuthContext`:
|
||
- `test/test-utils.tsx`
|
||
- `hooks/useAuth.test.tsx`
|
||
- `entities/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/sessionApi`
|
||
- `api/client.ts` → re-export из `shared/api/client`
|
||
- `api/portfolio.ts` → re-export из `entities/portfolio/api/portfolioApi`
|
||
- `api/responses.ts` → re-export из `shared/api/responses`
|
||
- `api/types.ts` → re-export из `shared/api/types`
|
||
- `api/broker.ts` → больше не нужен (шаг 1)
|
||
- `api/broker.test.ts` → мёртвый код
|
||
|
||
### hooks/ (кроме hooks/useScreener.ts)
|
||
Все 17 файлов — однострочные re-export.
|
||
|
||
### context/
|
||
- `context/AuthContext.tsx` — re-export
|
||
- `context/AuthContext.test.tsx` — тест shim
|
||
|
||
### components/ (кроме components/screener/ и components/portfolios/)
|
||
- `components/Layout.tsx` → `app/layouts/AppLayout`
|
||
- `components/ProtectedRoute.tsx` → `app/routing/ProtectedRoute`
|
||
- `components/SearchBar.tsx` → `widgets/search-bar`
|
||
- `components/PriceChart.tsx` → `widgets/price-chart`
|
||
- `components/StockDetails.tsx` → `widgets/stock-details`
|
||
- `components/BondDetails.tsx` → `widgets/bond-details`
|
||
- `components/SkeletonBlock.tsx` → `shared/ui/SkeletonBlock`
|
||
- `components/TableSkeleton.tsx` → `shared/ui/TableSkeleton`
|
||
- Соответствующие `.test.tsx` файлы
|
||
|
||
### pages/ flat shims
|
||
- `pages/HomePage.tsx` → `pages/home`
|
||
- `pages/StockPage.tsx` → `pages/stock`
|
||
- `pages/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.ts`
|
||
- `hooks/useAuth.test.tsx`, `hooks/useBrokerAccountPortfolios.test.tsx`,
|
||
`hooks/useBrokerAccounts.test.tsx`, `hooks/useSearch.test.tsx`
|
||
- `context/AuthContext.test.tsx`
|
||
- `components/BondDetails.test.tsx`, `components/Layout.test.tsx`,
|
||
`components/PriceChart.test.tsx`, `components/ProtectedRoute.test.tsx`,
|
||
`components/SearchBar.test.tsx`, `components/StockDetails.test.tsx`
|
||
- `pages/HomePage.test.tsx`, `pages/StockPage.test.tsx`, `pages/BondPage.test.tsx`
|
||
- `pages/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` — PASS
|
||
- `npm run lint -w apps/frontend` — PASS
|
||
- `npm run build -w apps/frontend` — PASS
|
||
- `npm run build -w apps/docs` — PASS
|
||
- Deep import verification: `rg -n "@/api/|@/hooks/|@/context/|@/components/(?!screener|portfolios)" apps/frontend/src` — no matches
|