Skip to main content

Documentation Index

Fetch the complete documentation index at: https://grantmaster.dev/llms.txt

Use this file to discover all available pages before exploring further.

Document Brain

StatusUpdatedCovered Files
🟢 Stable2026-02-22features/documents/, features/documents/services/documentBrainService.ts, features/documents/services/documentClassificationService.ts, features/documents/services/recommendationEngine.ts, features/documents/services/documentFolderService.ts

Overview

Document Brain is the AI-powered document management system that provides intelligent classification, automated folder organization, compliance gap analysis, and contextual recommendations. It uses Gemini 2.0 Flash for document analysis and classification across 40+ document types.

Architecture

┌─────────────────────────────────────────────────────────┐
│  Smart Upload (Dropzone)                                │
│  Drag-and-drop with AI classification preview           │
├─────────────────────────────────────────────────────────┤
│  Classification Service                                 │
│  Gemini 2.0 Flash: type detection, metadata extraction  │
├─────────────────────────────────────────────────────────┤
│  Document Brain Service                                 │
│  CRUD, versioning, approval workflow, search            │
├─────────────────────────────────────────────────────────┤
│  Recommendation Engine                                  │
│  Contextual suggestions, gap analysis, compliance       │
├─────────────────────────────────────────────────────────┤
│  Folder Service                                         │
│  Smart folders, auto-organization, access control       │
└─────────────────────────────────────────────────────────┘

Document Classification

File: src/features/documents/services/documentClassificationService.ts

AI Classification Pipeline

  1. Upload: User drops file into SmartUploadDropzone
  2. Extract: Text extraction from PDF, DOCX, images (OCR)
  3. Classify: Gemini 2.0 Flash analyzes content and suggests document type + metadata
  4. Confirm: User reviews classification via ClassificationConfirmModal
  5. Store: Document saved with verified classification and metadata

Document Types (40+)

Organized by domain:
DomainExample Types
GrantProposal, Award Letter, Budget Narrative, Modification Request
FinancialInvoice, Receipt, Audit Report, Bank Statement
CompliancePolicy Document, Certification, License, Insurance
HRContract, Resume, Performance Review, Training Certificate
ProjectWork Plan, Progress Report, Deliverable, Meeting Minutes
LegalMOU, NDA, Sub-award Agreement, Amendment

Classification Output

interface ClassificationResult {
  documentType: DocumentType;
  confidence: number;           // 0-1 confidence score
  suggestedMetadata: {
    title: string;
    description?: string;
    relatedProject?: string;
    relatedGrant?: string;
    expiryDate?: string;
    tags: string[];
  };
  suggestedFolder?: string;     // Auto-organization target
}

Approval Workflow

Document States

StateDescription
draftInitial state, editable
reviewSubmitted for approval, read-only
approvedApproved, version-locked
archivedSoft-archived, searchable but inactive

Version Control

Each document maintains a version history:
interface DocumentVersion {
  versionNumber: number;
  uploadedBy: string;
  uploadedAt: string;
  fileUrl: string;
  fileSize: number;
  changeNote?: string;
}

Recommendation Engine

File: src/features/documents/services/recommendationEngine.ts

Contextual Recommendations

The engine suggests relevant documents based on the user’s current context:
ContextRecommendation Type
Viewing a grantRelated compliance documents, budget narratives
Expense submissionReceipt templates, policy documents
Report generationSupporting evidence, data attachments
Project milestoneDeliverable templates, completion certificates

Gap Analysis

Component: GapAnalysisWidget Identifies missing or expired documents:
  • Required documents per grant/project that haven’t been uploaded
  • Compliance certificates approaching expiry
  • Missing audit trail documentation
  • Incomplete funder requirement checklists

Folder System

File: src/features/documents/services/documentFolderService.ts

Smart Folders

Auto-generated folder structure based on organizational context:
Organization Documents/
├── By Project/
│   ├── {Project Name}/
│   │   ├── Proposals/
│   │   ├── Reports/
│   │   └── Financial/
├── By Grant/
│   ├── {Grant Name}/
│   │   ├── Application/
│   │   ├── Compliance/
│   │   └── Closeout/
├── Compliance/
│   ├── Policies/
│   ├── Certifications/
│   └── Audit Reports/
└── Templates/

Access Control

Folder permissions inherit from the organization’s RBAC:
  • VIEW_DOCUMENTS — Read access to documents
  • UPLOAD_DOCUMENTS — Create/upload documents
  • MANAGE_DOCUMENTS — Edit metadata, move, approve
  • DELETE_DOCUMENTS — Soft-delete and archive

UI Components

ComponentDescription
DocumentBrowserMain document explorer with grid/list views
DocumentCardDocument preview card with classification badge
SmartUploadDropzoneAI-powered upload with classification preview
ClassificationConfirmModalReview and confirm AI classification
GapAnalysisWidgetMissing/expired document dashboard widget
DocumentVersionHistoryVersion timeline and comparison

Hooks

HookPurpose
useDocumentBrainMain context hook (CRUD, search, filters)
useCurrentFolderDocumentsDocuments in the active folder
useDocumentStatsAggregate statistics (counts, types, statuses)

Data Model

LibraryDocument

interface LibraryDocument {
  id: string;
  organizationId: string;
  title: string;
  description?: string;
  documentType: DocumentType;
  status: 'draft' | 'review' | 'approved' | 'archived';
  folderId?: string;
  tags: string[];
  fileUrl: string;
  fileSize: number;
  mimeType: string;
  versions: DocumentVersion[];
  classification?: ClassificationResult;
  relatedProjectId?: string;
  relatedGrantId?: string;
  uploadedBy: string;
  createdAt: string;
  updatedAt: string;
}

Key Files Reference

FilePurpose
src/features/documents/index.tsBarrel export (services, context, types, components)
src/features/documents/services/documentBrainService.tsCore CRUD, search, versioning
src/features/documents/services/documentClassificationService.tsAI classification via Gemini 2.0 Flash
src/features/documents/services/recommendationEngine.tsContextual document suggestions
src/features/documents/services/documentFolderService.tsSmart folder management
src/features/documents/DocumentBrainContext.tsxReact context provider
src/features/documents/components/DocumentBrowser.tsxMain document explorer
src/features/documents/components/SmartUploadDropzone.tsxAI upload component