USAMA IRFAN

Senior Full-Stack & AI Engineer

Skip to main content
USAMA+IRFAN®
Back to Work
02/Enterprise SaaS·2025

UI HRM

AI-Powered Multi-Tenant Human Resource Management SaaS

Role

Lead Full-Stack & AI Architect

Key Contribution

Multi-tenant SaaS architecture, 10+ HR modules, pgvector workflows & automated anomaly detection

Core Stack

Next.js 15TypeScriptDrizzle ORMPostgreSQLpgvectorAI Workflow Automation
UI HRM · MULTI-TENANT WORKSPACE10+ MODULES · PGVECTOR

ATTENDANCE ANOMALIES

LIVE · 98.4%
MONTHU · SPIKESUN

AI EXPENSE & LEAVE ROUTING

Travel ReimbursementAuto-Categorized
Engineering Leave ReqRouted · L2
Policy Vector Match0.94 Cosine
Payroll Compliance SyncVerified
NEXT.JS 15 · DRIZZLE ORM · POSTGRESQLTENANT ISOLATED
01 & 02 / CONTEXT

Overview & Business Problem

Project Overview

UI HRM is a modern multi-tenant Human Resource Management SaaS designed to consolidate fragmented HR workflows into a single cohesive platform. Spanning 10+ integrated modules, it pairs type-safe full-stack architecture with embedded AI automation for expense classification, intelligent leave routing, and attendance anomaly detection.

Business Problem

Growing organizations often stitch together separate tools for attendance, leave approvals, and expense processing, creating manual review bottlenecks and inconsistent policy enforcement across departments.

03 & 04 / SCOPE

My Role & Requirements

03 · My Role

  • Architected the multi-tenant database schema and tenant-isolation layer using PostgreSQL and Drizzle ORM.
  • Built 10+ integrated HR modules using Next.js 15 App Router and strict end-to-end TypeScript.
  • Engineered AI workflow automation for expense categorization, intelligent leave routing, and attendance anomaly detection.
  • Integrated pgvector inside PostgreSQL for semantic policy lookup and automated classification.

04 · Core Requirements

  • Strict tenant isolation across organizations sharing a unified SaaS deployment.
  • Modular architecture supporting 10+ cohesive HR workflows with shared permissions.
  • Automated classification of employee expenses and anomaly flagging on attendance logs.
  • Fast, low-latency dashboard UX with server-rendered data hydration.
05 / ENGINEERING HURDLES

Technical Challenges

01

Maintaining clean cross-module domain boundaries across 10+ HR workflows without duplicating business rules.

02

Keeping vector similarity lookups and transactional HR queries consistent inside a single PostgreSQL engine.

03

Designing deterministic fallback logic whenever AI expense categorization confidence falls below threshold.

06 / SYSTEM ARCHITECTURE

Architecture Blueprint

Unified Next.js 15 full-stack architecture backed by PostgreSQL + pgvector via Drizzle ORM, isolating tenant context at the data-access layer and running AI classification and anomaly workflows asynchronously.

SYSTEM ARCHITECTURE TOPOLOGYPRODUCTION FLOW
01 · Application & UI Layer
Next.js 15 App Router
Server Actions & RSC
10+ Modular HR Workspaces
02 · Domain & Automation Engine
Tenant-Scoped Services
Expense Categorizer
Leave Routing & Anomaly Engine
03 · Data & Vector Layer
Drizzle ORM (Type-Safe)
PostgreSQL Multi-Tenant Schema
pgvector Policy Embeddings
07 / STACK RATIONALE

Technology Choices

Next.js 15 & TypeScript

Server Components and Server Actions minimize client bundle bloat while keeping full-stack types synchronized.

Drizzle ORM + PostgreSQL

Provides zero-overhead SQL control, explicit migrations, and native compatibility with pgvector.

pgvector

Eliminates the operational overhead of a separate vector store while enabling semantic matching alongside relational HR records.

08 / IMPLEMENTATION

Core Pattern Excerpt

Tenant-scoped Drizzle queries combined with pgvector similarity search classify expenses against organization-specific policy rules.

Tenant-Scoped AI Expense Categorization (TypeScript + Drizzle)typescript
export async function categorizeExpense(
  tenantId: string,
  description: string,
  embedding: number[]
) {
  const matchedPolicies = await db
    .select({
      categoryId: expensePolicies.categoryId,
      policyName: expensePolicies.name,
      similarity: sql<number>`1 - (${expensePolicies.embedding} <=> ${JSON.stringify(embedding)}::vector)`,
    })
    .from(expensePolicies)
    .where(eq(expensePolicies.tenantId, tenantId))
    .orderBy(desc(sql`similarity`))
    .limit(3);

  const topMatch = matchedPolicies[0];
  return {
    categoryId: topMatch && topMatch.similarity > 0.82 ? topMatch.categoryId : null,
    requiresManualReview: !topMatch || topMatch.similarity <= 0.82,
    candidates: matchedPolicies,
  };
}
09 & 10 / IMPACT

Outcomes & Lessons Learned

09 · Verified Outcomes

  • Delivered a scalable multi-tenant SaaS architecture supporting end-to-end HR operations across 10+ integrated modules.
  • Automated repetitive expense categorization, leave routing, and attendance anomaly detection.

10 · Lessons Learned

  • Co-locating relational and vector data in PostgreSQL with pgvector dramatically simplifies multi-tenant consistency.
  • Always pair AI automation with explicit confidence thresholds and human-in-the-loop review paths for financial workflows.