Skip to content

Architecture ​

High Level Architecture ​

LazyTeams follows a Clean Architecture design with SRP enforcement. Packages are isolated and interact via dependency injection. The UI layer uses Elm Architecture (Model-Update-View) via Bubble Tea, while browser-assisted authentication is isolated in a companion binary (lazyteams-auth).

Package Structure ​

lazyteams/
├── main.go                          # Entry point, CLI auth overrides & transparent restart
├── cmd/
│   └── auth-helper/                 # Companion authentication binary (lazyteams-auth)
│       ├── main.go                  # CLI flags, batch orchestration & Playwright opt-in flow
│       ├── engine_config.go         # Precedence (CLI > env > prefs > default), browser discovery, JWT identity
│       ├── chromedp_engine.go       # Default chromedp (CDP) capture, OOPIF EDU & Graph renewal
│       ├── chromedp_session.go      # Isolated 0700 Chrome/Chromium/Edge/Brave CDP lifecycle
│       ├── edu.go                   # Assignments OOPIF EDU token capture helpers
│       ├── graph_headless.go        # Headless Graph Explorer SSO popup handling
│       ├── graph_sequence.go        # Graph diagnostic sequence instrumentation
│       ├── graph_diagnostic.go      # Structured diagnostic event reporting
│       ├── console_windows.go       # ANSI/VT + UTF-8 setup on Windows
│       └── console_other.go         # No-op console setup on Linux/macOS
└── internal/
    ├── auth/                        # Credential snapshots, event stream & JWT parsing
    │   ├── auth.go                  # Immutable CredentialSet, Generation, LoadCredentialSet(), SaveTokens()
    │   └── events.go                # JSONL streaming events for --renew-batch
    ├── graph/                       # HTTP client for Microsoft Graph & Teams APIs
    │   ├── client.go                # Client, doReq(), cleanHTML()
    │   ├── urls.go                  # Microsoft host allowlist (token exfiltration guard)
    │   ├── teams_api.go             # Teams and channels
    │   ├── chats_api.go             # Chats, auto-discovery self-chat
    │   ├── messages_api.go          # Read/write messages (ChatSvc)
    │   ├── files_api.go             # Drive browser, remote items
    │   ├── upload_api.go            # Chunked file uploads
    │   ├── download_api.go          # File downloads
    │   ├── ams_api.go               # Azure Media Services (inline image pasting)
    │   ├── presence_api.go          # Get/Set/Clear presence
    │   ├── assignments_api.go       # Education Assignments
    │   ├── activity_api.go          # Notifications via ChatSvc
    │   ├── auth_check.go            # Parallel startup token health checks
    │   └── debug_api.go             # Debug endpoints
    ├── helpers/                     # Shared cross-domain helpers
    │   ├── fs.go                    # HomeDir(), ConfigDir() (LAZYTEAMS_CONFIG_DIR)
    │   ├── auth_engine.go           # Engine/browser normalization & pairing validation
    │   ├── auth_process.go          # Owned process group runner for lazyteams-auth
    │   ├── auth_process_unix.go     # POSIX process-group isolation & cleanup
    │   ├── auth_process_windows.go  # Windows process cleanup
    │   ├── ownership.go             # Profile lock & ownership verifier (ErrProfileInUse)
    │   ├── ownership_unix.go        # POSIX ownership checks
    │   └── ownership_windows.go     # Windows ownership checks
    ├── teams/teams.go               # Attachment aggregation, file icons
    ├── version/                     # Semver (+ prerelease), GitHub updater & paired installer
    │   ├── version.go               # Version string & semver/prerelease comparison
    │   ├── update.go                # Release client, SHA-256 verification, ResolveAuthHelperPath()
    │   ├── install.go               # Paired installation orchestration & rollback
    │   ├── install_unix.go          # Atomic symlink-aware binary replacement (POSIX)
    │   ├── install_windows.go       # Windows helper installation
    │   └── install_pair_windows.go  # Detached paired replacement (Windows)
    └── ui/                          # TUI (Elm Architecture with Bubble Tea)
        ├── components/              # Reusable sub-components (directorypicker)
        ├── auth_status.go           # Non-secret local Silent renewal & Credentials evaluators
        ├── clipboard.go             # Native OS clipboard image extraction
        ├── commands.go              # tea.Cmd constructors & auth-helper command builder
        ├── format.go                # Message formatting logic
        ├── helpers.go               # Pure utility functions
        ├── help.go                  # Cheat sheet renderer
        ├── model.go                 # Application state & Ctrl+L menu definition
        ├── prefs.go                 # Persistent prefs.json & effectiveAuthEngine()
        ├── renewal.go               # Shared renewalOwner & 5-minute lead-time scheduler
        ├── styles.go                # Lipgloss styles
        ├── symbols.go               # UI unicode symbols and icons
        ├── types.go                 # Shared type definitions
        ├── update.go                # Main state machine & renewal lifecycle
        ├── update_data.go           # Network/API response handling
        ├── update_insert.go         # Textarea input logic
        ├── update_keys.go           # Keybinding routing
        ├── update_popups.go         # Floating windows (including Ctrl+L Authentication menu)
        └── view.go                  # Rendering logic (layouts, status banners, popups)

