Skip to content

Smart Document Organization Rules #232

@adriandarian

Description

@adriandarian

Description

Implement smart automation rules that automatically organize documents based on content, metadata, and usage patterns. Rules can auto-move files to folders, apply tags, and suggest organization improvements.


Objectives

  1. Create rule engine for document organization
  2. Define rule types (move, tag, rename, etc.)
  3. Implement condition matching
  4. Add rule templates
  5. Enable/disable rules individually
  6. Track rule execution history
  7. Suggest rules based on patterns

Rule Types

1. Auto-Move Rules

Move documents to folders based on conditions:

  • By Type: "Move all resumes to 'Resumes' folder"
  • By Company: "Move documents linked to Google applications to 'Google' folder"
  • By Date: "Move documents older than 1 year to 'Archive' folder"
  • By Size: "Move large files (>5MB) to 'Large Files' folder"

2. Auto-Tag Rules

Apply tags automatically:

  • By Content: "Tag documents containing 'React' with 'frontend'"
  • By Filename: "Tag files with 'cover_letter' in name with 'cover-letter'"
  • By Link: "Tag documents linked to 'Software Engineer' positions with 'engineering'"

3. Auto-Rename Rules

Standardize filenames:

  • Pattern: "Rename to: [Company][Position][Type]_[Date].pdf"
  • Clean: "Remove special characters and extra spaces"
  • Normalize: "Convert to lowercase/UPPERCASE/Title Case"

4. Duplicate Detection

Find and manage duplicates:

  • By Content Hash: Exact duplicates
  • By Name: Similar filenames
  • By Metadata: Same file info
  • Action: Keep newest, delete oldest, or prompt

5. Suggestion Rules

Suggest organization improvements:

  • "This document might belong in 'Tech Companies' folder"
  • "Consider tagging with 'senior-role'"
  • "Similar documents are tagged with 'javascript'"

Rule Structure

interface OrganizationRule {
  id: string;
  name: string;
  description: string;
  type: 'move' | 'tag' | 'rename' | 'duplicate' | 'suggest';
  enabled: boolean;
  conditions: RuleCondition[];
  actions: RuleAction[];
  priority: number; // 1-10
  createdAt: Date;
  lastRun?: Date;
  executionCount: number;
}

interface RuleCondition {
  field: 'name' | 'type' | 'size' | 'date' | 'content' | 'linkedApps';
  operator: 'equals' | 'contains' | 'matches' | 'greaterThan' | 'lessThan';
  value: any;
}

interface RuleAction {
  type: 'move' | 'tag' | 'rename' | 'delete' | 'notify';
  target?: string; // folder ID, tag name, etc.
  pattern?: string; // for rename
}

Example Rules

Rule 1: Organize Resumes by Company

{
  name: "Sort resumes by company",
  type: "move",
  conditions: [
    { field: "type", operator: "equals", value: "resume" },
    { field: "linkedApps", operator: "exists", value: true }
  ],
  actions: [
    { 
      type: "move", 
      target: "folder:resumes/{company}" 
    }
  ]
}

Rule 2: Auto-tag Tech Documents

{
  name: "Tag technical documents",
  type: "tag",
  conditions: [
    { 
      field: "content", 
      operator: "contains", 
      value: ["JavaScript", "Python", "React", "Node"] 
    }
  ],
  actions: [
    { type: "tag", target: "technical" },
    { type: "tag", target: "engineering" }
  ]
}

Rule 3: Archive Old Documents

{
  name: "Archive documents older than 1 year",
  type: "move",
  conditions: [
    { field: "date", operator: "lessThan", value: "1 year ago" },
    { field: "linkedApps", operator: "exists", value: false }
  ],
  actions: [
    { type: "move", target: "folder:archive" },
    { type: "tag", target: "archived" }
  ]
}

Rule Templates

