Interfaces
Interfaces provide reusable field configurations that can be shared across multiple collections in TrackVision AI. They ensure consistency, reduce duplication, and simplify maintenance of common field patterns.
What are Interfaces?
An interface is a predefined set of fields with their configurations that can be applied to multiple collections. When you apply an interface to a collection, all the fields from that interface are automatically added to the collection with their specified properties and validation rules.
System Interfaces
TrackVision AI includes several built-in interfaces that provide standard functionality across collections.
User Created
Tracks which user created each item and when it was created.
Fields:
user_created: Reference to the creating user (UUID)date_created: Timestamp of creation (DateTime)
Usage:
{
"collection": "products",
"interfaces": ["user_created"]
}
User Updated
Tracks which user last modified each item and when.
Fields:
user_updated: Reference to the last updating user (UUID)date_updated: Timestamp of last modification (DateTime)
Usage:
{
"collection": "products",
"interfaces": ["user_updated"]
}
Sort
Enables manual ordering of collection items.
Fields:
sort: Integer field for custom sorting (Integer)
Usage:
{
"collection": "menu_items",
"interfaces": ["sort"]
}
Archive
Provides soft deletion functionality without permanently removing data.
Fields:
status: Item status - published, draft, archived (String)archived: Boolean flag for archived state (Boolean)
Usage:
{
"collection": "articles",
"interfaces": ["archive"]
}
Custom Interfaces
Create your own interfaces for common field patterns used across multiple collections.
Address Interface
Reusable address fields for locations, contacts, and shipping.
{
"name": "address",
"description": "Standard address fields",
"fields": [
{
"field": "street_address",
"type": "string",
"required": true,
"width": "full"
},
{
"field": "city",
"type": "string",
"required": true,
"width": "half"
},
{
"field": "state_province",
"type": "string",
"width": "quarter"
},
{
"field": "postal_code",
"type": "string",
"width": "quarter"
},
{
"field": "country",
"type": "string",
"required": true,
"default_value": "US",
"width": "half"
}
]
}
Contact Information Interface
Common contact fields for people and organizations.
{
"name": "contact_info",
"description": "Standard contact information fields",
"fields": [
{
"field": "email",
"type": "string",
"validation": {
"format": "email"
},
"width": "half"
},
{
"field": "phone",
"type": "string",
"validation": {
"format": "phone"
},
"width": "half"
},
{
"field": "website",
"type": "string",
"validation": {
"format": "url"
},
"width": "full"
}
]
}
SEO Metadata Interface
Search engine optimization fields for content collections.
{
"name": "seo_meta",
"description": "SEO metadata fields",
"fields": [
{
"field": "meta_title",
"type": "string",
"note": "Recommended length: 50-60 characters",
"validation": {
"max_length": 60
}
},
{
"field": "meta_description",
"type": "text",
"note": "Recommended length: 150-160 characters",
"validation": {
"max_length": 160
}
},
{
"field": "meta_keywords",
"type": "string",
"note": "Comma-separated keywords"
},
{
"field": "canonical_url",
"type": "string",
"validation": {
"format": "url"
}
}
]
}
Interface Management
Creating Interfaces
Interfaces can be created through:
- Admin Interface: Visual interface builder
- API Endpoints: REST or GraphQL mutations
- Configuration Files: JSON schema definitions
- Database Migrations: Programmatic creation
Applying Interfaces
Apply interfaces to collections during creation or modification:
{
"collection": "blog_posts",
"interfaces": [
"user_created",
"user_updated",
"seo_meta",
"archive"
],
"fields": [
{
"field": "title",
"type": "string",
"required": true
},
{
"field": "content",
"type": "text",
"required": true
}
]
}
Updating Interfaces
When you update an interface definition:
- Changes propagate to all collections using that interface
- Field additions are applied automatically
- Field removals require manual confirmation
- Type changes may require data migration
Interface Inheritance
Multiple Interfaces
Collections can implement multiple interfaces:
{
"collection": "products",
"interfaces": [
"user_created",
"user_updated",
"sort",
"archive",
"seo_meta"
]
}
Interface Conflicts
If multiple interfaces define the same field name:
- Last applied interface takes precedence
- Manual field definitions override interface fields
- Validation rules are merged when compatible
Field Overrides
Override interface field properties in collection definition:
{
"collection": "products",
"interfaces": ["address"],
"fields": [
{
"field": "country",
"default_value": "CA",
"note": "Products ship from Canada"
}
]
}
Best Practices
Interface Design
- Single Responsibility: Each interface should serve one clear purpose
- Logical Grouping: Group related fields together
- Naming Convention: Use descriptive, consistent names
- Documentation: Provide clear descriptions and usage examples
Field Configuration
- Sensible Defaults: Provide reasonable default values
- Appropriate Validation: Include necessary validation rules
- User Experience: Consider field widths and grouping
- Performance: Avoid unnecessary complex field types
Maintenance
- Version Control: Track interface changes over time
- Impact Analysis: Understand which collections use each interface
- Migration Planning: Plan data migrations for breaking changes
- Testing: Test interface changes across all using collections
Reusability
- Generic Design: Make interfaces flexible for multiple use cases
- Optional Fields: Use required sparingly to maximize reusability
- Conditional Logic: Implement smart defaults and conditional requirements
- Documentation: Provide usage guidelines and examples
Migration Considerations
When modifying interfaces that are already in use:
Safe Changes
- Adding optional fields
- Updating field descriptions or notes
- Adding validation rules (if data already complies)
- Changing display properties (width, grouping)
Breaking Changes
- Removing fields
- Changing field types
- Adding required fields
- Modifying validation rules
Migration Strategy
- Assessment: Identify all collections using the interface
- Data Analysis: Check existing data compatibility
- Backup: Create data backups before changes
- Gradual Rollout: Apply changes incrementally
- Validation: Verify data integrity after migration