Facets Architecture Guide
This guide provides a comprehensive understanding of the Facets system in Infactory - a sophisticated rendering architecture that transforms structured data from query programs into interactive UI components.Overview
The Facets system is the heart of Infactory’s dynamic UI rendering. It creates a seamless bridge between backend data processing and frontend visualization, enabling intelligent, data-driven interfaces that adapt based on the type of data being displayed.High-Level Architecture
The Facets system follows a clear data flow from backend processing to frontend rendering:Core Concepts
1. Structured Data
Structured Data is the universal data format that flows through the Infactory system. It serves as the contract between backend and frontend, ensuring consistent data handling across language boundaries.Key Components:
-
Items: The actual data (DataFrames, scalars, dictionaries, lists)
- Keyed by store object names (e.g., “MAIN”, “RELATED”)
- Each item has a specific type defined in the data structure
-
Metadata: Additional information about the data
- Free-form dictionary with defined keys
- Contains result codes, IDs for streaming
- Includes rendering hints that determine facet selection
Implementation:
2. Streaming and Accumulation
The system supports real-time data streaming through an accumulator pattern:- Accumulator Pattern: Start with initial structured data, then accumulate changes
- Merge Logic: Both backend and frontend know how to merge overlays
- Incremental Updates: Send only changes, not full datasets
- Consistency: Guaranteed order and merge behavior
- Accumulator Pattern: Start with initial structured data, then accumulate changes
- Merge Logic: Both backend and frontend know how to merge overlays
- Incremental Updates: Send only changes, not full datasets
- Consistency: Guaranteed order and merge behavior
3. Rendering Hints
Rendering hints are the key mechanism for selecting which facet renders specific data:Facet System Architecture
Facet Compositions
Facet Compositions define how different facets work together for a specific use case:Key Elements:
- Workshop Variants: Different UI configurations for different use cases
- Modality: Determines the overall interaction pattern
- Tabs: Different request types and API templates
- Response Facets: Stack of facets for each rendering hint
Two Types of Facets
The Facets system has two distinct categories of components:1. Control Facets
Interactive components that can trigger API calls Characteristics:- Accept user input
- Issue API calls to backend
- Update dialog state
- Manage request/response cycle
2. Renderer Facets
Display components that visualize structured data Characteristics:- Parse and display structured data
- No direct API interaction
- Focus on visualization
- Support various data types
Facet Selection Process
The system automatically selects the appropriate facet based on data type:Dialog System
Architecture Overview
The Dialog system manages conversations and data flow:Dialog Components
Dialogues
- Represent complete conversations
- Belong to a project
- Contain multiple messages
- Track conversation state
Dialog Messages
- Individual messages in a dialogue
- Contains
sdjson
field with structured data - References a turn (User/Tool/Assistant)
- Ordered sequence
Dialog Turns
- User Turn: User’s input/question
- Tool Turn: API call or computation
- Assistant Turn: Results delivered to user
Modalities
Different ways to render and interact with dialogs:1. Chat Modality
2. Search Modality
3. Landing Page Modality (New)
Implementation Guide
File Structure
Key Directories:
base/
- Abstract base classes that all facets inherit fromimplementations/
- 20+ concrete facet implementations for specific data typesareas/
- High-level dialog view components that orchestrate facetsfacet-compositions.ts
- Central registry mapping variants to facet stacks
Creating a New Facet
Step 1: Define the Facet Class
Step 2: Register in Facet Compositions
Step 3: Set Rendering Hint in Query Program
Creating a New Modality
For implementing a new interaction pattern (like landing page):Step 1: Define the Modality
Step 2: Create Dialog View Component
Step 3: Update Page Component
Practical Examples
Example 1: Video Search Implementation
The video search feature demonstrates the complete facet flow:Example 2: Anonymous Session Handling
For landing pages with anonymous users:Best Practices
1. Facet Development
- Keep facets focused on single responsibility
- Use TypeScript types for structured data
- Handle loading and error states
- Implement proper cleanup in useEffect
2. Streaming Optimization
- Use accumulator pattern for large datasets
- Send minimal updates in streams
- Implement debouncing for rapid updates
- Handle connection interruptions gracefully
3. Modality Selection
- Chat: For conversational, multi-turn interactions
- Search: For query-response with history
- Landing Page: For public, anonymous access
4. Performance
- Lazy load heavy facets
- Use React.memo for expensive renders
- Implement virtual scrolling for large datasets
- Cache structured data when appropriate
Troubleshooting
Common Issues
Facet Not Rendering
- Check rendering hint matches exactly
- Verify facet is registered in composition
- Confirm workshop variant is correct
- Check structured data format
Streaming Not Working
- Verify accumulator initialization
- Check stream IDs match
- Ensure merge logic is correct
- Monitor WebSocket connection
Wrong Modality Display
- Verify modality in facet composition
- Check page component logic
- Ensure dialog state is correct
Advanced Topics
Custom Accumulator Logic
Dynamic Facet Loading
Cross-Facet Communication
Summary
The Facets architecture provides a powerful, flexible system for rendering dynamic UIs based on structured data. By understanding the flow from Query Programs through Structured Data to Facet rendering, developers can create sophisticated, data-driven interfaces that adapt intelligently to different types of content and user interactions. Key takeaways:- Structured Data is the universal format bridging backend and frontend
- Facets are either Controls (interactive) or Renderers (display)
- Modalities define overall interaction patterns
- The Dialog system manages conversation flow and state
- Facet Compositions tie everything together based on rendering hints