Pre-built Templates

  1. Resume Organization: Sort resumes by role type
  2. Company Filing: Organize by company name
  3. Date-based Archive: Move old files to archive
  4. Duplicate Cleanup: Find and remove duplicates
  5. Tag by Content: Auto-tag based on keywords

Users can:

  • Use template as-is
  • Customize template
  • Create from scratch
  • Share custom templates

UI Components

Rule Manager

┌─ Smart Organization Rules ──────────────────┐
│  [+ Create Rule]  [📋 Templates]            │
├──────────────────────────────────────────────┤
│  ✅ Sort resumes by company (Auto-Move)     │
│     Executed 45 times • Last run: Today     │
│     [Edit] [Disable] [Delete]               │
│                                              │
│  ✅ Tag technical documents (Auto-Tag)      │
│     Executed 123 times • Last run: Today    │
│     [Edit] [Disable] [Delete]               │
│                                              │
│  ⏸️  Archive old documents (Auto-Move)      │
│     Never executed • Disabled               │
│     [Edit] [Enable] [Delete]                │
└──────────────────────────────────────────────┘

Rule Editor

┌─ Create Rule ────────────────────────────────┐
│  Name: Sort resumes by company              │
│  Type: [Auto-Move ▼]                        │
│                                              │
│  Conditions (ALL must match)                │
│  ┌────────────────────────────────────────┐ │
│  │ Document type [equals ▼] [Resume ▼]   │ │
│  │ Linked to apps [exists ▼]             │ │
│  │ [+ Add Condition]                      │ │
│  └────────────────────────────────────────┘ │
│                                              │
│  Actions                                    │
│  ┌────────────────────────────────────────┐ │
│  │ Move to folder: [Resumes/{company}]   │ │
│  │ [+ Add Action]                         │ │
│  └────────────────────────────────────────┘ │
│                                              │
│  [Test Rule] [Save] [Cancel]                │
└──────────────────────────────────────────────┘

Requirements

  • Create rule data structure
  • Build rule engine/executor
  • Implement condition matching
  • Implement actions (move, tag, rename)
  • Create rule templates
  • Build rule manager UI
  • Build rule editor UI
  • Add rule testing feature
  • Track execution history
  • Add rule suggestions based on patterns
  • Implement batch execution
  • Add undo for rule actions

Acceptance Criteria

  • Can create custom rules
  • Can use rule templates
  • Rules execute correctly
  • Conditions match accurately
  • Actions perform as expected
  • Can enable/disable rules
  • Execution history tracked
  • Can test rules before applying
  • Batch execution works
  • Can undo rule actions
  • Rule suggestions are helpful
  • Performance acceptable (rules don't slow app)

Technical Details

Files to Create

  • src/types/rules.ts
  • src/lib/ruleEngine.ts
  • src/lib/ruleExecutor.ts
  • src/lib/ruleMatcher.ts
  • src/lib/ruleTemplates.ts
  • src/stores/ruleStore.ts
  • src/components/rules/RuleManager.tsx
  • src/components/rules/RuleEditor.tsx
  • src/components/rules/RuleTemplates.tsx
  • src/hooks/useRules.ts

Execution Strategy

  • Manual: User triggers rule execution
  • Auto on Upload: Run rules when document added
  • Auto on Link: Run rules when document linked
  • Scheduled: Run rules daily/weekly
  • On Demand: Run specific rule on specific documents

Testing Plan

  • Unit tests for rule engine
  • Test condition matching accuracy
  • Test each action type
  • Test rule templates
  • Test with 100+ documents
  • Test batch execution
  • Test undo functionality
  • E2E test for rule workflow

Success Metrics

  • Adoption: >40% users create rules
  • Automation: 50% of document organization automated
  • Time Saved: 30 minutes per user per month
  • Accuracy: >95% correct rule executions
  • Satisfaction: 4.5/5 rating

Related Tasks


Notes

  • Rules should be non-destructive by default
  • Add "what would this rule do?" preview
  • Consider ML for pattern recognition in future
  • May need rule versioning/history

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions