InsightPro - System Architecture
Complete technical documentation of the refactored system
Core Principle: SSOT in RequestInsights
The RequestInsights page maintains the single source of truth (projectData state) throughout the entire multi-step creation process. All child components receive this data as props and update it through callbacks.
Step 1: User Input
User interacts with step components (QuickStep1_Materials, etc.)
Step 2: Local State Collection
Component collects all form data in local state, validates it
Step 3: Submit to Hook
Component calls onNext(stepData) which triggers useProjectFormSteps.handleStepComplete()
Step 4: Backend Persistence
Hook calls saveProjectStep() function to persist data in database
Step 5: State Update
Backend returns complete project object, hook updates projectData state via setProjectData()
Step 6: Navigation
Hook advances to next step, new component receives updated projectData
Location: components/request/hooks/useProjectFormSteps.js
Responsibilities:
- Manage current step state
- Handle backend communication via saveProjectStep()
- Update projectData state after successful saves
- Manage loading and error states
- Provide navigation between steps
- Prevent duplicate project creation
Key Features:
- Auto-save: Every step completion saves to database
- Resume capability: Users can leave and return without losing progress
- URL synchronization: Project ID in URL updates automatically
- Error recovery: Failed saves can be retried without data loss
saveProjectStep
Handles project creation and updates with step-by-step validation
POST /functions/saveProjectStep
Body: { projectId?, stepNumber, stepData }
Features:
- Step-specific validation logic
- Automatic create vs update detection
- Permission checking for organizations
- current_step tracking for resume capability
signNDA
Handles NDA signature with legal binding and audit trail
POST /functions/signNDA
Body: { projectId, fullName, ndaType }
Security Features:
- IP address tracking
- User agent logging
- Timestamp with timezone
- Duplicate signature prevention
submitFeedback
Processes expert feedback submission with validation
POST /functions/submitFeedback
Body: { projectId, feedbackData }
Validation:
- NDA signature verification
- Required comments checking
- Survey response validation
- Automatic project status updates
Critical Design Decision
State Machine Pattern
The expert workflow uses a finite state machine with these states:
• LOADING → Fetching initial data
• INITIAL_LANDING → Not authenticated
• ACCEPT_PENDING → Needs to accept project
• NDA_PENDING → Needs to sign NDA
• FEEDBACK_PENDING → Ready to submit feedback
• FEEDBACK_SUBMITTED → Complete
State Transition Flow
- User performs action (accept, sign NDA, submit feedback)
- Backend function processes action and updates database
- Success callback triggers initializeWorkflow()
- initializeWorkflow() re-evaluates state based on fresh data
- Component re-renders with new state - NO RELOAD
Shared Components
• components/request/shared/NdaStep.js
• components/request/shared/SessionSetupStep.js
→ Reused across both Quick & In-Depth paths
Path-Specific Components
Quick Path:
• components/request/quick/QuickStep1_Materials.js
• components/request/quick/QuickStep4_Payment.js
• components/request/quick/QuickStep5_ExpertSelection.js
Prototype Path:
• components/request/prototype/PrototypeStep1_Materials.js
• components/request/prototype/PrototypeStep4_Payment.js
• components/request/prototype/PrototypeStep5_ExpertSelection.js
Expert Workflow Components
• components/expert/workflow/ExpertProgressTracker.js
• components/expert/workflow/ProjectDetailsCard.js
• components/expert/workflow/ExpertAcceptanceFlow.js
• components/expert/workflow/ExpertFeedbackSubmission.js
✅ Before Issues
- • Duplicate project creation
- • Data inconsistencies
- • Lost progress on refresh
- • window.location.reload() everywhere
- • No validation consistency
✨ After Solutions
- • Single source of truth
- • Centralized state management
- • Auto-save with resume
- • Zero page reloads
- • Backend validation layer
