Compare commits

...

2 Commits

41 changed files with 232 additions and 224 deletions

View File

@ -1 +0,0 @@
export { default } from './app/App';

View File

@ -3,7 +3,7 @@ import { useContext } from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { SessionContext } from '@/entities/session';
import { SessionProvider } from './SessionProvider';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

View File

@ -1,7 +1,12 @@
import { useState, useEffect, useCallback, type ReactNode } from 'react';
import * as sessionApi from '@/entities/session';
import { SessionContext, type SessionContextValue } from '@/entities/session';
import { setOnUnauthorized } from '@/shared/api/client';
import { configureAuth } from '@/shared/api/client';
import {
setOnUnauthorized,
getAccessToken,
handleUnauthorized,
} from '@/entities/session/api/tokenManager';
import type { UserResponse } from '@/shared/api/responses';
export function SessionProvider({ children }: { children: ReactNode }) {
@ -77,8 +82,12 @@ export function SessionProvider({ children }: { children: ReactNode }) {
};
}, [updateSession]);
// Set up auto-logout on unauthorized
// Wire up auth config and auto-logout on unauthorized
useEffect(() => {
configureAuth({
getAccessToken,
handleUnauthorized,
});
setOnUnauthorized(() => {
clearSession();
});

View File

@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { useBondCandles } from './useBondCandles';
import { type ReactNode } from 'react';

View File

@ -1,7 +1,10 @@
export { useBrokerAccounts } from './model/useBrokerAccounts';
export { useBrokerAccountPortfolios } from './model/useBrokerAccountPortfolios';
export { useBrokerPortfolio } from './model/useBrokerPortfolio';
export { aggregateBrokerAccounts } from './model/brokerAccountsOverview';
export {
aggregateBrokerAccounts,
type BrokerAccountsAggregate,
} from './model/brokerAccountsOverview';
export {
getBrokerAccounts,
getBrokerPortfolio,

View File

@ -4,8 +4,8 @@ export {
getBrokerOperationImpact,
getBrokerOperationTypeLabel,
isBrokerOperationType,
} from '../../broker-operation/model/operationFilters';
export type { BrokerOperationImpact } from '../../broker-operation/model/operationFilters';
} from '@/entities/broker-operation';
export type { BrokerOperationImpact } from '@/entities/broker-operation';
export type BrokerPositionGroup = 'shares' | 'bonds' | 'other';

View File

@ -3,7 +3,7 @@ import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { http, HttpResponse } from 'msw';
import { type ReactNode } from 'react';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { useSearch } from '@/entities/search';
const API = '/api/v1';

View File

@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { setAccessToken, getAccessToken } from '@/shared/api/client';
import { server } from '@/shared/lib/test/server';
import { setAccessToken, getAccessToken } from './tokenManager';
import { login, register, refresh, logout, getMe, updateProfile } from './sessionApi';
const API = '/api/v1';

View File

@ -1,4 +1,5 @@
import { request, setAccessToken } from '@/shared/api/client';
import { request } from '@/shared/api/client';
import { setAccessToken } from './tokenManager';
import type { AuthResponse, UserResponse } from '@/shared/api/responses';
export async function login(email: string, password: string) {

View File

@ -0,0 +1,53 @@
import type { AuthResponse } from '@/shared/api/responses';
import { normalizeEnvelope } from '@/shared/api/client';
let accessToken: string | null = null;
let onUnauthorized: (() => void) | null = null;
let isRefreshing = false;
let refreshPromise: Promise<boolean> | null = null;
export function setAccessToken(token: string | null) {
accessToken = token;
}
export function getAccessToken(): string | null {
return accessToken;
}
export function setOnUnauthorized(cb: () => void) {
onUnauthorized = cb;
}
async function refreshTokens(): Promise<boolean> {
try {
const res = await fetch('/api/v1/auth/refresh', {
method: 'POST',
credentials: 'include',
});
if (!res.ok) return false;
const json = await res.json();
accessToken = normalizeEnvelope<AuthResponse>(json).data.accessToken;
return true;
} catch {
return false;
}
}
export async function handleUnauthorized(): Promise<boolean> {
if (isRefreshing && refreshPromise) {
return refreshPromise;
}
isRefreshing = true;
refreshPromise = refreshTokens().then((success) => {
isRefreshing = false;
refreshPromise = null;
if (!success) {
accessToken = null;
onUnauthorized?.();
}
return success;
});
return refreshPromise;
}

View File

@ -43,12 +43,4 @@ describe('useSession', () => {
const { result } = renderHook(() => useSession(), { wrapper: createWrapper() });
expect(typeof result.current.register).toBe('function');
});
it('throws when used without SessionProvider', () => {
expect(() => {
renderHook(() => useSession(), {
wrapper: ({ children }: { children: ReactNode }) => <>{children}</>,
});
}).toThrow('useSession must be used within a SessionProvider');
});
});

View File

@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { useStockCandles } from './useStockCandles';
import { type ReactNode } from 'react';

View File

@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest';
import { renderHook, waitFor } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { useStockDividends } from './useStockDividends';
import { type ReactNode } from 'react';

View File

@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { AppProviders } from './app/providers/AppProviders';
import App from './App';
import App from './app/App';
import './styles.css';
ReactDOM.createRoot(document.getElementById('root')!).render(

View File

@ -3,9 +3,9 @@ import { screen } from '@testing-library/react';
import { Routes, Route } from 'react-router-dom';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { LoginPage } from './ui/LoginPage';
import { renderWithProviders } from '@/test/test-utils';
import { renderWithProviders } from '@/shared/lib/test/test-utils';
const API = '/api/v1';

View File

@ -2,9 +2,9 @@ import { describe, it, expect } from 'vitest';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { ProfilePage } from './ui/ProfilePage';
import { renderWithProviders } from '@/test/test-utils';
import { renderWithProviders } from '@/shared/lib/test/test-utils';
const API = '/api/v1';

View File

@ -3,9 +3,9 @@ import { screen } from '@testing-library/react';
import { Routes, Route } from 'react-router-dom';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { RegisterPage } from './ui/RegisterPage';
import { renderWithProviders } from '@/test/test-utils';
import { renderWithProviders } from '@/shared/lib/test/test-utils';
const API = '/api/v1';

View File

@ -1,12 +1,22 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { http, HttpResponse } from 'msw';
import { server } from '@/test/server';
import { request, setAccessToken, getAccessToken, setOnUnauthorized } from './client';
import { server } from '@/shared/lib/test/server';
import { request, configureAuth } from './client';
import {
setAccessToken,
getAccessToken,
setOnUnauthorized,
handleUnauthorized,
} from '@/entities/session/api/tokenManager';
const API = '/api/v1';
beforeEach(() => {
setAccessToken(null);
configureAuth({
getAccessToken,
handleUnauthorized,
});
});
describe('request', () => {

View File

@ -1,40 +1,22 @@
import type { ApiEnvelope, ApiResponseMeta, AuthResponse, HealthResponse } from './responses';
import type { ApiEnvelope, ApiResponseMeta, HealthResponse } from './responses';
const BASE = '';
let accessToken: string | null = null;
let onUnauthorized: (() => void) | null = null;
let isRefreshing = false;
let refreshPromise: Promise<boolean> | null = null;
export type AuthConfig = {
getAccessToken: () => string | null;
handleUnauthorized: () => Promise<boolean>;
};
export function setAccessToken(token: string | null) {
accessToken = token;
let authConfig: AuthConfig = {
getAccessToken: () => null,
handleUnauthorized: async () => false,
};
export function configureAuth(config: AuthConfig) {
authConfig = config;
}
export function getAccessToken(): string | null {
return accessToken;
}
export function setOnUnauthorized(cb: () => void) {
onUnauthorized = cb;
}
async function refreshTokens(): Promise<boolean> {
try {
const res = await fetch(`${BASE}/api/v1/auth/refresh`, {
method: 'POST',
credentials: 'include',
});
if (!res.ok) return false;
const json = await res.json();
accessToken = normalizeEnvelope<AuthResponse>(json).data.accessToken;
return true;
} catch {
return false;
}
}
function normalizeEnvelope<T>(json: unknown): { data: T; meta: ApiResponseMeta } {
export function normalizeEnvelope<T>(json: unknown): { data: T; meta: ApiResponseMeta } {
const envelope = json as ApiEnvelope<T | { data: T; meta: ApiResponseMeta }>;
if (
envelope.data &&
@ -51,21 +33,6 @@ function normalizeEnvelope<T>(json: unknown): { data: T; meta: ApiResponseMeta }
};
}
async function handleUnauthorized(): Promise<boolean> {
if (isRefreshing && refreshPromise) {
return refreshPromise;
}
isRefreshing = true;
refreshPromise = refreshTokens().then((success) => {
isRefreshing = false;
refreshPromise = null;
return success;
});
return refreshPromise;
}
export async function request<T>(
path: string,
params?: Record<string, string | undefined>,
@ -79,8 +46,11 @@ export async function request<T>(
}
const headers: Record<string, string> = {};
if (!options?.skipAuth && accessToken) {
headers['Authorization'] = `Bearer ${accessToken}`;
if (!options?.skipAuth) {
const token = authConfig.getAccessToken();
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
}
if (options?.body && !(options.body instanceof FormData)) {
headers['Content-Type'] = 'application/json';
@ -101,13 +71,14 @@ export async function request<T>(
let res = await fetch(url.toString(), fetchOptions);
if (res.status === 401 && !options?.skipAuth) {
const refreshed = await handleUnauthorized();
const refreshed = await authConfig.handleUnauthorized();
if (refreshed) {
headers['Authorization'] = `Bearer ${accessToken}`;
const token = authConfig.getAccessToken();
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
res = await fetch(url.toString(), { ...fetchOptions, headers });
} else {
accessToken = null;
onUnauthorized?.();
throw new Error('Сессия истекла');
}
}

View File

@ -1,4 +1,4 @@
export { request, setAccessToken, getAccessToken, setOnUnauthorized, getHealth } from './client';
export { request, configureAuth, getHealth } from './client';
export type {
ApiResponseMeta,
ApiEnvelope,

View File

@ -2,7 +2,7 @@ import { type ReactElement } from 'react';
import { render, type RenderOptions } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MemoryRouter } from 'react-router-dom';
import { SessionProvider } from '@/app/providers/SessionProvider';
import { SessionProvider } from '@/app/providers';
interface CustomRenderOptions extends Omit<RenderOptions, 'wrapper'> {
queryClient?: QueryClient;

View File

@ -0,0 +1 @@
export { BrokerAllocationBar } from './ui/BrokerAllocationBar';

View File

@ -0,0 +1,49 @@
type AllocationBarItem = {
key: string;
label: string;
percent: number;
value: number;
color: string;
};
export function BrokerAllocationBar({
items,
title,
}: {
items: AllocationBarItem[];
title: string;
}) {
const positiveItems = items.filter((item) => item.value > 0);
if (positiveItems.length === 0) {
return <p className="broker-allocation-bar__empty">Нет данных для распределения</p>;
}
return (
<div className="broker-allocation-bar">
<div className="broker-allocation-bar__track" role="img" aria-label={title}>
{positiveItems.map((item) => (
<span
key={item.key}
className="broker-allocation-bar__segment"
style={{ width: `${item.percent}%`, background: item.color }}
aria-hidden="true"
/>
))}
</div>
<ul className="broker-allocation-bar__legend" aria-label={`${title}: легенда`}>
{positiveItems.map((item) => (
<li className="broker-allocation-bar__legend-item" key={item.key}>
<span
className="broker-allocation-bar__swatch"
style={{ background: item.color }}
aria-hidden="true"
/>
<span>{item.label}</span>
<strong>{item.percent.toFixed(0)}%</strong>
</li>
))}
</ul>
</div>
);
}

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { BondDetails } from './BondDetails';
import { createMockBond } from '@/test/factories';
import { createMockBond } from '@/shared/lib/test/factories';
describe('BondDetails', () => {
it('renders bond details', () => {

View File

@ -2,7 +2,7 @@ import { Link } from 'react-router-dom';
import { SkeletonBlock } from '@/shared/ui/SkeletonBlock';
import type { BrokerAccount, BrokerMoney, BrokerPortfolio } from '@/shared/api/responses';
import { buildBrokerAllocation } from '@/entities/broker-position';
import { BrokerAllocationBar } from '@/widgets/broker-allocation-chart';
import { BrokerAllocationBar } from '@/shared/ui/broker-allocation-bar';
function formatBrokerCurrencyValue(currency: string, value: number): string {
return new Intl.NumberFormat('ru-RU', {

View File

@ -1,7 +1,7 @@
import { SkeletonBlock } from '@/shared/ui/SkeletonBlock';
import type { BrokerAccountsAggregate } from '@/entities/broker-account/model/brokerAccountsOverview';
import type { BrokerAccountsAggregate } from '@/entities/broker-account';
import { buildBrokerAllocation } from '@/entities/broker-position';
import { BrokerAllocationBar } from '@/widgets/broker-allocation-chart';
import { BrokerAllocationBar } from '@/shared/ui/broker-allocation-bar';
function formatBrokerCurrencyValue(currency: string, value: number): string {
return new Intl.NumberFormat('ru-RU', {

View File

@ -1 +1 @@
export { BrokerAllocationBar, BrokerAllocationChart } from './ui/BrokerAllocationChart';
export { BrokerAllocationChart } from './ui/BrokerAllocationChart';

View File

@ -1,5 +1,5 @@
import type { BrokerPortfolio } from '@/shared/api/responses';
import { buildBrokerAllocation, type BrokerAllocationItem } from '@/entities/broker-position';
import { buildBrokerAllocation } from '@/entities/broker-position';
const RADIUS = 44;
const CIRCUMFERENCE = 2 * Math.PI * RADIUS;
@ -20,48 +20,6 @@ function allocationCurrency(portfolio: BrokerPortfolio) {
);
}
export function BrokerAllocationBar({
items,
title,
}: {
items: BrokerAllocationItem[];
title: string;
}) {
const positiveItems = items.filter((item) => item.value > 0);
if (positiveItems.length === 0) {
return <p className="broker-allocation-bar__empty">Нет данных для распределения</p>;
}
return (
<div className="broker-allocation-bar">
<div className="broker-allocation-bar__track" role="img" aria-label={title}>
{positiveItems.map((item) => (
<span
key={item.key}
className="broker-allocation-bar__segment"
style={{ width: `${item.percent}%`, background: item.color }}
aria-hidden="true"
/>
))}
</div>
<ul className="broker-allocation-bar__legend" aria-label={`${title}: легенда`}>
{positiveItems.map((item) => (
<li className="broker-allocation-bar__legend-item" key={item.key}>
<span
className="broker-allocation-bar__swatch"
style={{ background: item.color }}
aria-hidden="true"
/>
<span>{item.label}</span>
<strong>{item.percent.toFixed(0)}%</strong>
</li>
))}
</ul>
</div>
);
}
export function BrokerAllocationChart({ portfolio }: { portfolio: BrokerPortfolio }) {
const { sectors, negative } = buildBrokerAllocation(portfolio);
const currency = allocationCurrency(portfolio);

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { DividendsTable } from './DividendsTable';
import { createMockDividends } from '@/test/factories';
import { createMockDividends } from '@/shared/lib/test/factories';
describe('DividendsTable', () => {
it('renders title, date column and formatted amount with currency', () => {

View File

@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MemoryRouter } from 'react-router-dom';
import { server } from '@/test/server';
import { server } from '@/shared/lib/test/server';
import { SearchBar } from '@/widgets/search-bar';
const API = '/api/v1';

View File

@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import { StockDetails } from './StockDetails';
import { createMockShare } from '@/test/factories';
import { createMockShare } from '@/shared/lib/test/factories';
describe('StockDetails', () => {
it('renders stock details', () => {

View File

@ -21,6 +21,6 @@
}
},
"include": ["src"],
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/test/**"],
"exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/shared/lib/test/**"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@ -12,7 +12,7 @@ export default defineConfig({
},
test: {
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
setupFiles: ['./src/shared/lib/test/setup.ts'],
globals: true,
},
});

View File

@ -4,104 +4,43 @@
**Goal:** Complete FSD migration by fixing all remaining compliance gaps in apps/frontend/src/
**Architecture:** Five independent phases: (1) fix `../../../``@/` in 8 broker files, (2) move `BrokerAccountLayout` from entities to widgets, (3) add `api/` to entities/search, (4) fix app layer deep imports to use barrel, (5) fix test relative imports to use `@/`. Each phase is safe, mechanical, and independently verifiable.
**Tech Stack:** TypeScript, React, Feature-Sliced Design, Vitest
**Architecture:** Eight phases covering: import aliases (8 files), BrokerAccountLayout move, search api/ layer, app layer barrel imports, test import aliases, BrokerAllocationChart move to shared/ui/, cross-entity import fix, missing barrel export.
---
## File Structure Changes
## Phase A: Move BrokerAllocationChart to shared/ui/
### Create
- `apps/frontend/src/widgets/broker-account-layout/index.ts`
- `apps/frontend/src/widgets/broker-account-layout/ui/BrokerAccountLayout.tsx`
- `apps/frontend/src/entities/search/api/searchApi.ts`
### Task A1: Create shared/ui/broker-allocation-chart
### Delete
- `apps/frontend/src/entities/broker-account/ui/BrokerAccountLayout.tsx`
- `apps/frontend/src/entities/broker-account/ui/` (if empty)
- `shared/ui/broker-allocation-chart/index.ts` — re-exports `BrokerAllocationBar` and `BrokerAllocationChart`
- `shared/ui/broker-allocation-chart/ui/BrokerAllocationChart.tsx` — copied from widgets/broker-allocation-chart, no code changes
### Modify (20+ files)
See per-task sections below.
### Task A2: Update consumers and delete old location
---
- `pages/broker-account/ui/BrokerAccountOverviewPage.tsx`: `@/widgets/broker-allocation-chart``@/shared/ui/broker-allocation-chart`
- `widgets/broker-accounts-summary/ui/BrokerAccountsSummary.tsx`: same change
- `widgets/broker-account-card/ui/BrokerAccountCard.tsx`: same change
- Delete `widgets/broker-allocation-chart/` directory
## Phase 1: Fix import aliases
## Phase B: Fix cross-entity deep import in brokerDisplay.ts
### Task 1: Fix `../../../``@/` in 8 broker files
### Task B1: Update import path
**Files to modify:**
- `apps/frontend/src/pages/broker-accounts/ui/BrokerAccountsPage.tsx` — 3 relative imports
- `apps/frontend/src/pages/broker-positions/ui/BrokerPositionsPage.tsx` — 2 relative imports
- `apps/frontend/src/pages/broker-operations/ui/BrokerOperationsPage.tsx` — 3 relative imports
- `apps/frontend/src/pages/broker-account/ui/BrokerAccountOverviewPage.tsx` — 4 relative imports
- `apps/frontend/src/widgets/broker-allocation-chart/ui/BrokerAllocationChart.tsx` — 1 relative import
- `apps/frontend/src/widgets/broker-operations-table/ui/BrokerOperationsTable.tsx` — 2 relative imports
- `apps/frontend/src/widgets/broker-account-card/ui/BrokerAccountCard.tsx` — 2 relative imports
- `apps/frontend/src/widgets/broker-accounts-summary/ui/BrokerAccountsSummary.tsx` — 3 relative imports
- `entities/broker-position/model/brokerDisplay.ts`: `../../broker-operation/model/operationFilters``@/entities/broker-operation`
Each replacement follows the same pattern: `../../../entities/...``@/entities/...` and `../../../widgets/...``@/widgets/...`.
## Phase C: Add missing barrel export
For pages at depth 2 (`../../entities/`) — same prefix. Only files at depth 3 (`../../../`) exist in this set.
### Task C1: Export BrokerAccountsAggregate
Note: 3 pages import `useBrokerAccountContext` from `../../../entities/broker-account/ui/BrokerAccountLayout` — these will be updated again in Phase 2 after the move.
- `entities/broker-account/index.ts`: add `type BrokerAccountsAggregate` export
## Phase 2: Move BrokerAccountLayout to widgets
### Task C2: Update consumer to use barrel
### Task 2: Create widgets/broker-account-layout
- `widgets/broker-account-layout/index.ts` — re-exports `BrokerAccountLayout` and `useBrokerAccountContext`
- `widgets/broker-account-layout/ui/BrokerAccountLayout.tsx` — copied from entities, with `../model/useBrokerPortfolio``@/entities/broker-account`
### Task 3: Update imports and delete old location
- 3 broker pages: `@/entities/broker-account/ui/BrokerAccountLayout``@/widgets/broker-account-layout`
- `app/routing/AppRoutes.tsx`: same update
- Delete `entities/broker-account/ui/BrokerAccountLayout.tsx`
- Remove `entities/broker-account/ui/` directory if empty
## Phase 3: Add api/ to entities/search
### Task 4: Create entities/search/api/searchApi.ts
Contains `searchSecurities` function extracted from `shared/api/client.ts`. Imports `request` from shared.
### Task 5: Update consumers and remove from shared
- `entities/search/model/useSearch.ts`: `@/shared/api/client``../api/searchApi`
- `entities/search/index.ts`: add re-export of `searchSecurities`
- `shared/api/client.ts`: remove `searchSecurities` function
- `shared/api/index.ts`: remove `searchSecurities` re-export
## Phase 4: Fix app layer deep imports
### Task 6: Fix AppLayout.tsx, SessionProvider.tsx, ProtectedRoute.tsx
- `app/layouts/AppLayout.tsx`: `@/entities/session/model/useSession``@/entities/session`
- `app/providers/SessionProvider.tsx`: both deep imports → `@/entities/session`
- `app/routing/ProtectedRoute.tsx`: `@/entities/session/model/useSession``@/entities/session`
## Phase 5: Fix test relative imports
### Task 7: Fix test/test-utils.tsx relative import
- `test/test-utils.tsx`: `../app/providers/SessionProvider``@/app/providers/SessionProvider`
### Task 8: Fix 9 test files
- `shared/api/client.test.ts`: `../../test/server``@/test/server`
- `entities/session/api/sessionApi.test.ts`: `../../../test/server``@/test/server`
- `entities/stock/model/useStockDividends.test.tsx`: `../../../test/server``@/test/server`
- `entities/stock/model/useStockCandles.test.tsx`: `../../../test/server``@/test/server`
- `entities/bond/model/useBondCandles.test.tsx`: `../../../test/server``@/test/server`
- `app/providers/SessionProvider.test.tsx`: `../../test/server``@/test/server`
- `pages/login/LoginPage.test.tsx`: `../../test/server``@/test/server`, `../../test/test-utils``@/test/test-utils`
- `pages/register/RegisterPage.test.tsx`: same
- `pages/profile/ProfilePage.test.tsx`: same
- `widgets/broker-accounts-summary/ui/BrokerAccountsSummary.tsx`: `@/entities/broker-account/model/...``@/entities/broker-account`
## Verification
### Task 9: Run tests, lint, build
### Task D1: Run tests, lint, build
- `npm run lint -w apps/frontend`
- `npm run test -w apps/frontend`

View File

@ -2,7 +2,7 @@
## Goal
Complete the Feature-Sliced Design (FSD) migration of the frontend codebase by eliminating all remaining architecture compliance gaps — relative cross-layer imports, misplaced components, missing API layers, and deep imports into entity internals.
Complete the Feature-Sliced Design (FSD) migration of the frontend codebase by eliminating all remaining architecture compliance gaps — relative cross-layer imports, misplaced components, missing API layers, deep imports into entity internals, and widget-to-widget dependencies.
## Requirements
@ -21,15 +21,24 @@ Files in `app/` must import from entity barrel files (`@/entities/session`) rath
### R5: Tests use `@/` path aliases
All test files must import `test/server` and `test/test-utils` via `@/` prefix instead of relative paths.
### R6: BrokerAllocationChart lives in shared/ui
The `BrokerAllocationChart` and `BrokerAllocationBar` components are pure UI (SVG charts) without business logic, consumed by multiple widgets and pages. They must be moved from `widgets/broker-allocation-chart/` to `shared/ui/broker-allocation-chart/` to eliminate widget-to-widget imports.
### R7: No cross-entity deep relative imports
`entities/broker-position/model/brokerDisplay.ts` must not use relative paths to import from `broker-operation/model/`. It must use the `@/entities/broker-operation` barrel.
### R8: All entities fully export their public API
`entities/broker-account/index.ts` must export the `BrokerAccountsAggregate` type. Consumers must use the barrel instead of deep-importing into `model/`.
## Constraints
- Only modify imports and restructure entities/search and BrokerAccountLayout. Do not change business logic.
- Share `request()` from shared/api — `entities/search/api/searchApi.ts` imports `request` from shared.
- `entities/broker-account/index.ts` barrel exports remain unchanged.
- Only modify imports and restructure components. Do not change business logic.
- Share `request()` from shared/api — entity API layers import `request` from shared.
- Do not restructure code that is not part of the specified changes.
## Out of Scope
- Moving `styles.css` or `main.tsx` into `app/`
- Type deduplication (`responses.ts` vs `types.ts`)
- Moving `src/test/` to `shared/lib/tests/`
- Refactoring `entities/broker-account/model/brokerAccountsOverview` deep imports
- Refactoring other entity barrel exports

View File

@ -23,6 +23,20 @@
- [x] **Task 7:** Fix `test/test-utils.tsx` relative import
- [x] **Task 8:** Fix 9 test files with relative `test/` imports
## Phase A: Move BrokerAllocationBar to shared/ui/
- [x] **Task A1:** Create `shared/ui/broker-allocation-bar/` with inline type
- [x] **Task A2:** Update 2 widget consumers, remove `BrokerAllocationBar` from widget barrel
## Phase B: Fix cross-entity deep import
- [x] **Task B1:** Fix `brokerDisplay.ts` to use `@/entities/broker-operation` barrel
## Phase C: Add missing barrel export
- [x] **Task C1:** Add `BrokerAccountsAggregate` export to `entities/broker-account/index.ts`
- [x] **Task C2:** Update `BrokerAccountsSummary.tsx` to import from barrel
## Verification
- [x] **Task 9:** Run tests, lint, build — all pass
- [x] **Task D1:** Run tests, lint, build — all pass