Case StudyFull-stack buildArchitecturePerformanceAI integration

IT Origin

A cybersecurity firm's whole web presence in one self-hosted Next.js codebase: marketing site, admin CMS, lead engine, and an AI chat desk

Client
IT Origin, a CERT-In empanelled cybersecurity firm
Role
Full build and ownership
Year
2026
Scope
Full-stack build, Architecture
Prabir Singh, profile photoPrabir Singh·23 min read
IT Origin live homepage showing its cybersecurity services introduction over a security operations centre video.

Live website preview · itorigin.com

Client
IT Origin, a CERT-In empanelled cybersecurity firm (Managed SOC, offensive security, GRC).
My role
Full build: product thinking, design system, front end, back end, infra, and deployment.
What it is
A marketing website plus a headless-style admin CMS plus growth tooling: leads, newsletter, appointments, and an AI chat desk.
Scale of the code
~55,000 lines of strict TypeScript with zero `any`, 41 public pages, 22 admin screens, 63 API routes, 29 tables across 12 schema modules.
Stack in one breath
Next.js 16, React 19, TypeScript, Drizzle ORM, PostgreSQL, Better Auth, Tailwind v4. Bun for installs, Node 22 in production.
Hosting
Self-hosted with Docker on a VPS via Coolify. No Vercel bill, full control.
The turnaround
A live SEO and performance audit came back a B minus with two F's. Measured, fixed, re-verified. Hero page weight cut 86%. Then a security pass closed a client-reported chat bypass and hardened auth end to end.
StackNext.js 16React 19TypeScriptNode.jsBunPostgreSQLDrizzleBetter AuthTailwind CSSTiptapVercel AI SDKGeminiResendZodCloudinaryDockerCoolify

A cybersecurity company sells trust. If their own website loads slow, breaks on hydration, or ships a 56 MB video to a phone on 4G, the pitch is dead before the first sentence. So the brief was never "make a pretty site."

It was "build the machine that turns a visitor into a booked call, and give the team the keys to run it without calling a developer every week."

That second half is where most agency builds quietly fail. They ship a beautiful front end wired to a CMS the client is scared to touch. I wanted the opposite: a front end fast enough to disappear, and a back office the marketing lead could drive on a Tuesday morning with a coffee and zero training.

That's the difference between building for the user and building for the buyer.

The problem, framed honestly

IT Origin had a service to sell and no engine to sell it. What they were missing broke down into four gaps.

They had no way to publish. Every blog post, case study, or event meant emailing a developer and waiting. Content that should ship in an hour took a week, so it mostly never shipped.

They had no way to capture. Visitors landed, read, and left with no trace. No lead record, no newsletter list, no follow-up. Attention walked in the front door and out the back.

They had no way to answer. A security buyer researching at 11 pm has questions, and a contact form that replies "we'll get back to you in 2 business days" loses them to a competitor who answered in ten seconds.

And they had no way to run any of it themselves. A marketing site that only a developer can edit is not an asset. It is a recurring invoice.

Success looked like this: the team ships content without me, leads land in a place they can act on, the buyer gets answers in real time, and the whole thing loads fast enough that Google and a distracted human both stick around.

The stack, and why each piece earned its seat

I do not pick tools because they trend. I pick them because they remove a specific pain I have felt at 2 am. Here is the short version, then the reasoning that matters.

LayerChoiceThe one-line reason
FrameworkNext.js 16 (App Router)Server Components mean the heavy work happens before the page reaches the phone
Runtime / PMBun for installs and dev, Node 22 in productionBun keeps the loop fast; Node builds and serves the release (more on that below)
LanguageTypeScript, strict, zero anyMany type mismatches surface before deployment; runtime checks remain necessary
DatabasePostgreSQL + Drizzle ORMThe query types come from the schema, so a wrong column is a red squiggle, not a production 500
AuthBetter AuthSessions, roles, and email/password without renting a third-party identity bill
StylingTailwind v4 (OKLCH)Design tokens live in CSS, colors stay perceptually even across the theme
EditorTiptapA real rich-text surface the content team controls, not a raw textarea
EmailResend + React EmailEmails written as components, so they match the brand instead of looking like a receipt
AI chatGoogle Gemini via the AI SDKStreaming answers grounded in a system prompt about the actual company
Rate limitingUpstash rate limit over RedisThe contact form and chat verify endpoints do not become a spam faucet
ImagesCloudinaryEvery CMS image field uploads straight to it, served in the best format for each browser

Two of those deserve more than a line.

