Project Structure
Last Updated: 2026-10-29
The dracory/auth library is organized into focused packages for clarity and maintainability.
Directory Layout
dracory/auth/
├── types/ # Public: configs, interfaces, Method, PostAuthHooks
├── utils/ # Utility functions (internal use)
├── internal/ # Internal implementation (not public API)
│ ├── api/ # JSON endpoint handlers (one dir per endpoint)
│ ├── core/ # Shared post-auth pipeline
│ ├── emails/ # Default email templates
│ ├── helpers/ # Internal helpers
│ ├── links/ # Route path helpers
│ ├── middlewares/ # Internal middleware (CSRF, rate limit)
│ ├── rules/ # Reusable rule checks (throttles, validation, registration policy)
│ ├── testutils/ # Shared test fixtures
│ └── ui/ # Server-rendered pages (one dir per page)
├── examples/ # Runnable example apps
│ ├── passwordless/
│ ├── usernamepassword/
│ └── authknight/
├── docs/ # Documentation (markdown → generated HTML site)
│ ├── peers/ # Feature comparisons vs peer solutions
│ ├── proposals/ # Design proposals
│ └── tasks/ # Implementation tasks (pending/done)
└── *.go # Public API: constructors, method adapters, middleware
types/ — Public API
auth_interfaces.go—AuthSharedInterface,AuthOtpInterface,AuthPasswordInterface,AuthAuthKnightInterfaceconfig_shared.go—ConfigShared(endpoint, cookies, callbacks, rate limiting) embedded by all configsconfig_passwordless.go/config_username_and_password.go/config_authknight.go— per-method configsmethod.go—Methodinterface +RouteProvider(multi-method composition)post_auth.go—PostAuthHooks+SessionInterfacesession.go,cookie_config.go,observability.go,user_auth_options.go,messages.go,constants.go,password.go
internal/api/ — Endpoint handlers
api_login · api_login_code_verify · api_magic_link_send · api_magic_link_callback · api_register · api_register_code_verify · api_logout · api_password_restore · api_password_reset · api_authenticate_via_username · api_authknight_callback · api_impersonate_start · api_impersonate_stop
Each subdirectory holds the handler, a Dependencies struct (or …WithAuth wrapper taking the public interface), and tests.
internal/ui/ — Page handlers
page_login · page_magic_link · page_login_code_verify · page_register · page_register_code_verify · page_logout · page_password_restore · page_password_reset · shared (page scaffold, RedirectAuthKnightIfActive)
Pages are built with github.com/dracory/hb, styled with Bootstrap, and take the auth interface so FuncLayout and page hooks apply consistently.
internal/ support packages
core/—PostAuth: the shared post-authentication pipeline all methods funnel through when hooks are configuredrules/— reusable checks (per-email send throttle, validation, registration policy:ProfileCompletionRule,RegisterFirstRule,VerifiedEmailKeyRule)links/— endpoint path helpersemails/— default plain email bodiesmiddlewares/,helpers/,testutils/
Root package
new_passwordless_auth.go,new_username_and_password_auth.go,new_authknight_auth.go— constructors (validate config, wire defaults)multi_method.go—MultiMethodAuth,NewMultiMethodAuth, and the built-intypes.Methodadapters (otpMethod,magicLinkMethod,passwordMethod,authKnightMethod)auth_implementation*.go— the implementation struct: getters/setters, API/page delegation, cookies- Middleware + cookie helpers (
AuthCookieSet,CookieName, …)
Design Principles
- Separation of concerns — types, rules, API handlers, UI handlers, and the post-auth pipeline are distinct packages
- Internal encapsulation —
internal/is not importable; public surface is root package +types/ - Thin facade — the root package delegates to internal packages
- Composable methods —
types.Method+RouteProviderlet methods ship pages, ajax, callbacks, and extra routes without core changes - Optional hooks via type assertion — new capabilities (session store, post-auth hooks, temp-key delete) attach through optional interfaces so existing
AuthSharedInterfaceimplementers don't break - Testability — tests live next to each component
Public vs Internal
Safe to import: github.com/dracory/auth, github.com/dracory/auth/types Do not import: github.com/dracory/auth/internal/*, github.com/dracory/auth/utils