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
| Status | Updated | Covered Files |
|---|
| 🟢 Stable | 2026-02-22 | features/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
- Upload: User drops file into
SmartUploadDropzone
- Extract: Text extraction from PDF, DOCX, images (OCR)
- Classify: Gemini 2.0 Flash analyzes content and suggests document type + metadata
- Confirm: User reviews classification via
ClassificationConfirmModal
- Store: Document saved with verified classification and metadata
Document Types (40+)
Organized by domain:
| Domain | Example Types |
|---|
| Grant | Proposal, Award Letter, Budget Narrative, Modification Request |
| Financial | Invoice, Receipt, Audit Report, Bank Statement |
| Compliance | Policy Document, Certification, License, Insurance |
| HR | Contract, Resume, Performance Review, Training Certificate |
| Project | Work Plan, Progress Report, Deliverable, Meeting Minutes |
| Legal | MOU, 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
| State | Description |
|---|
draft | Initial state, editable |
review | Submitted for approval, read-only |
approved | Approved, version-locked |
archived | Soft-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:
| Context | Recommendation Type |
|---|
| Viewing a grant | Related compliance documents, budget narratives |
| Expense submission | Receipt templates, policy documents |
| Report generation | Supporting evidence, data attachments |
| Project milestone | Deliverable 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
| Component | Description |
|---|
DocumentBrowser | Main document explorer with grid/list views |
DocumentCard | Document preview card with classification badge |
SmartUploadDropzone | AI-powered upload with classification preview |
ClassificationConfirmModal | Review and confirm AI classification |
GapAnalysisWidget | Missing/expired document dashboard widget |
DocumentVersionHistory | Version timeline and comparison |
Hooks
| Hook | Purpose |
|---|
useDocumentBrain | Main context hook (CRUD, search, filters) |
useCurrentFolderDocuments | Documents in the active folder |
useDocumentStats | Aggregate 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
| File | Purpose |
|---|
src/features/documents/index.ts | Barrel export (services, context, types, components) |
src/features/documents/services/documentBrainService.ts | Core CRUD, search, versioning |
src/features/documents/services/documentClassificationService.ts | AI classification via Gemini 2.0 Flash |
src/features/documents/services/recommendationEngine.ts | Contextual document suggestions |
src/features/documents/services/documentFolderService.ts | Smart folder management |
src/features/documents/DocumentBrainContext.tsx | React context provider |
src/features/documents/components/DocumentBrowser.tsx | Main document explorer |
src/features/documents/components/SmartUploadDropzone.tsx | AI upload component |