Docs
Complete guide to understanding and using Derived for code generation
Derived Documentation
What is Derived?
Derived is a desktop application that helps developers generate code quickly and efficiently using templates. Think of it as a powerful code scaffolding tool with a user-friendly interface, live preview, and zero setup required.
Core Concepts
Templates
Templates are text files with placeholders that generate code based on your input data. For example, a template with {{.name}}Controller
and input {"name": "user"}
generates userController
in your code.
Blocks
A block is a collection of templates that creates a complete module or feature. Examples include:
- Authentication system
- CRUD operations
- Email service
- User management
Each block can have:
- Multiple templates with specific file paths
- Optional JSON input that templates can reference
- Public or private visibility
Block Categories
Blocks are organized into categories for better structure and discoverability. Categories help you:
- Organize blocks logically - Group related functionality together
- Find blocks quickly - Browse by category instead of searching through all blocks
- Maintain structure - Keep your workspace organized as you create more blocks
Common category examples:
- Backend - API controllers, services, database models
- Frontend - Components, pages, utilities
- DevOps - Docker files, CI/CD configurations
- Documentation - README templates, API docs
- Authentication - Login systems, user management
- Database - Migrations, seeders, queries
When creating a block, you can assign it to an existing category or create a new one, making it easier for you and your team to find and reuse blocks later.
Projects
Projects link your blocks to a local directory on your computer. Once linked, this becomes the root directory where your generated code will be placed.
Template Syntax
Derived uses a powerful templating syntax that allows you to create dynamic, reusable code templates.
Accessing Data
Access JSON data using the {{ .key }}
syntax:
Nested Data
Access nested properties using dot notation:
Loops
Loop through arrays using {{ range .key }}
:
Accessing Parent Context in Loops
Use $.
to access parent context inside loops:
Conditional Statements
Use if
statements for conditional logic:
Built-in Functions
Transform your data using built-in functions:
Using the Template Editor
Creating Templates
- Select your project from the top-left dropdown
- Create a new template using the 'Add new template' button
- Choose template type:
- Add: Creates a new file
- Modify: Modifies an existing file using identifiers
Template Types
Add Templates
Creates entirely new files in your project:
Modify Templates
Modifies existing files using identifiers (comments in your code):
Existing file (routes.ts
):
Template with identifier // Add routes here
:
Result:
File Paths with Variables
Use template variables in file paths for dynamic file generation:
Key Features
Live Preview
See your generated code in real-time as you write templates and modify input data. This helps you:
- Verify template logic immediately
- Test different input scenarios
- Debug template issues quickly
Error Detection
Derived automatically detects and highlights:
- Invalid template syntax
- Missing data references
- JSON formatting errors
Auto-completion
Get intelligent suggestions for:
- Available data properties
- Built-in functions
- Template syntax
Folder Structure Preview
Visualize how your generated files will be organized in your project structure before creating them.
Getting Started
1. Create Your First Block
- Open Derived
- Create a new project and link it to your local directory
- Create a new block with a descriptive name
- Add your first template with a file path
2. Example: Simple React Component
Block Input:
Template (src/components/{{.componentName}}.tsx
):
3. Example: Backend CRUD Operations
Block Input:
Controller Template (src/controllers/{{camelCase .entity}}Controller.ts
):
Best Practices
1. Organize Your Blocks
- Use descriptive names for blocks and templates
- Group related templates in the same block
- Keep block inputs simple and well-documented
2. Template Design
- Use clear, meaningful variable names
- Add comments to explain complex template logic
- Test with various input scenarios
3. File Organization
- Use consistent naming conventions
- Organize generated files in logical directory structures
- Consider existing project conventions
4. Data Structure
- Keep JSON inputs flat when possible
- Use arrays for repeating elements
- Validate your JSON before using it in templates
Common Use Cases
- API Development: Generate controllers, services, and routes
- Frontend Components: Create React/Vue/Angular components
- Database Models: Generate entity classes and migrations
- Configuration Files: Create environment-specific configs
- Documentation: Generate API docs and README files
- Admin Panels: Create CRUD interfaces for data management
Tips for Success
- Start Small: Begin with simple templates and gradually add complexity
- Use Live Preview: Take advantage of real-time feedback while developing
- Share Blocks: Create public blocks for common patterns your team uses
- Iterate: Refine your templates based on actual usage and feedback
- Leverage Functions: Use built-in functions like
camelCase
andsnakeCase
for consistent naming
Derived makes code generation accessible and powerful, helping you focus on what matters most - building great software efficiently.