ARCHTECH (@archtechx) header
ARCHTECH (@archtechx) profile picture

Meticulously architected web applications. @TenancyLaravel v4 launching soon!

United States
Joined April 2021
The final step in generating each boilerplate setup is running tests (multiple variations, including regular tests, in-memory SQLite, and parallel tests) and if they all pass, create a zip file that users can download. If tests don't pass, the program reports which test run failed and how
1
2
140
Speaking of helpers, can't forget dd() 😁 If you're at least a bit familiar with Rust, you'll notice we use unwrap() a lot. This is intentional — there are basically no recoverable errors in our code, so they should all panic and report exactly where they happened
1
3
103
Most of the Rust code looks like this Functions that either modify files or copy stubs, and helpers that are called by those functions
1
2
128
This means the only things we need to maintain *separately* are views Separate views for Inertia and Blade/Livewire setups, also depending on the starter kit being used since they use different components and layouts
1
2
103
The methods shown above are used in controller *templates* like this one We keep route names consistent across setups, so the only things that need to change are usually view names (Blade vs Inertia) or parameters based on what the view might need
1
2
113
The first thing is having descriptive types for anything our code may want to know about the setup being generated Based on those types, functions adjust their behavior to the currently used frontend stack, database setup, identification method, or starter kit used
1
2
158
🦀 The neat thing is how we've implemented this. Maintaining 24 repos would be impossible, so instead we have a custom tool written in Rust for generating these setups Each generated setup has a clean git history and is automatically tested after being built Here's how we keep this maintainable 👇
🤯 Tenancy v4 will launch with 24 different SaaS boilerplate setups That is any combination of: - Jetstream with teams, Jetstream without teams, new Laravel 12 starter kits - Domain identification / Path identification - Livewire / Inertia + Vue - Multi-database / PostgreSQL RLS (new v4 feature!)
2
4
1
23
2,550
True! Over the years of working on Tenancy for Laravel, one of the biggest sources of pain was the queue logic. Difficult to test with just testbench, fixing bug A introduces bug B or some kind of regression, ... Spent a few days on writing a full *app-based* testing suite
There's nothing better than having a full testing workflow. There's nothing worse than setting up a full testing workflow.
1
1
14
2,712
Hence the `$_ =`. You only need to keep a reference to the PDO instance somewhere. The lifetime of the DB will match the lifetime of its longest reference. So you can do something like this to keep it alive until the end of the script Now, what's an actual use case for this?
1
315
The current behavior is that foo() prints "foo", while bar() prints "foo" *AND* "bar". Both functions connect to the same database If I uncomment the second `$dsn = ...`, I get "foo" from foo() and "bar" from bar(). Meaning, each function gets a SEPARATE database
1
363
With :memory:, you can have multiple separate databases, but you need to pass the specific PDO instance around With named in-memory databases, you can connect to *the same database* from another location in code as long as the connection string is the same See this code:
1
5
451
⚡️ Did you know SQLite can have *named* in-memory databases? We've submitted a PR to Laravel and the latest version now supports them! Here's why they're so cool and fundamentally different from :memory:
1
14
3
81
11,196
Thanks to @aarondfrancis's WAL mode evangelism, SQLite databases created by Tenancy v4 now use the WAL journal mode by default, significantly improving performance Turns out SQLite can be very fast and a great fit for many multi-tenant applications!
1
2
33
5,396
FFI lets us call into C code, it's generally used something like this: FFI::cdef('function declarations', '/path/to/library.dll'); However, since we're using a system function provided by libc (basically the standard library), we don't need to link any .dll/.so/.dylib
1
1
109
...a CLI utility for that as there are fewer moving parts Now for the FFI code itself. It's basically the following C code translated into PHP:
1
1
157
So we make sure to take this into account. Now, we could write code like this and it'd work pretty much exactly like the sysctlGetLogicalCoreCount() in the original tweet So what's the benefit of writing all that verbose code?
1
1
107
Instead, we need to use the sysctl utility:
1
1
169
Here's what the code looks like, with a detailed explanation of how it works: teapawt.org/archtechx/status/18403…
The Tenancy v4 codebase now uses FFI 🫣
1
1
1
9
4,860