Design Principles ​

Clean Architecture ​

The ui package never makes HTTP calls directly. All network requests pass through graph and teams via tea.Cmd (async commands), and all browser automation runs out-of-process inside lazyteams-auth.

Elm Architecture (Model-Update-View) ​

Every UI component follows the Elm pattern:

  1. Model: Holds the entire application state (including immutable credential generation state and Ctrl+L menu state)
  2. Update: Pure state transitions that handle keyboard, API, timer, and JSONL helper events and return new state + commands
  3. View: Pure function rendering panels, status banners, and popups

4 Workspaces ​

The application is organized into 4 workspaces, each with a left panel (list) and right panel (detail):

Auth Helper — Dual-Engine Architecture ​

lazyteams-auth is resolved strictly next to the running lazyteams executable (version.ResolveAuthHelperPath) so both binaries always come from the same installation and version.

1. Default Engine: chromedp (Direct CDP in Go) ​

  • Talks directly to an already-installed Chromium-family browser (Chrome, Chromium, Edge, or Brave >= 120) via Chrome DevTools Protocol using github.com/chromedp/chromedp — zero Node.js driver process and no hidden browser download.
  • Creates a dedicated 0700 profile directory at <config-dir>/sessions/chromedp-<browser>/, pinned to its canonical executable path via <config-dir>/sessions/chromedp-<browser>.meta.json (0600) and guarded by a single-owner lock file (.lock).
  • Intercepts network requests across top-level frames, workers, and out-of-process iframes (OOPIF, used by Education Assignments) to capture Teams Web, Notifications, Spaces, EDU, and Graph tokens.
  • Uses headless mode (--headless=new) for automatic and manual silent renewals when a session exists, and visible mode (--show) for initial sign-in or interactive recovery from Ctrl+L.

2. Opt-in Engine: Playwright (Firefox) ​

  • Retained as an explicit opt-in fallback (--engine playwright, LAZYTEAMS_AUTH_ENGINE=playwright, or Ctrl+L → Use Playwright engine (opt-in)).
  • Uses an independent profile directory (<config-dir>/browser-session/, 0700) and lock (browser-session.lock), plus dynamic driver patching (patchDriverBundle) to guard against short-lived iframe frame errors.

3. Shared Renewal, Validation & Fallback Guarantees ​

  • Strict precedence: CLI flags > Environment variables > prefs.json > Default (chromedp / auto). Invalid engine/browser pairings are rejected up front without implicit cross-engine fallback.
  • JSONL batch protocol (--renew-batch): The TUI launches lazyteams-auth inside an owned process group (renewalOwner) and streams structured JSONL events (TokenCapturedEvent, TokenRenewedEvent, interaction_required, BatchCompletedEvent). On TUI exit, the process group is cleanly terminated.
  • Headless-first with clean interaction_required fallback: If Microsoft requires MFA, Conditional Access, password login, or account disambiguation during a headless attempt, the helper stops cleanly and emits interaction_required so the TUI can prompt Ctrl+L without looping or hanging.
  • Identity binding & Stage 7B Fabric guard: Before writing Graph credentials, the helper verifies (oid, tid) agreement with the active Teams session. TEAMS_FABRIC_TOKEN remains disabled (Stage 7B closed) and is never captured or persisted.
  • Local non-secret readiness check (auth_status.go): Silent renewal status in the Ctrl+L popup inspects only directory/metadata/cookie-store presence on disk — it never reads secret contents, never launches a browser, and never makes network requests.

For empirical latency, memory (Peak PSS), disk footprint, and causal attribution comparisons between playwright-firefox, playwright-chrome, and chromedp-chrome, see Authentication Engine Benchmarks.

Self-Updater & Process Restart ​

The self-updater operates as an atomic paired subsystem:

  1. Paired Release Resolution: checks GitHub Releases for both lazyteams and lazyteams-auth, falling back to gh api if anonymous requests hit rate limits. Strips prerelease suffixes during semver comparison so development builds ahead of older releases (e.g. v0.2.0-dev > v0.1.6 and < v0.2.1) do not suggest downgrades.
  2. Pre-Replacement Verification: downloads both binaries, verifies their SHA-256 against SHA256SUMS, checks embedded build tags, and resolves symlinks.
  3. Safe Paired Installation with Rollback: replaces both binaries atomically; if lazyteams-auth installation fails, the original lazyteams binary is restored from backup.
  4. Transparent Process Restart: on Unix, main.go invokes syscall.Exec to replace the running process without dropping terminal state; on Windows, a detached helper completes the swap and relaunches the TUI.

Key Protocol Notes ​

  • Teams v2 uses substrate.office.com as a Graph proxy rather than making direct browser calls to graph.microsoft.com.
  • The JWT aud claim for Microsoft Graph is the GUID 00000003-0000-0000-c000-000000000000.
  • TEAMS_NOTIF_TOKEN and TEAMS_WEB_TOKEN share the same ChatSvc token audience.
  • MSAL keeps refresh tokens in JavaScript memory rather than IndexedDB, which is why silent renewals rely on re-using the authenticated browser SSO profile.