# TUI Session Manager Plan

## Overview
Server-side session manager for terminal clients (CLI + TUI).
Holds live SSE connections, delivers real-time events.

## Stack
- http-kit (HTTP server + SSE)
- reitit (routing) + Ring middleware
- NATS (via shared/) for event pub/sub — no direct PG connection
- Reads data from API (internal HTTP calls)

## Responsibilities
- Manage live SSE connections for terminal clients
- Subscribe to NATS for real-time events (messages, presence, typing)
- Publish ephemeral events (typing indicators) to NATS — no API round-trip
- Fetch full data from API when notification contains only IDs
- Sits behind auth gateway (all requests pre-authenticated)

## TODO
- [ ] http-kit server setup with SSE
- [ ] Connection tracking (atom of connected SSE clients)
- [ ] HTTP POST endpoints for client→server signals (typing indicators)
- [ ] NATS subscription for chat events
- [ ] NATS publish for typing indicators
- [x] Internal API client for data fetches — `ajet.chat.shared.api-client` in shared/
- [ ] Event filtering: deliver only relevant events per client
- [ ] Presence batching: buffer heartbeat events, flush 1x/min
