Understanding Astrelo: A Deep Dive Into a Production SaaS
I built a SaaS and I’m going to understand every line.
A chapter-by-chapter walkthrough of the Astrelo codebase — a B2B go-to-market intelligence platform with ML scoring, CRM integrations, an AI chat agent, and real-time proactive alerts. Every example is real production code.
What You’ll Learn
Part 1: Foundations
- Authentication — JWTs, middleware, login flow, the
requireAuthpattern - The Database — Connection pooling, parameterized queries, migrations, multi-tenancy
- React Query — QueryClient, query keys, mutations, optimistic updates
- API Routes — The canonical 10-step handler, validation, error handling
Part 2: The Intelligence Engine
- Embeddings — 384-dimensional vectors, cosine similarity, NAICS codes
- Fit Scoring — NAICS matching, size similarity, loss penalties
- Intent Scoring — Signals, recency decay, semantic topic matching
- Composite Score — Weighted combination, buying stages, batch scoring
- Discovery Engine — 80/20 explore/exploit, 7 strategies, segment tracking
Part 3: Integrations
- HubSpot — OAuth, sync pipeline, entity resolution
- Salesforce — The alternative CRM path, SOQL, multi-CRM support
- Slack — Bot tokens, Block Kit, event subscriptions
- Groq — Two-model LLM architecture, JSON mode, caching
Part 4: Proactive Intelligence
- Event-Driven Architecture — Webhooks to triggers, the 9-step pipeline
- Alert Evaluation — 14 triggers, deduplication, rate limiting
- Predictions — Slip risk, loss risk, champion cold
- Autonomous Actions — The approval queue, auto-execute, 5 action types
- AI Content Generation — Async LLM enrichment, structured analysis
Part 5: The Chat Agent
- Cosmo’s Tool Architecture — Intent classification, tool registry, two-model design
- Tool Dispatch — Three branches, disambiguation, adaptive enrichment
- Goldilocks Brain — Strategic recommendations, explore/exploit, segment absorption
- Action Tools — Email, tasks, CRM sync, the safe vs. confirmation split
Part 6: Production Concerns
- Error Handling —
logError, sanitization, graceful degradation - Cron Jobs — 18 scheduled jobs,
SKIP LOCKED, timeout budgets - Rate Limiting — Fixed-window algorithm, monthly quotas, fail-open design
- Deployment — Build spec, webpack fallbacks, the monolith advantage
How to Read
Start with Part 1 (Chapters 1-5) in order — they establish patterns you’ll see everywhere. After that, jump to any Part that interests you.
Every code example includes the file path so you can open the actual source and see it in full context.
28 chapters. ~30,000 words. One complete SaaS, explained.
Last updated on