# rlnorthcutt/go-passwordless architecture

> Architecture diagram of the GitHub repository rlnorthcutt/go-passwordless, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rlnorthcutt/go-passwordless
- Repository: https://github.com/rlnorthcutt/go-passwordless

## Overview

##### Project type and purpose
- This is a Go-language “passwordless authentication” library, not a standalone frontend/backend application.
- It provides a Manager orchestration layer, pluggable Stores for token persistence, and pluggable Transports for delivering one-time codes or links.

##### File structure
- Top-level packages and files:
- passwordless.go / onetimelogin.go / config.go – core manager logic, helpers, configuration
- store/ – token persistence interfaces and implementations (MemStore, DbStore, file, cookie, session helpers)
- transport/ – delivery interfaces and implementations (LogTransport, SMTPTransport)
- mocksmtp/ – test-only SMTP server implementation
- examples/ – sample client programs demonstrating CLI, REST API, file-based, SMTP auth
- Config & CI: .devcontainer, GitHub workflows, go.mod, tests, mocks.

##### README for additional insights
- Key flow: StartLogin → generate & store token → Transport.Send → user receives code/link → VerifyLogin → validate & delete token.
- Interfaces: Store (Create, Fetch, Delete), Transport (Send).
- External dependencies: securecookie, modernc.org/sqlite, net/smtp.

##### Detail without over-engineering
- Every Store implementation and every Transport implementation as subcomponents.
- Mocksmtp package in a “Testing” or “Dev” boundary.
- Examples/ folder as “Sample Integrations” off to one side.

- The central Manager module, its two plugin points (Store and Transport),
- All store & transport variants,
- External dependencies, and
- How a client application integrates and drives the passwordless flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Application
    ClientApp["Client Application"]:::client
    ClientApp -->|"StartLogin(ctx, identifier)"| Manager

    %% Core Orchestrator
    subgraph "Passwordless Library"
        direction TB
        Manager["Passwordless Manager"]:::core
        Config["Configuration Module"]:::core

        %% Store Layer
        subgraph "Store Layer"
            direction TB
            StoreIntf["Store Interface"]:::store
            MemStore["In-Memory Store"]:::store
            DbStore["Database Store"]:::store
            FileStore["File-based Store"]:::store
            CookieStore["Cookie-based Store"]:::store
            SessionHelpers["Session Helpers"]:::store
        end

        %% Transport Layer
        subgraph "Transport Layer"
            direction TB
            TransIntf["Transport Interface"]:::transport
            LogTrans["LogTransport"]:::transport
            SMTPTrans["SMTPTransport"]:::transport
            CustomTrans["Custom Transport"]:::transport
        end
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        DB["Relational Database"]:::external
        SMTPServer["SMTP Server"]:::external
        MockSMTP["Mock SMTP Server"]:::external
    end

    %% Sample Integrations
    subgraph "Sample Integrations"
        direction TB
        CLIExample["CLI Integration"]:::examples
        FileExample["File-based Integration"]:::examples
        RESTExample["REST API Integration"]:::examples
        SMTPExample["SMTP Integration"]:::examples
    end

    %% Core dependencies
    Manager --> Config
    Manager --> StoreIntf
    Manager --> TransIntf

    %% Store implementations bind
    StoreIntf --> MemStore
    StoreIntf --> DbStore
    StoreIntf --> FileStore
    StoreIntf --> CookieStore
    StoreIntf --> SessionHelpers
    DbStore --> DB

    %% Transport implementations bind
    TransIntf --> LogTrans
    TransIntf --> SMTPTrans
    TransIntf --> CustomTrans
    SMTPTrans --> SMTPServer
    LogTrans --> MockSMTP

    %% Flow sequence
    Manager -->|"Store.Create"| StoreIntf
    Manager -->|"Transport.Send"| TransIntf
    ClientApp -->|"VerifyLogin(ctx, tokenID, code)"| Manager
    Manager -->|"Store.Fetch/Delete"| StoreIntf

    %% Sample integrations connect
    CLIExample --> Manager
    FileExample --> Manager
    RESTExample --> Manager
    SMTPExample --> Manager

    %% Click Events
    click Manager "https://github.com/rlnorthcutt/go-passwordless/blob/main/passwordless.go"
    click Manager "https://github.com/rlnorthcutt/go-passwordless/blob/main/onetimelogin.go"
    click Config "https://github.com/rlnorthcutt/go-passwordless/blob/main/config.go"
    click StoreIntf "https://github.com/rlnorthcutt/go-passwordless/blob/main/store/store.go"
    click MemStore "https://github.com/rlnorthcutt/go-passwordless/blob/main/store/mem_store.go"
    click DbStore "https://github.com/rlnorthcutt/go-passwordless/blob/main/store/db_store.go"
    click FileStore "https://github.com/rlnorthcutt/go-passwordless/blob/main/store/session/file_store.go"
    click CookieStore "https://github.com/rlnorthcutt/go-passwordless/blob/main/store/session/cookie_store.go"
    click SessionHelpers "https://github.com/rlnorthcutt/go-passwordless/blob/main/store/session/session_helpers.go"
    click TransIntf "https://github.com/rlnorthcutt/go-passwordless/blob/main/transport/transport.go"
    click LogTrans "https://github.com/rlnorthcutt/go-passwordless/blob/main/transport/log_transport.go"
    click SMTPTrans "https://github.com/rlnorthcutt/go-passwordless/blob/main/transport/smtp_transport.go"
    click MockSMTP "https://github.com/rlnorthcutt/go-passwordless/blob/main/mocksmtp/mock_smtp.go"
    click CLIExample "https://github.com/rlnorthcutt/go-passwordless/blob/main/.examples/cli_auth/main.go"
    click FileExample "https://github.com/rlnorthcutt/go-passwordless/blob/main/.examples/file_auth/main.go"
    click RESTExample "https://github.com/rlnorthcutt/go-passwordless/blob/main/.examples/rest_api/main.go"
    click SMTPExample "https://github.com/rlnorthcutt/go-passwordless/blob/main/.examples/smpt_auth/main.go"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef store fill:#E6FFEA,stroke:#2c662d,color:#2c662d;
    classDef transport fill:#FFF4E6,stroke:#d97706,color:#d97706;
    classDef external fill:#F0F0F0,stroke:#666666,color:#333333;
    classDef client fill:#F5F5FF,stroke:#5a5aff,color:#1f1fff;
    classDef examples fill:#F8E6FF,stroke:#8e2bf3,color:#5e00e6;
```
