I'd opened the code to fix a collision, and found something else entirely.
The login part, the piece that feeds an ID and password into an internal system and comes back with a logged-in session, was sitting inside every single automation. The same code doing the same job, copied one by one into more than a dozen files. The login the AI wrote for my first automation, I'd pasted whole into the next one, and the next, and the next. A copy of a copy of a copy.
Why was obvious. Each time I built a new automation, rethinking login from scratch was a nuisance. One already worked, so scraping and pasting it at least got me logged in. It looked like the fastest path. For the moment, it was.
But the cost was now in front of me. To change the login method even slightly, I had to fix a dozen-plus files identically. Miss one, and that one kept running the old way and quietly tripped on its own. Which actually happened: when the login procedure shifted a little, I fixed most of the automations and forgot one buried in a corner. The deflation of finding, days later, that one lone automation silently returning empty results. Same code, some fixed, some not, a dozen pieces scattered across a dozen different states.
Flipping file to file, comparing login blocks by eye, I laughed out loud. One file's login was the original version I'd first received; another was a once-patched version; another a clumsy mix of the two. The same job, all wearing different faces. Each time I pasted, I hadn't even registered that it was "the same thing." I'd just scraped what worked. And those scrapes had stacked into a dozen logins, each drifted slightly from the others. What stung most was the diligence of it: a mistake I could have made once, I'd faithfully repeated ten times over.
I Was Building a House Upside Down
Half-complaining to the AI about why login was scattered in ten places, an image surfaced in my head. I was building a house upside down.
A house normally goes bottom-up: pack the ground, raise the columns, lay the roof on top. I was doing the reverse. I'd put up the roof I needed right now, each visible lookup, and hastily propped a column under each roof. Ten roofs, ten separate columns. Those columns had nothing to do with each other. So the moment the ground shook even a little, meaning the login method changed just once, I had to repair ten columns one at a time. There was no single floor laid underneath them all.
The fix was clear. The login code scattered across a dozen spots had to be gathered into one place and laid down as a floor. Login lives in exactly one place, and every automation shares that one place. In house terms: pull out the columns propped up all over, and lay a single foundation underneath.
Again, I couldn't write the code. All I did was draw the picture. I want login gathered into one place; I want every automation to get its session from that one place. I said the direction, and the AI translated it as "separate it into a shared module." A word I'd never heard. I asked what a module was, and it said: a chunk of code set aside on its own, that other code can "call and use." The instant I heard it, I thought, ah, that's the floor I was picturing.
// auth.js — the one place login lives now.
async function getSession() {
// Reuse the current login if it is still valid; log in again only if needed.
if (isSessionValid()) return currentSession();
return await login(process.env.APP_USER, process.env.APP_PASSWORD);
}
// Each lookup no longer carries its own login. It just borrows the shared one.
async function lookupUsage(customer) {
const session = await getSession(); // the shared foundation, not a copy
return fetchUsage(session, customer);
}
Don't worry if the code doesn't land for you. The point isn't the code, it's the shape: where each lookup used to carry a whole login inside it, now it just calls, in one line, "lend me the one underneath." The login floor is singular now, and every lookup stands on it. Here too I drew the picture; the AI turned it into working code.
Honestly, the work was unnerving. These were things already running fine. The roof was up, people living under it, and I was shoving a new column in underneath. One wrong touch and everything working might stop at once. Each time I stripped login from a file and swapped in that one line, I held my breath and ran it. It runs. Next file. Runs again. Next. My fingertips trembled a little, swapping the underside one at a time. Sliding a hand under a house already standing is far more delicate than laying a floor on empty ground. But when I confirmed not one had collapsed, all still in place, the held breath burst out at once. One confirmation was enough to turn dread into relief.
After the change, a startling amount got simpler. When the login method shifted again, I fixed that one file, auth.js, and that was it. No more wandering a dozen files, no more one-missed-and-it-trips. Pack the floor once, and whatever you put on top, you never touch the floor again. And a bonus: with login gathered into one place, the lock from before, the thing that let only one log in at a time, only needed to be set there, in that one place. The scattered complexity above resolved itself once the base was tidy.
Ashamed to Have Built It Backwards, But
At first all of this embarrassed me. Someone who actually knew would have laid the floor from the start. Keeping login in one shared place is basic, I was told, the most basic of basics. And I hadn't known, so I'd put up the roof first, propped ten separate columns, and only after it collapsed went back to slide in columns and lay a floor. The order was completely backwards. This was a house built upside down.
But after laying the floor, my thinking shifted a little. Could I have laid the floor from the start? No. Back then I didn't even know why a floor was needed. Why scattering login across ten places was a problem, I couldn't know before living it. Only after fixing the same code in ten spots and tripping over the one I missed did I learn, in my body, ah, this is supposed to live in one place. Because the scattered version burned me, I came to understand bone-deep why gathering matters.
My first thought after finishing the floor was "I should have done this sooner", and I immediately took it back. There was no sooner. To do it sooner, I'd have had to know sooner, and I didn't. "Belatedly" always drags "if only I'd known then" behind it, but looking back, the me of that time stood in a place where, no matter how hard I tried, I couldn't have known. Lateness wasn't proof of my laziness; it was simply the hour my learning arrived. Looking down at the late-laid floor, I decided to forgive the lateness a little.
So I built it backwards not because I was stupid, but because there was no other road. For a non-developer, "foundation first" isn't even on the menu, you don't know what a foundation is. You raise the roof first, you watch it shake and fall, and only then do you see what belongs underneath. The order wasn't backwards; it was the only order a non-developer can build in. First you get burned, then you know.
If you're ashamed that you seem to be building something backwards right now, I want to tell you it's all right. Build it backwards, and someday it collapses, and when it collapses you lay the floor. Someone who never built has no floor to lay at all. A house built upside down is still a house. You just have to accept that, once, it will fall.
And once the floor was down, a strange change set in. Until then, each new automation felt like writing everything from login to lookup over from scratch. Now, with a floor, building something new got much lighter: login is underneath, so I just "call it," and I only have to think about the new lookup itself. Like setting one more column on an existing base. The house grew sturdy, and I wanted to put more on top, a wanting that would pull me out of the terminal entirely. But that's the next story.
This essay is adapted from one of my Korean e-books on automating my own enterprise work as a non-developer. Details are anonymized: no company, system, or tool names, only the shape of what happened.
Related reading: When Two Automations Both Did the Right Thing and Broke Each Other · I Was Keeping Passwords in My Code: A Non-Developer's First Taste of Technical Debt
Comments
Post a Comment