0%
balqalam Logo
balqalam
FeaturesCommunityPricingDocumentation
Login
  • Introduction
  • Pitch
  • Hogwarts
  • Live Demo
  • MVP
  • Roadmap
  • Launch Sprint
  • PRD
  • Get Started
  • Localhost
  • Architecture
  • Structure
  • Pattern
  • Page
  • Layout
  • Content
  • Types
  • Config
  • Actions
  • Queries
  • Authorization
  • Validation
  • Form
  • Table
  • Detail
  • Card
  • Util
  • Hooks
  • List Params
  • Views
  • README.md
  • ISSUE.md
  • Technology Stack
  • Database
  • File
  • CDN Assets
  • Entry Points
  • Dashboard
  • Authentication
  • Credentials
  • OAuth
  • Flow Diagrams
  • Multi-Tenancy
  • Offline
  • Onboarding
  • Onboarding Videos
  • Add Values
  • Admission
  • Application
  • Attendance
  • Compliance
  • Profile
  • Exams
  • Exam Wizard
  • Timetable
  • Classrooms
  • Notifications
  • Conference
  • LMS (Lumos)
Finance
  • Finance
  • Fee Management
  • Invoice
  • Wallet
  • Salary
  • Payroll
  • Timesheet
  • Expenses
  • Budget
  • Receipt
  • Accounts
  • Banking
  • Reports
  • Dashboard
  • Permissions
  • Messages
  • Integration Flow
  • Provision
  • AI Document Processing
  • Document Intelligence
  • Internationalization
  • Translation
  • Translation Guide
  • Icons
  • Docs Factory
  • Inspiration
  • Listings
  • Teachers
  • Students
  • Catalog
  • Library
  • Contributing
  • Code of conduct
  • GitHub Workflow
  • Database Seeds
  • Database Safety
  • Test Accounts
  • Playwright
  • Prettier
  • Block Rebound
Sales & GTM
  • Marketing Brief
  • Sales
  • Go-to-market
  • Marketing
  • Admission — Feature Spotlight
  • Pilot Program
  • Leads
  • Proposal
  • Outreach Templates
  • Case Study
  • Competitors
  • Landing-page teardown
  • Competitor FAQ
  • Business model
  • Shared economy
  • Traction
Fundraising & Ecosystem
  • Get Support
  • Investor Deck
  • Data Room
  • Investors
  • Accelerators
  • Incubators
  • Grants
  • Sponsors
  • Partners
  • Competitions & Hackathons
  • Universities & Training Centers

AI Document Processing

PreviousNext

Domain-agnostic Anthropic-powered extraction pipeline shared by every feature that processes uploaded documents.

A single extraction service, processing queue, and budget enforcer that any domain can plug into. Today it runs admission documents and bank receipts; the foundation supports 8 future domains tracked in Document Intelligence.

Architecture

Domain features (Admission, Bank Receipts, …)
        │
        ▼
extractWithSchema<T>(schema, prompt, fileUrl)   ← PDF / Word / Excel / CSV / Image
        │
   ┌────┼─────────────┐
   ▼    ▼             ▼
Handler  Queue Runner  Budget Enforcer
Registry (async +     (per-school caps,
         retry)        domain toggles)
        │
        ▼
/api/document-processing/run  (cron, DEVELOPER/ADMIN only)

Core layers

LayerLocationResponsibility
Generic Extraction Servicesrc/lib/document-extraction/Accepts any Zod schema + prompt; returns validated structured data
Handler Registrysrc/lib/document-extraction/handlers/Strategy pattern — each domain registers a handler
Queue Runnersrc/lib/document-extraction/queue-runner.tsAsync jobs, exponential backoff (30s, 60s, 120s)
Budget Enforcementsrc/lib/ai/budget.tsMonthly spend caps, per-domain toggles, usage tracking
Processing API/api/document-processing/runCron trigger endpoint

Processing flow

  1. File uploads via S3 / CloudFront pipeline.
  2. Domain feature classifies the document type (or accepts user-provided).
  3. DocumentProcessingJob row created with PENDING.
  4. Queue runner sets PROCESSING and delegates to the registered handler.
  5. Handler calls extractWithSchema() with schema + prompt.
  6. Results stored as JSON; status set to COMPLETED.
  7. Cost logged to AIUsageLog and checked against the school budget.

Database models

DocumentProcessingJob

FieldTypePurpose
idString @idPrimary key
schoolIdStringTenant isolation
userIdStringInitiator
jobTypeStringADMISSION_DOCUMENT, BANK_RECEIPT, …
statusEnumPENDING, PROCESSING, COMPLETED, FAILED
inputFileUrlStringSource file
inputDataJson?Extra context
resultDataJson?Extracted data
errorMessageString?On failure
retryCountInt @default(0)Attempts
maxRetriesInt @default(3)Cap
processingTimeMsInt?Duration
costUsdDecimal?Cost

