How steveiliop56/tinyauth works
Project Type and Purpose
• Tinyauth is a full-stack authentication middleware: a Go-based service (backend + CLI) that serves a React/Vite frontend.
• It sits in front of your Docker-deployed apps (via Traefik, Nginx, Caddy) and provides login screens, basic auth, TOTP, and OAuth (Google, GitHub, generic).
File Structure Analysis
• Top-level “cmd/” holds CLI entry points (toten generation, user creation/verification and root.go wiring).
• main.go bootstraps the HTTP server, mounts API routes and serves embedded frontend assets.
• internal/ contains modular packages:
• api: HTTP routing, request/response types
• handlers: request handlers for login, TOTP, OAuth callbacks
• auth: session/token management
• oauth & providers: OAuth flows for Google/GitHub/generic
• hooks, utils, constants, types, assets (embedded React build)
• frontend/ is a standalone React/Vite app: pages, UI components, contexts (user/app), i18n, schemas for form validation, build config.
• Devops: Dockerfiles (service & frontend), docker-compose.yml examples, CI workflows, .env template.
README Insights
• Emphasizes Docker-first deployment, works with popular proxies.
• Demo uses Traefik + whoami + tinyauth.
• No external database; config and user store likely file-based or in-memory (managed via CLI).
Key Components
a. Main Components
• External Client (Browser)
• Edge Proxy (Traefik/Nginx/Caddy)
• Tinyauth Service (Go HTTP server)
• Authentication API (login, logout, TOTP, OAuth)
• Session Store (in-memory or file)
• Embedded Frontend (React)
• OAuth Providers (Google, GitHub, Generic)
• Protected Upstream Services (e.g., whoami, your app)
• CLI Tools (user management, totp generation) – optional, for operators
b. Interactions
• 1. Browser → Edge Proxy → Tinyauth (serves React UI or API)
• 2. Tinyauth ↔ OAuth providers (token exchange, user info)
• 3. Browser ← Tinyauth (session cookie)
• 4. Edge Proxy (post-auth) → Protected Service → Browser
• 5. Operator CLI → Tinyauth config/store (via file or API)
c. Architectural Patterns
• Monolithic service with clear layers: HTTP API, business logic (auth, OAuth), and static asset serving.
• CLI as separate commands under cmd/.
• Modular Go packages under internal/ (separation of concerns).
• Frontend: Component-driven UI with context providers and schema-based validation.
d. Technologies & Libraries
• Go modules, Gin/chi (or custom router) in internal/api
• React + Vite + TypeScript + Sonner (toast) + Zod (schemas) + i18n
• Docker, Docker-Compose, Traefik/Nginx integration
Detailed Capture of Architectural Elements
• How the embedded frontend/dist is served by Go’s asset handler (internal/assets).
• API endpoints under the Go service (e.g., /login, /oauth/callback, /totp, /verify).
• Session flow: cookie issued → Proxy reads cookie → grants/denies forwarding to upstream.