Building Authentication for Plughub: The decisions Behind the code
===
I've been spending some time thinking about authentication lately, and honestly, it's one of those engineering problems that becomes more interesting the deeper you get into it.
I'm currently building Plughub, a developer infrastructure ecosystem aimed at making common backend capabilities easier to integrate into applications.
The idea is straightforward: developers shouldn't have to repeatedly build the same infrastructure from scratch whenever they start a new project.
Things like email delivery, file storage, authentication and other backend capabilities should be reusable, composable and easy to integrate into existing applications.
But there's something I've become increasingly conscious of while building this project.
Making something reusable doesn't automatically make it well-designed.
Starting with Email and Storage
Email and Storage were among the first capabilities I worked on.
They helped establish an important direction for Plughub: provide functionality through packages that developers can install and use directly.
No mandatory framework. No requirement to restructure an existing application. No Plughub-controlled infrastructure that developers must depend on.
The developer installs the package, configures it and remains in control of how it fits into their application.
Backkit, our CLI integration tool, is intended to make that process more convenient. But it shouldn't be a requirement for using Plughub.
The package should work independently.
That distinction matters.
Then came Authentication
Authentication introduced a different level of complexity.
Unlike sending an email or uploading a file, authentication deals with persistent identity and security-sensitive state.
We're talking about users, credentials, OAuth identities, sessions, verification, password resets, account linking and eventually other authentication methods.
And these aren't isolated features.
For example, what happens when someone signs in using Google today and later attempts to sign in using email and password?
Should the system automatically associate both identities because they share an email address?
What happens when a session expires? How should it be revoked? What happens when multiple devices are involved?
These are not merely API design questions. They affect the security and integrity of the entire application.
It became clear that I couldn't approach Auth in exactly the same way I approached Email or Storage.
Should we build the engine ourselves?
This is where things got interesting.
One option was to build the authentication engine ourselves.
That would give us considerable control over the implementation, data model and public API.
But authentication isn't an area where I want to reinvent things simply because I can.
There are years of security research, implementation experience and edge cases behind mature authentication systems. Building and maintaining all of that ourselves would introduce a significant responsibility.
Then there's Better Auth.
Better Auth is an established TypeScript authentication framework with support for features such as email/password authentication, OAuth, sessions, database integration and plugins.
It presents an interesting possibility: could we use an established authentication engine internally while Plughub provides its own developer experience and integration contracts?
But that introduces another question.
If we're building Plughub Auth around Better Auth, what exactly are we contributing?
I don't want to build a thin wrapper that simply renames another project's APIs and calls it an ecosystem.
I also don't want to create unnecessary abstractions that make a developer's experience more complicated than using the original tool.
There's a difference between reusing an established implementation and building a meaningful product around it.
That's a distinction I'm still evaluating.
The architecture matters as much as the implementation
One thing I don't want Plughub to become is another framework that dictates how developers should structure their applications.
Imagine someone already has a Fastify application, a PostgreSQL database and Drizzle ORM.
Why should adopting Plughub Auth require them to restructure their project, introduce a prescribed directory layout or move their application logic into generated files?
It shouldn't.
I'm thinking about the problem in separate layers:
- Runtime: the actual authentication functionality developers install and execute.
- Configuration: where developers define their authentication settings, in whatever location makes sense for their application.
- Integration: how the capability connects to an HTTP framework or application.
- Persistence: how database schemas, migrations and adapters are handled while keeping the developer in control of their data.
- Backkit: an optional tool for reducing integration work.
These concerns shouldn't be unnecessarily coupled.
A developer should be able to install and configure Plughub Auth without ever using Backkit.
Likewise, using Backkit shouldn't mean copying the authentication engine into the developer's project.
The package should remain the source of functionality. Generated code, where useful, should only provide integration convenience.
A bigger question about developer tooling
This process has made me think more deeply about what good developer tooling should actually accomplish.
Convenience is important, but convenience shouldn't come at the cost of control.
Abstractions are useful, but an abstraction that hides important behaviour or makes migration difficult can become another problem.
And supporting multiple frameworks doesn't necessarily mean creating a separate implementation for every framework.
Sometimes the better approach is to establish a stable integration contract and let framework-specific bridges handle the differences.
I'm still working through these decisions, and I haven't settled on whether Better Auth should become the internal engine for Plughub Auth.
But I think that's part of engineering.
Not every architectural decision should be made simply to keep development moving. Sometimes it's worth slowing down to understand what you're actually building.
For me, Plughub isn't just about providing reusable backend packages.
It's about finding a way to make backend development less repetitive while preserving the freedom developers already have.
And authentication is proving to be a good test of that philosophy.
I'd genuinely like to hear from developers who have built authentication infrastructure or integrated solutions like Better Auth into their projects.
Would you rather build your own authentication engine, compose established tools behind your own contracts, or use an existing solution directly?
I'm interested in the reasoning behind the choice.
0 comments
Back to readingLog in to join the conversation.
No comments yet. Be the first.