Drizzle over a heavier ORM. Picture the schema as the single source of truth. You write the table once, and Drizzle infers the exact shape of every row, every insert, every join. Change a column from nullable to required, and the compiler walks you to every place that assumption now breaks. I have shipped apps where a renamed field slipped through and surfaced as a null-pointer three weeks later in front of a client. Inferred types catch many of those mismatches during development, provided the deployed schema and runtime data match the declarations. The queries read like SQL because they basically are SQL, so there is no fat translation layer guessing what I meant. This is one language across the whole stack doing real work.

Bun for the loop, Node for the release. The frugal builder in me hates waiting. Bun made the install-test-repeat loop fast enough that I ran the full production build after almost every meaningful change instead of "later." That habit is why the perf and SEO problems later in this document got caught in minutes, not after a client complaint. I started with Bun in production too. Then a Next.js upgrade that carried security fixes crashed under Bun's build. I didn't hold the security patch hostage to a runtime preference. Production builds and serves on Node 22 now, Bun still does the installs, and the site got its patches the same day.

I gave things up, too. Self-hosting on Coolify means I own the uptime. No Vercel edge network catching a bad deploy for me. I took that trade on purpose, and I will explain the payoff when we get to infra.

Architecture: a kitchen that preps the plate before it reaches the table

Server Components are the backbone. Think of a restaurant kitchen. The prep happens out of sight, the diner only ever sees the finished plate. Most of this site renders on the server, ships as HTML, and only reaches for client-side JavaScript where a human actually needs to click, type, or watch something move. Default to server.

Add "use client" only when interaction demands it. That single rule keeps the JavaScript the browser has to parse small, and small JavaScript is fast JavaScript. (I unpack that metaphor properly in React Server Components explained like a kitchen.)

The app splits into three worlds by route group, each with its own layout:

  • (marketing) wraps the public pages in the topbar, header, chat widget, and footer. This is the shop window.
  • (auth) is a stripped, centered card for sign-in and sign-up. Nothing to distract from the one action.
  • admin is the back office: sidebar, header, and every management screen behind a role check.

Security runs in two layers, and I kept both on purpose. The edge proxy (Next.js 16 renamed the middleware file, same idea) checks one cheap thing before any admin request even reaches the server: is there a session cookie? No cookie, you bounce to sign-in. That is the bouncer at the door. Then every single admin API route and admin page checks the real question again on the server: is this user actually an admin? That is the manager verifying the badge inside.

Admin request and authorisation boundaries

Explore the connections · swipe or use arrow keys when focused

Admin request and authorisation boundariesCookie presence is an early routing check, not proof of identity or permission. Server-side session validation and the admin role check protect every operation. Database access happens only after that check succeeds.SERVER-SIDE AUTHORISATION BOUNDARYAdmin requestPage or API requestCookie present?Cheap proxy checkValid admin?Verify session + roleAdmin APIResource operationsSign-inNo session cookieDeniedInvalid or insufficient accessPostgreSQLDrizzle schema modulesyesallowednodenied
Cookie presence is an early routing check, not proof of identity or permission. Server-side session validation and the admin role check protect every operation. Database access happens only after that check succeeds.

The API follows one boring, predictable shape, and boring is the point. Every resource gets /api/admin/{resource} for list and create, /api/admin/{resource}/[id] for read, update, delete. Special actions, like sending a campaign, get their own explicit endpoint. When the pattern never surprises you, you stop thinking about plumbing and start thinking about the feature.

Illustrative TypeScript, written for this article. This function receives a session already verified by a server-side authentication system. Never construct that trusted input from a role sent by the browser.

type VerifiedSession = { userId: string; role: "editor" | "admin" };
 
function adminDecision(session: VerifiedSession | null): 200 | 401 | 403 {
  if (!session) return 401;
  if (session.role !== "admin") return 403;
  return 200;
}
 
console.log(adminDecision(null)); // 401: authenticate first
console.log(adminDecision({ userId: "demo", role: "editor" })); // 403

The function teaches the distinction between authentication and authorisation. It does not implement session verification, expiry, revocation, resource ownership, or CSRF protection. Those belong around the route and operation, not in a hopeful frontend flag.

The useful test is the denied path: a valid editor session must still fail an admin-only operation. OWASP’s authorisation guidance recommends checking permissions on every request. The proxy can save work; the server check must protect the data.

The data layer: 12 modules that model a real business

The schema is not one giant file. It is 12 focused modules holding 29 tables, each module owning a slice of the business: auth, blog, leads, services, chat, email, settings, resources, case studies, testimonials, events, appointments. They export through a single index, so the rest of the app imports types from one clean door.

