App Logo
Introduction

Architecture

Clean Architecture and design principles

Authula follows Clean Architecture principles with built-in HTTP handlers:

┌─────────────────────────────────────────────────────────────┐
│ Authula Library                                             │
├─────────────────────────────────────────────────────────────┤
│ Standalone HTTP Handlers                                    │
│ • Built-in http.Handler implementation                      │
│ • auth.Handler() returns ready-to-use handler               │
│ • Mount on any standard Mux HTTP server                     │
│ • Uses Chi router under the hood                            │
│─────────────────────────────────────────────────────────────│
│ Database Adapters                                           │
├─────────────────────────────────────────────────────────────┤
│ • SQLite                                                    │
│ • PostgreSQL                                                │
│ • MySQL                                                     │
└─────────────────────────────────────────────────────────────┘

Key Design Principles

  1. Framework-Agnostic Core: Clean separation between business logic and HTTP concerns
  2. Standard Library First: Handlers implement net/http.Handler interface

Component Layers

Models Layer

  • Entities: User, Account, Session, Verification and more

Handler Layer

  • Entrypoint for API endpoints, delegates logic to either use cases in some scenarios which call one or multiple services. Or if the handler only has a dependency on one service then it delegates to that single service without the need for a use case. Services handle business logic and delegate data access to repositories providing clear separation of concerns.
  • Integrated with hooks for extensibility

Use Cases Layer

  • Use cases (interfaces), services (interfaces with concrete implementations for business logic), repositories (handle database access).

Database Layer

  • Bun ORM for database interactions with support for multiple databases

Extensibility

  • Various hooks into the authentication flow for customisation
  • Plugin system for custom logic and extensions
  • Event Bus for event-driven architecture

On this page