What Broke, What Held: Three Bugs That Never Crashed My Farm App
I built ProFarm, a farm management app with a crop and soil guide, weather, market prices, and a planner for farms, crop cycles and tasks. The app started, the pages loaded and the features worked. Then I went back thro
I built ProFarm, a farm management app with a crop and soil guide, weather, market prices, and a planner for farms, crop cycles and tasks. The app started, the pages loaded and the features worked.
Then I went back through the project looking for things that were wrong without being broken, and I found three. None of them crashed anything or threw an error. Each one looked fine on screen, which is exactly why nothing ever pointed at them.
This post is about those three, how I proved each one with a test, and what I check first now.
Code: https://github.com/JayantBansal900/ProFarm-V2
Bug 1: The clock
The planner marks a task overdue when its due date is before "today". My first version got "today" from the server's clock. That is what everyone does, and it is wrong the moment your server and your users live in different timezones.
Servers usually run in UTC. The farms ProFarm is built for are in India, five and a half hours ahead. So between midnight and 05:30 in India, the server still thought it was yesterday. A task that was due yesterday would not show as overdue until the server caught up with the calendar.
I did not trust myself to reason my way to a fix, so I pinned the behaviour down with a test that walks across midnight:
// server in UTC, clock frozen. overdueNow() fetches the task list and returns its isOverdue flag
vi.setSystemTime(new Date('2026-11-25T18:00:00Z')); // 23:30 in India
expect(await overdueNow()).toBe(false);
vi.setSystemTime(new Date('2026-11-25T19:00:00Z')); // 00:30 in India
expect(await overdueNow()).toBe(true);
The fix is a small helper that asks "what is the date in this timezone?" (an APP_TIMEZONE setting, Asia/Kolkata by default) instead of reading the server's. Now a server in Oregon and a server in Mumbai agree.
What I check first now: anything that says "today" or "now" gets a test on either side of midnight, run on a server in a different timezone from the users.
Bug 2: Everyone looked like one person
Sign-in has a rate limit: too many wrong passwords from one address and you are blocked for a while. Sensible.
Then I prepared the app to run on a free hosting plan, and I realised what a proxy does. Behind it, every visitor arrives from the proxy's address. To my rate limiter, the whole world was one very persistent person. A handful of wrong passwords from one user could lock out everybody else.
I wanted proof, not a feeling, so I tested both versions. With the proxy configured correctly, a user who hits the limit is blocked, and a different visitor is still allowed in. With it misconfigured, a total stranger gets blocked for someone else's mistakes.
The fix was a single setting: tell Express how many proxy hops to trust (1 in production, 0 on my laptop). The lesson was bigger. The code was fine; my picture of the network was wrong.
What I check first now: I ask where my code actually sits. Proxies, load balancers and CDNs change what "the client's address" means.
Bug 3: The types that lied
This one is the sneakiest, because TypeScript was telling me everything was fine.
My backend runs on Express 4, but my package.json asked for the type definitions of Express 5, and another types package kept pulling them back in even after I noticed. So my editor autocompleted an API that was not the one actually running, and the compiler checked my code against rules that did not apply. Nothing failed. The types were confident, and they were describing the wrong version.
I pinned the Express type packages to version 4 in the root package.json, using overrides, so no other package can quietly drag them back.
What I check first now: when a library has a major version, I confirm the runtime and its @types agree. Types are only a promise, and a promise about the wrong version is worse than none.
One design choice I'm proud of
Farmers' data is private, and admins still need to manage accounts. So I made the admin panel unable to see inside anyone's farms. Admins only ever see counts. Their role is re-checked from the database on every request, their routes require two-step verification (a TOTP implementation I tested against the RFC's own test vectors), and every admin action goes into an audit log. Admins cannot demote or switch off themselves, so nobody locks themselves out by accident.
The rule I took from it: if a feature does not need to see something, build it so it cannot, rather than promising it won't.
What is not finished
I would rather say this than have you find it. There is no password reset yet, farms can be archived but not deleted, and the market prices come from India's government data feed, so that page is India-only. I have not deployed a public demo, and on free hosting plans the disk is wiped on restart, so accounts would disappear. For that reason the app can recreate a demo account with sample farms on startup. SQLite suits one server; for more I would move to PostgreSQL.
What I took from it
The tests that mattered were not the ones that confirmed things worked. They were the ones I wrote because something felt off: a frozen clock, two different visitors, a pinned dependency.
If your app has never crashed, that is not the same as it being right. Go looking for the quiet ones.
The full project has 642 automated tests (472 backend, 170 frontend) and runs checks on every pull request. If you read the code and find a fourth quiet bug, I would genuinely like to hear about it.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.