Eighteen migrations track how the model grew over time. Nothing gets pushed to a schema by hand in production. The build emits a standalone server, and the container runs the migrations on startup before it serves a single request. So a deploy that changes the database applies the change automatically, in order, every time. No "did someone run the migration?" Slack message at midnight.

One small discipline that pays off quietly: raw SQL in the API routes uses parameterized queries, the $1, $2 style, not string interpolation. On a pooled connection that is both safer against injection and kinder to the query planner. It costs nothing to do and saves you from the one bug you really do not want on a security company's website.

The design system: tokens first, so the brand stays honest

Here is the thing nobody tells you about design systems: consistency is not about picking nice colors. It is about making the wrong choice impossible. If a developer can type any hex code, they will, and six months later you have forty shades of "brand red."

So the color lives in one place, as a token, and everything references the token. That's the whole argument for a design system that earns its keep.

The palette is built in OKLCH, not hex or HSL. That matters more than it sounds. OKLCH is perceptually even, so when the brand's signature high-chroma red (oklch(0.637 0.237 25.331), a red that means business) shifts between light and dark mode, it stays the same felt red instead of drifting muddy or neon.

Every semantic color, background, foreground, primary, accent, muted, card, sits behind a CSS variable. Dark mode is not a second stylesheet. It is the same tokens with different values, flipped by a class on the root.

Typography carries two jobs. Satoshi for headings, so the loud moments feel sharp and deliberate. Inter for body, because you read a lot of it and it should get out of the way.

The components are shadcn/ui primitives built on Radix, which means the accessible behavior (focus traps, keyboard nav, ARIA wiring) is handled correctly underneath, and I get to style the surface without rebuilding a dropdown from scratch for the hundredth time.

Motion comes from Motion (the library formerly styled as Framer Motion), with a small set of shared variants: fade-in-up, stagger, and a few friends. Reused, not reinvented per page. Movement should feel like the same hand drew it everywhere.

And the copy itself is not trapped in JSX. Page text lives in a data layer under utils/data, organized per page. When marketing wants to reword the hero, that is a content edit in one file, not a scavenger hunt through components. Small decision, big difference on a site this size.

What it actually does: the feature set

This is where the "whole company online" claim earns itself. The build is not a brochure with a contact form bolted on. It is a set of working systems.

A real content CMS. Blog posts with a Tiptap rich-text editor, categories, tags, comments, draft and published states, cover images, reading time, view counts, and slug-redirect handling so an old URL never 404s after a rename. The team writes, previews, and ships. No developer in the loop.

A lead and growth engine. Contact submissions become lead records. A newsletter with double opt-in (subscribe, confirm by token, welcome), unsubscribe by token, and CSV export for the sales team. Campaigns you compose in the admin and send to the list when the team is ready.

An appointment system. Bookings with a full lifecycle: pending, confirmed, completed, cancelled, no-show. The team runs their calendar from the same dashboard they run everything else.

An AI chat desk. A support widget backed by Google's Gemini, streaming answers grounded in a system prompt about IT Origin's actual services. It verifies a visitor's email before a real conversation, and every conversation is stored so the team can review what buyers are asking. This is the "answer at 11 pm" gap, closed, and it's the frugal kind of AI that ships instead of AI that demos.

The rest of the shop. Case studies, testimonials with an approval flow, events and webinars, downloadable resources and gated whitepapers with a content-derived table of contents, and a services section that builds itself from the database so the navigation updates when the offerings do.

Every one of those has an admin screen, an API, and a schema behind it. Twenty-two admin screens is not padding. It is the difference between a site the client owns and a site the client rents from me forever. I would rather they own it.

The chapter I am proudest of: making it fast, and getting caught being honest

Here is where I break the fourth wall, because the case study rule I hold myself to is simple. Show what went wrong. Polished success stories build less trust than an honest post-mortem, and I have one.

I ran a full SEO and performance audit on the live site. It came back a B minus. Two categories scored an F. Not the client's fault. Mine. A site is a living thing, and things I let slide during the sprint had piled up. So I fixed them, measured every change, and the numbers below are all real, taken from this codebase and the live server.

The 56 MB hero

The homepage hero was a rotating video carousel. Gorgeous. Also quietly catastrophic. All three background videos mounted at once, every one set to autoplay, none told to wait. So a browser hitting the page eagerly pulled all three: 3.6 MB, then 33 MB, then 19 MB. Roughly 56 MB of video before the visitor read a single word.

On a phone, that is somebody's data plan and their patience, gone.

