Files
sleep-guard/docs/architecture.md
Vadim Sobinin 852e01df39 feat: initial SleepGuard implementation
Wake-on-demand proxy + agent system with SvelteKit dashboard.
Monorepo: shared types, proxy (Hono + http-proxy), agent (monitors + locks), web (SvelteKit SPA).

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-10 13:46:51 +03:00

52 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SleepGuard Architecture
## Обзор
Wake-on-demand система из двух компонентов:
- **Proxy** (n150, 192.168.50.199) — reverse proxy + state machine + dashboard
- **Agent** (PC, 192.168.1.50) — мониторинг нагрузки + lock manager
## State Machine
```
REQUEST_RECEIVED
OFFLINE ─────────────────────► WAKING
▲ │
│ SHUTDOWN_COMPLETE │ HEALTH_CHECK_PASSED
│ ▼
SHUTTING_DOWN ◄──── IDLE_CHECK ◄── ONLINE
AGENT_IDLE IDLE_TIMEOUT ▲
│ │
│ AGENT_BUSY / REQUEST
└────────┘
```
- `OFFLINE` → запрос → wake через UpSnap → `WAKING`
- `WAKING` → health check passed → `ONLINE`
- `ONLINE` → idle timeout → `IDLE_CHECK`
- `IDLE_CHECK` → agent busy → `ONLINE`, agent idle → `SHUTTING_DOWN`
- `SHUTTING_DOWN` → agent offline → `OFFLINE`
## Shutdown Policy (Agent)
Три уровня проверки (все должны быть пройдены):
1. **Locks** — если есть активные локи, выключение блокируется
2. **Processes** — hashcat, ffmpeg, whisper, python3, ollama
3. **Metrics** — CPU >15%, GPU >10%, RAM >50%, Disk I/O active
## Проксирование
Proxy матчит сервисы по `Host` заголовку. Если PC online — http-proxy проксирует запрос. Если offline — показывает "Waking up" страницу с автополлом.
## Деплой
Два приложения в Dokploy из одного git repo:
- `sleepguard-proxy`: Dockerfile `packages/proxy/Dockerfile`, build context `.`
- `sleepguard-agent`: Dockerfile `packages/agent/Dockerfile`, build context `.`
Agent деплоится на PC как remote server в Dokploy с NVIDIA GPU passthrough.
## Env переменные
См. `.env.example` в корне репозитория.