case study — AI-powered SaaS platform · NatRIX
HudFinanceAI
A vertically specialized AI assistant,
built to be commercially operable.
HudGPT brings domain-locked HUD financing expertise to professionals on demand — wrapped in production-grade infrastructure: token-level cost metering, a quota engine, persistent conversations, secure verified accounts, a provider-flexible LLM layer, and an analytics-rich admin dashboard.
React 19
TypeScript
Express 5
LangChain
PostgreSQL
Drizzle ORM
Ollama
OpenAI
Langfuse
Docker + Nginx
the problem
| Complex, evolving HUD rules | Professionals spend significant time researching eligibility and structuring questions across dense program documentation |
| Scarce specialist knowledge | Routine HUD questions create bottlenecks and high advisory costs — expertise doesn't scale with demand |
| Generic AI tools drift off-domain | General chatbots lack HUD focus, hallucinate finance details, and aren't trusted for regulatory work |
| AI cost is unpredictable | Uncontrolled LLM spend can make an AI product economically unviable at scale |
| No conversation continuity | Users lose prior analysis between sessions — repeating context on every query |
the solution
HudFinanceAI solves the problem with a domain-constrained AI assistant wrapped in production-grade product infrastructure. Most AI prototypes nail the chat experience and ignore everything else. This one was built as a commercially operable product from day one.
HudGPT — domain-locked assistant
A carefully engineered system prompt scopes answers to HUD multifamily/healthcare financing, enforces professional tone, keeps responses in Markdown, and prevents model/provider disclosure.
Provider-flexible AI layer
LangChain abstraction with two interchangeable backends: self-hosted Ollama for data privacy and cost control, and OpenAI for managed high-capability inference. One-line switch between them.
Cost governance built in
Every AI response records input/output/total tokens. Per-user running totals, a configurable global quota, and per-user overrides make AI consumption measurable and enforceable — the foundation for future billing tiers.
three-application architecture
Client · :7501
User Portal
Admin · :7503
Operations Dashboard
Server · :7502
Express API
core features
HudGPT Chat
Domain-locked conversational AI with Markdown rendering, typewriter animation, and HUD program awareness.
Persistent Conversations
Chats and messages stored in PostgreSQL — users resume prior threads across sessions without losing context.
Secure Auth + Email Verification
bcrypt hashing, JWT sessions, signed-token verification via Nodemailer, resend support, and isVerified gating.
Token Usage Metering
Input/output/total tokens recorded per message and aggregated per user — the data layer for cost governance.
Quota Engine
Global default token limit plus per-user override. Exceeded flag surfaces automatically. Admins manage all limits from the dashboard.
Admin Analytics
Total users, new users (30d), verified users, and aggregate AI usage — visualized with Recharts and TanStack Table.
Admin User Management
User listing, deletion, password reset, per-user quota override, and conversation oversight from the admin dashboard.
HUD Resources Library
Curated program summaries for Sections 221(d)(4), 223(f), 232/223(f), 241(a), 220, and 231.
user & data workflow
01
Sign up & email verification
bcrypt-hashed password stored; Nodemailer sends a signed JWT verification link; isVerified flag gated on click
02
Login → JWT issued
Credentials verified; JWT issued and stored client-side; protected routes (/chats, /admin) unlocked
03
HudGPT question submitted
JWT middleware authorizes; LangChain invokes Ollama or OpenAI with HudGPT system prompt; Langfuse traces the call
04
Response persisted + usage metered
Message saved to PostgreSQL; token counts written to token_usage; user_token_usage aggregate updated; exceeded flag checked against quota
05
Markdown answer rendered to user
react-markdown + remark-gfm renders the response; typewriter effect animates delivery
06
Admin dashboard updated
SQL aggregates surface updated user counts, activity, and AI consumption metrics in real time
database schema (PostgreSQL · Drizzle ORM)
users
Identities, credentials, isVerified flag
admins
Admin credentials and access
chats
Conversation records per user
messages
Individual messages with role (user/assistant)
token_usage
Per-message input/output/total token counts
user_token_usage
Per-user aggregate + exceeded flag
quotas_default
Global active token limit
quotas_override
Per-user token limit overrides
security model
| Password storage | bcrypt hashing — no plaintext, no reversible encryption |
| Sessions | JWT-based; tokens required on all /chats and /admin routes via middleware |
| Email verification | Signed JWT tokens delivered via Nodemailer; isVerified gating with resend support |
| Authorization boundaries | Separate admin credentials and module; client routes have no access to admin endpoints |
| AI domain safety | System prompt instructs assistant not to disclose model/provider and to stay on-domain |
| Data privacy option | Self-hosted Ollama backend keeps prompts and responses off third-party infrastructure |
implementation highlights
01Built the AI layer behind a LangChain abstraction — triggerOllamaAI and triggerOpenAI behind a uniform interface means switching LLM providers is a single configuration change, with no refactoring of chat routes or prompt logic.
02Captured token usage at the moment of each AI response using usage_metadata — aggregating it immediately into per-user totals rather than reconstructing cost after the fact. This makes the quota engine reliable and the data always current.
03Designed the quota system as two tables — quotas_default for the global limit and quotas_override for per-user exceptions — making it the direct foundation for future billing tiers without schema changes.
04Separated client and admin into distinct Vite SPAs served behind independent Nginx instances — cleaner access boundaries, isolated UI concerns, and independent deployability, all behind a shared modular API.
05Added Langfuse tracing across all AI calls — giving the platform production-level observability over LLM latency, token patterns, and response quality from day one.
future roadmap
Near-term
RAG over HUD docs
Citation-backed answers from authoritative HUD program documents via retrieval-augmented generation
Near-term
Streaming responses
Token-streamed chat delivery for lower perceived latency on longer AI responses
Mid-term
Document upload
Analyze term sheets and loan files for deal-specific HUD program guidance
Mid-term
Billing & tiers
Subscription tiers layered directly onto the existing quota engine and usage metering infrastructure
Long-term
Org accounts
Team workspaces, shared conversation history, and role hierarchies for enterprise customers
Long-term
Eligibility screening
Automated HUD program matching and pre-screening based on deal parameters
full tech stack
React 19TypeScriptVite 6TanStack RouterTanStack QueryTanStack TableTailwind CSS v4Radix UIZustandReact Hook FormZodreact-markdownRechartsDnD KitExpress 5Node.jsLangChainOllamaOpenAILangfusePostgreSQLDrizzle ORMJWTbcryptNodemailerDockerNginx