Two separate problems hid inside that one symptom, and telling them apart was the whole fix. The first was a loading problem: three videos in the DOM when only one is on screen. The second was a weight problem: a 33 MB file for an eight-second loop that sits behind an 80 percent black overlay, where nobody can see the detail you paid all those megabytes for.

So I fixed both. Only the active slide now mounts a video. The others rest as a lightweight poster image, which doubles as the instant first paint instead of a black rectangle. Then I re-encoded every clip to a web-sane 720p, stripped the audio nobody hears on a muted background, and moved the file's index to the front so playback starts before the download finishes.

AssetBeforeAfter
Hero videos, total56 MB7.7 MB (down 86%)
Videos fetched on first paint3 (all)1, behind a ~100 KB poster
Dead weight removed24 MB of videos referenced nowheredeleted

The two sitemaps that were fighting

This one is my favorite, because it is invisible until you go looking. The site had two sitemap generators. A modern Next.js route that correctly used the real domain, and an older tool that wrote a static file at build time using an outdated domain.

In Next.js, a static file in the public folder wins over a generated route at the same path. So the stale one was serving. For weeks, search engines were being handed a sitemap pointing at the wrong domain, and nobody noticed because both files "existed."

The bug that was never in the console

The audit flagged a JavaScript error. The browser console was clean. That contradiction is exactly why it survived so long. It was a React hydration mismatch, and it came from the most innocent line in the codebase: a footer that rendered today's date with toLocaleDateString(). The server formats that date in its timezone. The browser formats it in yours.

Different text, same spot, and React throws a fit that shows up as a page error but not a console log. Gone now, and I swept the rest of the site for the same trap.

Twelve pages pointed their social share image at files that did not exist. So every link shared on LinkedIn or WhatsApp showed up bald, no picture. Instead of drawing twelve images by hand and maintaining them forever, I built a single generator route that renders a branded card on demand, takes the page title as a parameter, and stamps the trust badges (CERT-In, ISO 27001, STQC) straight from config.

One route, every page covered, nothing to keep in sync.

The scoreboard

What the audit dingedBeforeAfter
Structured data (schema for AI and search)none livesite-wide: organization, services, articles, FAQs, breadcrumbs
Broken booking link404removed, native flow
Sitemap and robots domainsplit, wrong domain servedsingle, correct domain
Meta descriptiontoo shortrewritten with the keywords that were missing
Hero page weight4+ MBslashed with the video work above
Hydration error on load10, verified on a real build
Broken social images120, generated on demand

I also wired up analytics the right way, gated behind cookie consent, so the team can finally measure instead of guess. The instrument is in. The reading comes next.

The security pass: a security company's site gets tested like one

A cybersecurity firm's own customers poke at its website. That's the job. So when the client's team reported that they could open the AI chat without verifying an email, by rewriting the server's response in an intercepting proxy, I didn't treat it as an edge case. I treated it as the front door.

The flaw was a familiar one: the browser was trusted to remember that verification had happened. Fixing the symptom would have meant hiding the panel a little harder. Fixing the cause meant taking the decision away from the browser entirely.

  • Codes live on the server. One-time codes come from a cryptographic random source, are stored only as hashes, compared in constant time, used once, and locked after five wrong tries. The grant travels in an HttpOnly cookie that page scripts can't read.
  • The panel asks before it opens. The chat now checks the session with the server first. The server must validate the grant on chat requests, regardless of what the browser displays. Changing a response locally must not grant access to protected data.
  • History comes from the database, not the browser. The server rebuilds the conversation from its own records instead of trusting what the page sends, so nobody can slip a forged assistant reply into the context. Messages and history length are capped.

Then I swept the rest of the auth surface while I was in there:

AreaBeforeAfter
Revoking a sessionTook up to five minutes to biteTakes effect on the next request, with an admin view of active devices
PasswordsBasic length rule12+ characters, complexity, a check that sees through letter-for-number swaps, no reuse of the last five
Changing a passwordRejected every attempt, due to a hashing mismatchWorks, and the mismatch is fixed at the source
Scheduled endpointOpen if its secret was missingFails closed
Structured dataUnescapedEscaped against script injection
CSV exportsRaw cell valuesProtected against spreadsheet formula injection
Public formsContact, leads and newsletter unthrottledRate-limited
DependenciesKnown advisories, including a proxy bypassPatched framework, ORM and auth library

None of this shows up in a screenshot. All of it shows up in the first penetration test a prospect runs before signing.

Deployment: I own the uptime, and I wanted it that way