AIUsageLog

FieldType
schoolIdString
jobTypeString
modelString (e.g., claude-sonnet-4-20250514)
providerString (e.g., anthropic)
inputTokens, outputTokensInt
costUsdDecimal
createdAtDateTime

School extensions

FieldTypePurpose
aiMonthlyBudgetDecimal?Monthly cap; null = unlimited
aiEnabledDomainsJsonArray, e.g. ["admission", "bank_receipt"]

Active domains

Admission documents (EPIC-1)

CapabilityDetail
Classificationdegree, transcript, national_id, resume, other
ExtractionPer-type Zod schemas with .describe() annotations
Arabic-aware promptsLatin transliteration, Hijri→Gregorian, bilingual fields
CompletenessCross-references campaign requiredDocuments
Merit engineWeighted scoring from GPA, entrance exam, interview

Server actions: processApplicationDocument, getDocumentProcessingStatus, classifyDocument.

Bank receipts

CapabilityDetail
ExtractionAmount, date, reference number, bank name
MatchingAuto-match to pending Payment records
ValidationCross-check amount against expected fee

UI components

Shared

ComponentFileBehavior
ProcessingStatusBadgeshared/processing-status-badge.tsxPENDING amber, PROCESSING blue + spinner, COMPLETED green, FAILED red
ConfidenceScoreDisplayshared/confidence-score-display.tsxHIGH (≥0.8) green, MEDIUM (≥0.5) amber, LOW (<0.5) red
ProcessingProgressCardshared/processing-progress-card.tsxComposite — badge + confidence + error + retry
AIBudgetIndicatorshared/ai-budget-indicator.tsxSpend vs limit progress bar

Admission AI

ComponentFile
DocumentCardadmission/ai/document-card.tsx
DocumentReviewPaneladmission/ai/document-review-panel.tsx
DocumentsSectionadmission/ai/documents-section.tsx

Settings

AISettingsForm (settings/ai-settings-form.tsx) — admin config for monthly budget, domain toggles, usage display.

Foundation files

FilePurpose
src/lib/document-extraction/types.tsGeneric types, ProcessingJobType enum
src/lib/document-extraction/claude-extractor.tsextractWithClaudeGeneric()
src/lib/document-extraction/index.tsextractWithSchema<T>() public API
src/lib/document-extraction/queue-runner.tsAsync job runner
src/lib/document-extraction/handlers/index.tsHandler registry
src/lib/document-extraction/handlers/admission.tsAdmission handler
src/lib/document-extraction/handlers/bank-receipt.tsBank receipt handler
prisma/models/document-processing.prismaDocumentProcessingJob, AIUsageLog
src/lib/ai/budget.tscanUseAI(), trackAIUsage(), getAIUsageSummary()
src/app/api/document-processing/run/route.tsCron endpoint

Configuration

ANTHROPIC_API_KEY=sk-ant-...

Set aiMonthlyBudget (null = unlimited) and toggle domains in AI Settings.

Cost estimates

OperationEstimated cost
Document classification~$0.01 / doc
Document extraction~$0.02–0.05 / doc
Bank receipt extraction~$0.02–0.03 / doc
Full application (5 docs)~$0.15
200 applications / campaign~$30

When the budget is exhausted, AI operations return AI_BUDGET_EXCEEDED and the UI prompts manual processing.

Adding a new domain

// 1. src/components/school-dashboard/<domain>/ai/schemas.ts
export const textbookMetadataSchema = z.object({
  title: z.string().describe("Book title"),
  author: z.string().describe("Author name"),
  isbn: z.string().optional().describe("ISBN"),
  edition: z.string().optional(),
  publisher: z.string().optional(),
})
  1. Add a handler in src/lib/document-extraction/handlers/ mapping the job type to schema + prompt.
  2. Import the handler in queue-runner.ts so it auto-registers.
  3. Server actions in <domain>/ai/actions.ts call createProcessingJob() with the job type.
  4. Add the domain string to the school's aiEnabledDomains via AI Settings.

Roadmap

EpicNameStory pointsStatus
0Foundation34Done
1Admission Documents49Done
2Exam Paper Intelligence36Planned
3Textbook & Curriculum28Planned
4Library & Book Management24Planned
5Attendance Intelligence20Planned
6School Onboarding Intelligence20Planned
7Invoice & Expense22Planned

Total: 233 story points.

See also

  • Document Intelligence
  • Admission
  • File
  • Multi-Tenancy
ProvisionDocument Intelligence

On This Page

ArchitectureCore layersProcessing flowDatabase modelsDocumentProcessingJobAIUsageLogSchool extensionsActive domainsAdmission documents (EPIC-1)Bank receiptsUI componentsSharedAdmission AISettingsFoundation filesConfigurationCost estimatesAdding a new domainRoadmapSee also

Built by Databayt ·

Welcome to balqalam.

A great journey is about to begin.