doctype-schema-expert
DocType Schema Expert
This skill provides comprehensive guidance for working with Frappe DocType schemas, their JSON structure, field definitions, and best practices.
Overview
DocTypes are the fundamental building blocks of a Frappe application. Each DocType defines:
- Database Table Structure: Fields and their types
- UI Form Layout: How data is displayed and edited
- Business Logic: Controllers and validation rules
- Permissions: Who can access and modify data
Every DocType is defined by a JSON file (e.g., doctype_name.json) that specifies the complete schema.
Note: Custom DocTypes created via the UI do not have a .json file on disk. Their definition is stored in the database only. Standard DocTypes (shipped with apps) have JSON files in the codebase.
Quick Reference
Core DocType Properties
Essential properties that define a DocType's behavior:
- doctype: Always "DocType"
- name: The DocType name (e.g., "Sales Order")
- module: Module this DocType belongs to
- istable: Set to 1 for child tables (used in Table fields)
- issingle: Set to 1 for single doctypes (no table, one instance only)
- is_submittable: Set to 1 to enable Submit/Cancel workflow
- is_tree: Set to 1 for hierarchical/tree structures
- editable_grid: Set to 1 for inline editing in child tables
- custom: Set to 1 for custom doctypes
- fields: Array of field definitions
- permissions: Array of permission definitions
Field Types Categories
Data Fields (store values):
- Text:
Data,Text,Small Text,Long Text,Code,Text Editor,HTML Editor,Markdown Editor - Numeric:
Int,Long Int,Float,Currency,Percent - Date/Time:
Date,Datetime,Time,Duration - Special:
Link,Dynamic Link,Select,Check,Attach,Attach Image,JSON,Password,Color,Barcode,Geolocation,Rating,Signature,Phone,Autocomplete,Icon,Read Only
Layout Fields (UI structure only):
Section Break,Column Break,Tab Break,HTML,Button,Image,Fold,Heading
Relationship Fields:
Table: Child table (one-to-many)Table MultiSelect: Multiple selection from child tableLink: Foreign key to another DocTypeDynamic Link: Foreign key determined by another field
Common Tasks
Creating a New DocType
- Create JSON file:
frappe/module_name/doctype/doctype_name/doctype_name.json - Define basic structure with required properties
- Add fields in the
fieldsarray - Define permissions in the
permissionsarray - Run
bench migrateto create database table
See references/doctype-structure.md for complete structure.
Adding Fields
Add field objects to the fields array with these essential properties:
{
"fieldname": "field_name",
"fieldtype": "Data",
"label": "Field Label",
"reqd": 0,
"hidden": 0,
"read_only": 0
}
See references/field-types.md for all field types and their properties.
Child Tables
Child tables require:
- Parent DocType: Field with
fieldtype: "Table"andoptionspointing to child DocType - Child DocType: Set
istable: 1and include parent tracking fields
The framework automatically adds parent, parenttype, and parentfield fields to child tables.
Single DocTypes
Single doctypes (settings, configurations) have only one instance:
- Set
issingle: 1 - Data stored in
tabSinglestable, not a dedicated table - No
namefield needed (automatically set to DocType name) - Cannot be renamed or have multiple instances
Reference Files
For detailed information on specific topics:
Structure and Properties
- references/doctype-structure.md: Complete DocType JSON structure with all properties
- references/field-types.md: All field types with descriptions and use cases
- references/field-properties.md: All field properties and their effects
Best Practices
- references/naming-conventions.md: Naming rules for DocTypes, fields, and fieldnames
- references/best-practices.md: Schema design patterns and recommendations
Common Patterns
- references/common-patterns.md: Frequently used DocType patterns and configurations
Key Principles
- Naming: Use PascalCase for DocType names, snake_case for fieldnames
- Required Fields: Mark mandatory fields with
reqd: 1 - Field Order: Use
field_orderarray to control field sequence - Layout: Use Section/Column Breaks for organized forms
- Validation: Set properties like
unique,non_negative,precisionfor data integrity - Performance: Add
search_index: 1to frequently queried fields - User Experience: Use appropriate field types and provide helpful labels/descriptions
Standard Fields
Every DocType automatically includes these fields (don't add manually):
name: Unique identifierowner: User who created the documentcreation: Creation timestampmodified: Last modification timestampmodified_by: User who last modifieddocstatus: Document status (0=Draft, 1=Submitted, 2=Cancelled)idx: Index for sorting
Optional fields (added automatically when used):
_user_tags: User tags_comments: Comments_assign: Assigned users_liked_by: Users who liked_seen: Users who viewed
Usage
When working with DocType schemas:
- Identify the task: Creating new DocType, modifying existing, adding fields, etc.
- Reference appropriate guide: Use reference files for detailed information
- Follow conventions: Adhere to naming and structure guidelines
- Validate schema: Ensure all required properties are present
- Test changes: Run migrations and verify functionality
Important Notes
- JSON files must be valid JSON (use double quotes, no trailing commas)
- Changes to DocType schema require running
bench migrate - Renaming fields or changing field types can cause data loss
- Always backup before making schema changes
- Test schema changes in development before production
- Field names cannot be changed after data exists (requires migration)
More from kehwar/frappe_tweaks
frappe-tweaks-power-query-expert
Expert guidance for connecting Power Query (Power BI, Excel) to Frappe apps and reports. Use when building Power Query M code for Frappe data access, integrating Frappe reports with Power BI/Excel, implementing authentication for Power Query connections, handling heavy/long-running reports with report_long_polling API to avoid timeouts, applying column types and transformations, or troubleshooting Power Query caching and connection issues.
6open-observe-api-expert
Expert guidance for OpenObserve API integration in Frappe Tweaks. Use when creating, configuring, or troubleshooting OpenObserve API DocType, implementing send_logs() or search_logs() functionality, integrating with Server Scripts/Business Logic/Client-side code, debugging connection issues, or implementing logging, monitoring, error tracking, performance metrics, or audit trail use cases.
5frappe-ci-expert
Expert guidance for setting up CI/CD tests for Frappe apps. Use when users ask about GitHub Actions workflows, CI test setup, continuous integration for Frappe apps, running tests in CI environments, database setup for CI, bench configuration in CI, or automating tests for Frappe/ERPNext applications.
4workflow-expert
Expert guidance on Frappe Workflow system including workflow structure, states and transitions, workflow actions, email notifications, permission hooks (before_transition, after_transition, filter_workflow_transitions, has_workflow_action_permission), and best practices. Use when creating workflows, implementing workflow logic, understanding state transitions, working with workflow actions, configuring email notifications, or troubleshooting workflow-related issues.
4report-expert
Expert guidance on Frappe reports including report types, structure, creation workflow, and best practices. Use when creating standard script reports, query reports, understanding report structure, working with columns and filters, or troubleshooting report-related issues.
4api-reviewer
Security review and analysis for Frappe API endpoints decorated with @frappe.whitelist(). Use when reviewing API security, checking for permission vulnerabilities, scanning for unprotected endpoints, validating role restrictions, or auditing API endpoints for security best practices. Helps identify missing frappe.only_for(), frappe.has_permission(), or frappe.get_list() usage.
4