Framework Architecture
ERPNext follows a modular, metadata-driven architecture that separates business logic from the framework layer.Application Layer
ERPNext is organized into modules (Accounts, Stock, Selling, Buying, Manufacturing, etc.) that contain business logic and domain-specific functionality.
Framework Layer
Frappe Framework provides the foundation: ORM, routing, authentication, background jobs, websockets, and API infrastructure.
Core Architectural Patterns
1. Metadata-Driven Design
ERPNext uses JSON metadata files to define DocTypes (data models). The framework reads these definitions and generates database tables, forms, and APIs automatically.2. Controller Pattern
Each DocType has a corresponding Python controller class that inherits fromDocument or specialized controllers.
3. Module Structure
ERPNext follows a consistent directory structure:Document Lifecycle
Understanding the document lifecycle is crucial for implementing business logic:Document States
Document States
Document Events
Framework provides hooks at every stage of document lifecycle:API Architecture
Whitelisted Methods
Expose server-side methods as REST/RPC endpoints:Permission System
Role-based permissions are defined in DocType metadata and enforced automatically:Regional Customization
ERPNext supports region-specific overrides without modifying core code:Performance Patterns
ERPNext includes several patterns for optimal performance:
- Caching:
frappe.cache()for frequently accessed data - Background Jobs: Use
frappe.enqueue()for long-running tasks - Query Optimization: Use
qb(query builder) instead of raw SQL - Batch Processing: Process large datasets in chunks
Query Builder Example
Key Utilities
Database Operations
Validation Helpers
Next Steps
DocType System
Learn how to create and customize DocTypes
Hooks
Extend ERPNext using hooks
Testing
Write tests for your customizations
API Reference
Explore the complete API