Feature Configuration
The template uses a feature flag system to gracefully enable or disable functionality based on system configuration. This allows the application to work without a database (serving static content only) while progressively enabling features as infrastructure becomes available.
Feature Flags Module
The feature flags are defined in lib/config/feature-flags.ts.
FeatureFlags Interface
interface FeatureFlags {
/** User ratings and reviews functionality */
ratings: boolean;
/** User comments on items */
comments: boolean;
/** User favorite items collection */
favorites: boolean;
/** Admin-managed featured items display */
featuredItems: boolean;
/** User surveys and feedback collection */
surveys: boolean;
}
How Flags Are Determined
All current features depend on database availability. A feature is enabled when DATABASE_URL is configured:
export function getFeatureFlags(): FeatureFlags {
const isDatabaseConfigured = Boolean(process.env.DATABASE_URL);
return {
ratings: isDatabaseConfigured,
comments: isDatabaseConfigured,
favorites: isDatabaseConfigured,
featuredItems: isDatabaseConfigured,
surveys: isDatabaseConfigured,
};
}
This design allows the template to serve content from the Git-based CMS without any database, while database-dependent interactive features (ratings, comments, favorites) are disabled automatically.
Utility Functions
The module provides several helper functions:
// Check a single feature
import { isFeatureEnabled } from '@/lib/config/feature-flags';
if (isFeatureEnabled('comments')) {
// Render comments component
}
// Get all enabled features
import { getEnabledFeatures } from '@/lib/config/feature-flags';
const enabled = getEnabledFeatures();
// e.g., ['ratings', 'comments', 'favorites', 'featuredItems', 'surveys']
// Get all disabled features (useful for debugging)
import { getDisabledFeatures } from '@/lib/config/feature-flags';
const disabled = getDisabledFeatures();
// Check if everything is ready
import { areAllFeaturesEnabled } from '@/lib/config/feature-flags';
if (areAllFeaturesEnabled()) {
console.log('Full platform is operational');
}
Full API Reference
| Function | Returns | Description |
|---|---|---|
getFeatureFlags() | FeatureFlags | All flags as a boolean object |
isFeatureEnabled(name) | boolean | Check a single feature by name |
getEnabledFeatures() | string[] | Array of enabled feature names |
getDisabledFeatures() | string[] | Array of disabled feature names |
areAllFeaturesEnabled() | boolean | True if every feature is enabled |