Sergey Krylov 238836c850 refactor(backend): connect RequestLoggingMiddleware through DI
- AppModule implements NestModule with configure() for middleware
- Remove manual middleware instantiation from main.ts
- 120 tests pass, build succeeds
2026-06-25 20:37:10 +03:00

3.4 KiB
Raw Blame History

Backend Architecture Improvements — Tasks

Итерация 1: Shared envelope DTO + consistency fixes

  • 1.1 Создать документ аудита в docs/research/
  • 1.2 Вынести ApiResponseMeta в common/dto/api-response.dto.ts как единый shared класс
  • 1.3 Заменить AuthResponseMetaDto на ApiResponseMeta в auth/
  • 1.4 Заменить PortfolioResponseMetaDto на ApiResponseMeta в portfolio/
  • 1.5 Заменить BrokerResponseMetaDto на ApiResponseMeta в tbank/
  • 1.6 Поправить shares/shares.service.ts:getShare() — обернуть в ApiEnvelopePayload
  • 1.7 Убрать лишний импорт CacheModule из securities/securities.module.ts
  • 1.8 Удалить дублирующиеся envelope DTO (ScreenerResponseMetaDto, AuthResponseMetaDto, PortfolioResponseMetaDto, BrokerResponseMetaDto)
  • 1.9 npm run build успешен, 116 тестов проходят

Итерация 2: Screener caching

  • 2.1 Добавить screenerTtl в конфиг (900s default)
  • 2.2 Перевести screener на отдельный TTL
  • 2.3 Тест на cache key + ttl config key

Итерация 3: Domain exceptions

  • 3.1 Создать common/exceptions/domain.exception.ts
  • 3.2 Создать common/exceptions/entity-not-found.exception.ts
  • 3.3 Создать common/exceptions/moex-api.exception.ts
  • 3.4 Создать common/exceptions/tbank-api.exception.ts (+ TBankNotConfiguredException)
  • 3.5 Создать common/exceptions/portfolio-access.exception.ts
  • 3.6 Обновить HttpExceptionFilter с логгированием необработанных ошибок
  • 3.7 Заменить generic исключения в shares, bonds, portfolio, tbank сервисах
  • 3.8 Обновлены все тесты (117 проходят)

Итерация 4: Health check

  • 4.1 Создан HealthService с checkPrisma() — реальный SQL-запрос
  • 4.2 Добавлен checkMoex() — HTTP-запрос к ISS MOEX с 5s timeout
  • 4.3 Добавлен checkTBank() — проверка наличия токена
  • 4.4 HealthResponseDto обновлён: добавлено поле checks: HealthCheckResultDto[]
  • 4.5 Модуль обновлён (imports PrismaModule, providers HealthService)
  • 4.6 Тесты: health.service.spec.ts (3 теста) + envelope-contract.spec.ts проверяет checks
  • Все 120 тестов проходят

Итерация 5: RequestLoggingMiddleware DI

  • 5.1 AppModule implements NestModule с configure()consumer.apply(RequestLoggingMiddleware).forRoutes('*')
  • 5.2 Убран new RequestLoggingMiddleware() и app.use() из main.ts
  • 120 тестов проходят, build успешен

Итерация 6: MoexClientService split (отдельный эпик)

  • 6.1 ADR на разделение MoexClientService
  • 6.2 spec/plan/tasks отдельного эпика
  • 6.3 Выделение rate limiter + circuit breaker в shared utils
  • 6.4 Создание MoexSecuritiesClient
  • 6.5 Создание MoexMarketDataClient
  • 6.6 Создание MoexCandlesClient
  • 6.7 Обновление всех потребителей