The build compiles to a standalone server, packed into a multi-stage Docker image: Bun installs the dependencies, Node 22 builds and runs it. The container's entrypoint runs the database migrations first, then boots the server, so schema changes ship with the code and apply themselves. Coolify on a VPS handles the deploy, watches the main branch, and rebuilds on merge.

A local Docker Compose file gives me Postgres and Redis for development that mirror production without me installing anything on the metal.

I chose self-hosting with eyes open. The trade is real: no managed edge network to catch my mistakes, so my build discipline has to be the safety net instead. The payoff is control and a more predictable infrastructure baseline. Capacity upgrades, bandwidth, backups and operational time can still increase the total cost.

For a company that plans to publish steadily for years, owning the box beats renting the magic. It's the same instinct as building the web app like an appliance: predictable, owned, and boring in the ways that count.

How to read the evidence in this case study

The page counts and asset reductions describe the build and audit recorded here. They are useful engineering evidence, but they do not establish conversion lift, search-ranking gains or customer revenue. Those need separate production measurements over an agreed period. A lighter hero is a real improvement; a lighter hero is not automatically a sales forecast.

For a similar site, I would turn the handover into three short demonstrations:

  1. Publishing: an editor saves a draft, previews it, publishes it and follows the old URL after a slug change. Confirm which roles may perform each step.
  2. Permissions: an unauthorised account requests the admin endpoint directly. Hiding an admin button is not a server-side access check.
  3. Recovery: restore a backup into an isolated environment and verify that content, uploads and required configuration can be recovered together.

These are proposed acceptance checks for readers adapting the architecture, not claims that new tests were run against the client's production system during this editorial update.

OWASP's authorisation guidance explains the permission boundary. For the AI desk, verifying an email establishes control of an address; it does not grant admin privileges or make an answer accurate. The separate AI shipping guide covers evaluation and fallback. Operational ownership means knowing how to recover on a bad Tuesday, not just how to deploy on a good one.

What I would do differently, and what is next

Honesty is the whole point of this section, so here it is.

I would run the audit first, not after the sprint. Every problem in that performance chapter was avoidable at the moment I wrote the code. The 56 MB hero was a decision I made and did not measure. Catching it later cost more than catching it early would have. Measure the thing while your hands are still on it.

I would collapse duplicate systems the day I notice them. The two-sitemap mess grew because "both work" felt fine at the time. It was not fine. It was a quiet bug with a fuse.

What is next is mostly instrumentation paying off. Analytics is live now, so the next round of decisions gets made on real visitor behavior instead of my best guess. The AI chat logs are a goldmine of the exact questions buyers ask, which is free product research the sales team can mine.

And there is a short punch list I handed back to the client: connect the analytics ID, finish the booking flow on their own platform, and put a CDN in front for the last slice of speed.

The bigger next step is a handover in the truest sense. The plan moves production onto a server and a code repository the client owns outright, running the same container setup, with the current server kept warm as a rollback. I'd rather a client own their stack than rent it from me.

Why this build holds up

Most marketing sites are a pretty face on a fragile body. This one is the other way around. The face is fast because the body does the heavy lifting on the server. The team owns their own content because the CMS was built for them, not for me. The buyer gets answers at midnight because the chat desk never sleeps.

And when the site started slipping, I could measure exactly where and fix it in an afternoon, because the whole thing is typed, tested by build, and honest about its own state.

That is the standard I hold every project to. Not "does it look good in a screenshot," but "does it still work when the traffic spikes, the team edits it on a Friday, and the founder checks the analytics on a Monday." This one does.

If you are building something where the website is not decoration but the actual engine of the business, that is the kind of work I like most. Tell me what you are building, and I will tell you honestly how I would build it.

ShareXLinkedInFacebook
Prabir Singh, profile photo

Prabir Singh

Full-stack engineer in Mumbai. Twenty years in sales taught me why people buy; seven years of code taught me how to build what they'll pay for. I still read error messages the way I once read objections: as the most honest feedback of the day. More about me or start a project.

More work

Concept illustration of an exploded building model with structural floors, glass facade and a highlighted beam.
Full-stack product engineer·2026

A Whole Building in a Browser Tab

A browser-native BIM platform: heavy IFC building models converted on the server, so anyone can click a wall in the browser and read the exact engineering data behind it. No install, no plugin, no license.

Full-stack buildArchitecture3D / WebGLPerformance
Geometric woven pattern of alternating forest-green and apricot threads on a warm yellow background.
Sole product engineer·2026

Garden Vareli Kiosk

A showroom tablet that keeps selling when the internet quits

Full-stack buildArchitecturePWA & offlinePerformance