@startuml Crowd Analyzer Architecture title Архитектура Crowd Analyzer package "External Systems" { [Redis Queue] as redis [Storage Service] as storage [Tevian API] as tevian_api [Camera Server] as camera_server } package "Crowd Analyzer" { [analyze_crowd()] as entry_point [_analyze_crowd()] as main_logic [_run_detectors()] as detector_runner [_get_triggered_zones()] as trigger_logic [_build_zones_info()] as zones_builder } package "Detectors" { [TevianHeadsDetector] as tevian_detector } package "Data Access" { [frames.pull()] as frame_puller [central.send()] as central_sender [services_db] as services_db [zones_db] as zones_db } package "Storage" { [MongoDB Local] as mongo_local [MongoDB Crowd] as mongo_crowd } ' External connections redis --> entry_point : tasks camera_server <-- frame_puller : get frames tevian_api <-- tevian_detector : AI requests storage <-- main_logic : upload images ' Internal flow entry_point --> main_logic main_logic --> detector_runner main_logic --> zones_builder main_logic --> trigger_logic detector_runner --> tevian_detector ' Data access frame_puller --> camera_server central_sender --> redis : results services_db --> mongo_local zones_db --> mongo_local ' Key relationships main_logic --> frame_puller : get frames main_logic --> central_sender : send results main_logic --> zones_db : update status detector_runner --> services_db : check config tevian_detector --> tevian_api : detect heads note right of entry_point Entry point: - Semaphore control - Error handling - Metrics tracking end note note right of main_logic Main logic: - Frame processing - Zone analysis - Result storage - Notification sending end note note right of detector_runner Detector runner: - AI service calls - Error handling - Performance tracking end note @enduml Диаграмма состояний зоны: @startuml Zone State Diagram title Состояния зоны в процессе анализа [*] --> Inactive : zone created state Inactive { Inactive : length_by_ai = 0 Inactive : no triggers } state Active { Active : length_by_ai > 0 Active : analyzing people count } state Triggered { Triggered : trigger condition met Triggered : schedule active Triggered : not in grace period } state GracePeriod { GracePeriod : trigger condition met GracePeriod : but in grace period GracePeriod : suppressing notifications } Inactive --> Active : people detected Active --> Inactive : no people detected Active --> Triggered : trigger_at threshold reached\nAND schedule active\nAND not in grace period Active --> GracePeriod : trigger_at threshold reached\nBUT in grace period Triggered --> Active : trigger condition not met GracePeriod --> Triggered : grace period expired\nAND trigger still met GracePeriod --> Active : trigger condition not met note right of Triggered Actions: - Zone highlighted on image - Notification sent - Grace period started end note note right of GracePeriod Grace period prevents spam notifications for zones that constantly trigger end note @enduml