# Потоки данных и сценарии

## Запуск окружения

```mermaid
flowchart TB
  make[make dev / make up]
  env[.env + .env.local]
  networks[docker-compose.networks.yml]
  dbs[docker-compose.dbs.yml]
  apps[docker-compose.apps.yml]
  dev[docker-compose.dev.yml]
  monitoring[docker-compose.monitoring.yml]

  make --> env
  make --> networks
  make --> dbs
  make --> apps
  make --> dev
  make -->|make up| monitoring

  networks --> public[public-network]
  networks --> internal[internal-network]
  dbs --> pgsql[pgsql]
  dbs --> redis[redis]
  apps --> nginx[nginx]
  apps --> php84[php84 backend]
  apps --> php82[php82 cabinet]
  apps --> nextjs[nextjs sovamed]
  dev --> nodejs[nodejs helper]
```

## Синхронизация справочников

```mermaid
sequenceDiagram
  participant Cron as cron / developer
  participant Command as Symfony Command
  participant Bitrix as Bitrix / external source
  participant MIS as Infoclinica / MIS
  participant Service as Domain Service
  participant Repo as Repository
  participant DB as PostgreSQL

  Cron->>Command: php bin/console app:...
  Command->>Bitrix: получить контент/врачей/отзывы
  Command->>MIS: получить расписание/филиалы/цены
  Bitrix-->>Command: external data
  MIS-->>Command: external data
  Command->>Service: нормализовать и применить
  Service->>Repo: upsert/update
  Repo->>DB: persist + flush
```

## Получение расписания врача

```mermaid
sequenceDiagram
  participant Client
  participant Controller as SpecialistController
  participant Service as SpecialistService
  participant Cache as ScheduleCacheService
  participant MIS as InfoclinicaClientService
  participant DB as PostgreSQL

  Client->>Controller: GET /specialist/schedule
  Controller->>Service: getSchedule(...)
  Service->>Cache: getCachedSchedule(query)
  alt cache hit
    Cache-->>Service: cached schedule
  else cache miss
    Service->>MIS: getSchedule(...)
    MIS-->>Service: schedule
    Service->>Cache: saveSchedule(...)
  end
  Service->>DB: при необходимости read/write Schedule
  Service-->>Controller: расписание
  Controller-->>Client: JSON
```

## Анонимная запись

```mermaid
sequenceDiagram
  participant Client
  participant API as Controller
  participant Service as SpecialistService / Infoclinica Rest
  participant MIS as MIS
  participant DB as Record Repository
  participant SMS as SMS service

  Client->>API: POST anonymous-reserve
  API->>Service: подготовить reserve payload
  Service->>MIS: создать запись
  MIS-->>Service: результат записи
  Service->>DB: сохранить Record
  Service->>SMS: отправить уведомление при необходимости
  Service-->>API: success + record data
  API-->>Client: JSON
```

## Авторизация backend по JWT

```mermaid
flowchart LR
  login[POST /user/login] --> dto[UserLoginDto]
  dto --> auth[AuthenticationService]
  auth --> user[(User)]
  auth --> password[password check]
  password --> jwt[JWTTokenManager]
  jwt --> response[token + user]

  request[Защищенный request] --> firewall[JWT firewall]
  firewall --> decoder[JWTDecoderService]
  decoder --> currentUser[Current User]
```

## Авторизация cabinet через сессию

```mermaid
flowchart LR
  login["POST /login"] --> authenticator["LoginFormAuthenticator"]
  authenticator --> provider["User provider by email"]
  provider --> user[(User)]
  authenticator --> session["Session cookies"]
  session --> protected["ROLE_USER pages"]
  logout["GET /logout"] --> clear["Удаление cookies"]
```

## Документация VitePress

```mermaid
flowchart LR
  makeDocs[make docs]
  compose[docker-compose.docs.yml]
  node[node:24-alpine]
  npm[npm install]
  vitepress[VitePress dev server]
  browser[http://localhost:5173]

  makeDocs --> compose
  compose --> node
  node --> npm
  npm --> vitepress
  vitepress --> browser
```
