Recommended File Structure
We recommend creating a dedicatedcedar/
folder at the same level as your app/
directory (in Next.js projects) or equivalent in other frameworks:
Configuration Philosophy
The core principle is that configuration should be centralized, but logic can live wherever it makes business sense.β Recommended Pattern
- Define all Cedar configurations in the
cedar/
folder - Import and pass configuration objects directly to
CedarCopilot
during initialization - Keep configuration objects in dedicated files for better organization and debugging
β Anti-Pattern: Hooks Everywhere
We discourage using hooks scattered throughout your application for Cedar configuration because:- Components may mount at unexpected times
- Harder to trace the source of bugs
- Reduced observability for new developers
- Inconsistent initialization timing
Exception: State-Related Functionality
The centralized configuration pattern has one important exception: state-related functionality must be defined where the state lives. When registering state with Cedar, this must happen in the component code that owns that state:Benefits of This Approach
- Better Debugging: All Cedar configuration is in one predictable location
- Improved Observability: New team members know exactly where to look for Cedar setup
- Consistent Initialization: Configuration is passed directly during component initialization
- Easier Maintenance: Changes to Cedar behavior are centralized and easier to track
Getting Started
- Create a
cedar/
folder in your project root - Move your Cedar configurations into dedicated files within this folder
- Import these configurations and pass them directly to
CedarCopilot
- Keep state registration in component code where the state is defined