Skip to Content
Part 1: FoundationsPreface

I built a SaaS application. A real one — not a tutorial todo app, not a weekend project. It has 60 database tables, 68 API routes, an ML scoring engine, CRM integrations with HubSpot and Salesforce, a chat agent with 40+ tools, real-time alerts, predictive analytics, and autonomous actions that draft emails while you sleep.

And I’ll be honest: I vibe coded most of it.

I told an AI what I wanted, it wrote the code, I handled the errors and steered the direction. The product works. Users can log in, connect their CRM, get ML-powered prospect scores, talk to an AI assistant, and receive proactive alerts. It’s deployed on AWS Amplify, talks to an Aurora PostgreSQL database, and processes real webhook events from real CRM systems.

But I realized something: I own this code and I don’t fully understand every piece of it.

This book fixes that.

We’re going to walk through the entire Astrelo codebase — every layer, every pattern, every architectural decision — as if you were in a university course and I were the professor. The examples aren’t contrived. They’re pulled directly from production code. When I show you how authentication works, it’s not a textbook diagram — it’s the actual middleware that protects 68 live endpoints.

Who This Book Is For

  • You built something with AI and want to actually understand it. You’re not alone. Millions of developers are shipping AI-assisted code right now. Understanding what you shipped is the gap between being a prompt operator and being an engineer.
  • You’re learning web development and want to see real production patterns. Most tutorials stop at “here’s how to make a button.” This book shows you what a 60-table, multi-tenant SaaS application actually looks like.
  • You’re curious about how ML, CRM integrations, and real-time systems fit together in practice. Not in theory. In code that’s running right now.

How to Read This Book

Each chapter covers one architectural concept using real code from the Astrelo codebase. The chapters build on each other — the auth chapter explains patterns you’ll see in every API route chapter, the database chapter explains queries you’ll encounter in the ML chapter, and so on.

You don’t need to read every chapter sequentially. If you want to understand the ML scoring engine, jump to Part 2. If you want to understand the alert pipeline, jump to Part 4. But if you’re starting from scratch, Parts 1 and 2 in order will give you the strongest foundation.

File paths are included with every code example so you can open the actual file and see it in full context.

The Stack

Before we begin, here’s what we’re working with:

LayerTechnologyPurpose
FrameworkNext.js 14 (Pages Router)React frontend + API routes in one project
UI LibraryMaterial UI (MUI) v7Pre-built components (buttons, tables, dialogs)
Server StateTanStack React Query v5Data fetching, caching, and synchronization
DatabasePostgreSQL (AWS Aurora)Relational data storage
CacheUpstash RedisML score caching with 24-hour TTL
AuthJWT (JSON Web Tokens)Stateless authentication
LLMGroq (Llama 3.1 8B / 3.3 70B)AI analysis, content generation, chat
CRMHubSpot + SalesforceCustomer data sync via OAuth
MessagingSlack (Bot API)Alert delivery and daily digests
HostingAWS AmplifyCI/CD and deployment
AnalyticsPostHogProduct analytics and feature flags
PaymentsStripeSubscription billing

Let’s begin.

Last updated on