Frappe Framework Version 15 Create App: Complete Custom Application Development Guide
Creating custom applications in Frappe Framework Version 15 leverages the powerful bench new-app command to generate scaffolded project structures that integrate seamlessly with the framework’s architecture and development workflow.
Application Creation Prerequisites
Bench Environment Verification
Before creating applications in Frappe v15, ensure you’re operating within a properly initialized bench directory:
bash
# Verify bench directory status
bench find.
# Expected output:
# /home/frappe/frappe-bench is a bench directory!
Development Environment Preparation
Ensure developer mode is enabled for an optimal app development experience:
bash
# Enable developer mode globally
bench set-config -g developer_mode true
# Restart bench processes
bench restart
Creating Your First Frappe Application
Using the new-app Command
Generate a new Frappe application using the bench CLI with comprehensive configuration options:
bash
# Navigate to bench directory
cd frappe-bench/
# Create new application
bench new-app library_management
Application Configuration Prompts
The new-app command presents interactive prompts for application metadata configuration:
bash
App Title (default: Library Management):
App Description: Library Management System
App Publisher: Faris Ansari
App Email: faris@example.com
App Icon (default 'octicon octicon-file-directory'):
App Color (default 'grey'):
App License (default 'MIT'):
'library_management' created at /home/frappe/frappe-bench/apps/library_management
Configuration Options Explained:
- App Title: Display name shown in user interfaces
- App Description: Brief summary of application functionality
- App Publisher: Developer or organization name
- App Email: Contact email for support and communication
- App Icon: Octicon identifier for visual representation (see Primer Octicons)
- App Color: Theme color for application branding
- App License: Software license (MIT, GPL, Apache, etc.)
Automated Installation Process
After configuration, Frappe v15 automatically performs essential setup operations:
bash
Installing library_management
$ ./env/bin/pip install -q -U -e ./apps/library_management
$ bench build --app library_management
yarn run v1.22.4
$ FRAPPE_ENV=production node rollup/build.js --app library_management
Production mode
✔ Built js/moment-bundle.min.js
✔ Built js/libs.min.js
✨ Done in 1.95s.
Installation Steps Overview:
- Package Installation: Installs app as editable Python package in virtual environment
- Asset Building: Compiles JavaScript and CSS files for production use
- Dependency Resolution: Installs required Node.js and Python dependencies
- Apps.txt Registration: Adds application to bench’s application registry
Application Directory Structure Analysis
Complete Directory Layout
Frappe v15 generates a comprehensive directory structure optimized for modern web development:
text
apps/library_management/
├── README.md # Project documentation
├── library_management/ # Main source code directory
│ ├── hooks.py # Framework hooks configuration
│ ├── library_management/ # Application module
│ │ └── __init__.py # Module initialization
│ ├── modules.txt # Module definitions list
│ ├── patches.txt # Database migration patches
│ ├── public/ # Static assets directory
│ │ ├── css/ # Stylesheets
│ │ └── js/ # JavaScript files
│ ├── templates/ # Jinja2 template directory
│ │ ├── __init__.py # Template initialization
│ │ ├── includes/ # Reusable template components
│ │ └── pages/ # Page-specific templates
│ │ └── __init__.py # Page template initialization
│ └── www/ # Web pages directory
└── pyproject.toml # Modern Python package configuration
Critical Directory Functions
Source Code Organization (library_management/)
The main source directory contains the core application logic and framework integration points :
Key Components:
- Application Module: Contains DocTypes, controllers, and business logic
- Public Assets: Static files served directly by web server in production
- Templates: Jinja2 templates for custom web views and print formats
- WWW Directory: Web pages accessible via URL routing
Modern Package Configuration (pyproject.toml)
Frappe v15 exclusively uses pyproject.toml for Python package configuration, replacing legacy setup.py files:
text
[build-system]
requires = ["flit_core >=3.4,<4"]
build-backend = "flit_core.buildapi"
[project]
name = "library_management"
authors = [{name = "Faris Ansari", email = "faris@example.com"}]
description = "Library Management System"
requires-python = ">=3.10"
dynamic = ["version"]
dependencies = [
"frappe"
]
[project.optional-dependencies]
dev = ["frappe[dev]"]
[tool.bench.dev-dependencies]
watch = [
"library_management/**"
]
Framework Integration Through Hooks
Understanding Hooks Architecture
Hooks provide the primary mechanism for extending and customizing Frappe Framework functionality without modifying core code. The hooks.py file serves as the central configuration point for framework integration.
Essential Hook Configurations
Basic Application Hooks
Configure fundamental application properties and behavior:
python
# hooks.py
from . import __version__ as app_version
app_name = "library_management"
app_title = "Library Management"
app_publisher = "Faris Ansari"
app_description = "Library Management System"
app_email = "faris@example.com"
app_license = "MIT"
app_version = app_version
# Applications required for this app
required_apps = []
# Includes in <head>
# ------------------
# Include js, css files in header of desk.html
# app_include_css = "/assets/library_management/css/library_management.css"
# app_include_js = "/assets/library_management/js/library_management.js"
# Include js, css files in header of web template
# web_include_css = "/assets/library_management/css/library_management.css"
# web_include_js = "/assets/library_management/js/library_management.js"
# Include custom scss in every website theme (without file extension ".scss")
# website_theme_scss = "library_management/public/scss/website"
DocType and Controller Hooks
Define custom behavior for document lifecycle events :
python
# Document Events
# ---------------
# Hook on document methods and events
doc_events = {
"*": {
"on_update": "method",
"on_cancel": "method",
"on_trash": "method"
},
"Library Transaction": {
"before_submit": "library_management.library_management.doctype.library_transaction.library_transaction.validate_membership"
}
}
# Scheduled Tasks
# ---------------
scheduler_events = {
"all": [
"library_management.tasks.all"
],
"daily": [
"library_management.tasks.daily"
],
"hourly": [
"library_management.tasks.hourly"
],
"weekly": [
"library_management.tasks.weekly"
],
"monthly": [
"library_management.tasks.monthly"
]
}
Advanced Hook Implementations
Permission and Validation Hooks
Implement custom permission logic and validation rules:
python
# Permission Query Conditions
# ---------------------------
permission_query_conditions = {
"Library Transaction": "library_management.library_management.doctype.library_transaction.library_transaction.get_permission_query_conditions",
}
# Has Permission
# --------------
has_permission = {
"Library Transaction": "library_management.library_management.doctype.library_transaction.library_transaction.has_permission",
}
# Override standard DocType class
# --------------------------------
# override_doctype_class = {
# "ToDo": "custom_app.overrides.CustomToDo"
# }
# Document Methods
# ----------------
# override_doctype_methods = {
# "User": {
# "add_roles": "custom_app.overrides.user_add_roles"
# }
# }
Module System and Organization
Creating Application Modules
Modules provide logical organization for related DocTypes and functionality:
bash
# modules.txt content
Library Management
Settings
Reports
Module Directory Structure
Each module maintains its own directory structure within the application:
text
library_management/library_management/
├── __init__.py
├── library_management/ # Default module
│ ├── __init__.py
│ ├── doctype/ # DocType definitions
│ │ ├── article/ # Article DocType
│ │ ├── library_member/ # Library Member DocType
│ │ └── library_transaction/ # Library Transaction DocType
│ ├── page/ # Custom pages
│ ├── report/ # Custom reports
│ └── web_form/ # Web forms
└── settings/ # Settings module
└── doctype/
└── library_settings/ # Library Settings DocType
Asset Management and Building
Static Asset Organization
Organize CSS, JavaScript, and other static files for optimal performance:
text
public/
├── css/
│ ├── library_management.css # Main stylesheet
│ └── components/ # Component-specific styles
├── js/
│ ├── library_management.js # Main JavaScript
│ └── controllers/ # Form controllers
└── images/ # Static images
Asset Building Process
Frappe v15 uses modern build tools for asset compilation:
bash
# Build assets for specific app
bench build --app library_management
# Build all assets
bench build
# Development mode with file watching
bench watch
Development Workflow Integration
Site Installation Process
Install the newly created application on a development site:
# Create development site (if needed)
bench new-site library.test
# Install application on site
bench --site library.test install-app library_management
# Set as default site
bench use library.test
# Migrate database changes
bench --site library.test migrate
Version Control Integration
Initialize Git repository for custom application development:
# Navigate to app directory
cd apps/library_management/
# Initialize Git repository
git init
# Add initial commit
git add .
git commit -m "Initial commit: Library Management application"
# Add remote repository
git remote add origin https://github.com/username/library_management.git
git push -u origin main
Advanced Configuration and Customization
Custom Dependencies Management
Define application-specific dependencies using modern Python packaging:
text
# pyproject.toml dependencies section
[project]
dependencies = [
"frappe>=15.0.0",
"requests>=2.25.0",
"pandas>=1.3.0"
]
[project.optional-dependencies]
dev = [
"frappe[dev]",
"pytest>=6.0.0",
"black>=21.0.0"
]
test = [
"pytest>=6.0.0",
"pytest-cov>=2.10.0"
]
Multi-Environment Configuration
Configure applications for different deployment environments:
python
# hooks.py environment-specific configuration
import os
# Development-specific hooks
if os.getenv("FRAPPE_ENV") == "development":
app_include_js = [
"/assets/library_management/js/library_management.dev.js"
]
# Production-specific hooks
elif os.getenv("FRAPPE_ENV") == "production":
app_include_js = [
"/assets/library_management/js/library_management.min.js"
]
Testing and Quality Assurance
Application Testing Framework
Implement comprehensive testing for custom applications:
bash
# Create test directory structure
mkdir -p library_management/tests/
touch library_management/tests/__init__.py
touch library_management/tests/test_library_transaction.py
Test Implementation Example
python
# tests/test_library_transaction.py
import frappe
import unittest
from frappe.tests.utils import FrappeTestCase
class TestLibraryTransaction(FrappeTestCase):
def setUp(self):
# Create test data
self.create_test_member()
self.create_test_article()
def test_transaction_creation(self):
transaction = frappe.get_doc({
"doctype": "Library Transaction",
"library_member": self.member.name,
"article": self.article.name,
"type": "Issue"
})
transaction.insert()
self.assertTrue(transaction.name)
def create_test_member(self):
# Test member creation logic
pass
def create_test_article(self):
# Test article creation logic
pass
Production Deployment Considerations
Application Distribution
Prepare applications for production deployment and distribution:
bash
# Build application package
python -m build
# Create distribution package
pip wheel .
# Install from package
pip install ./dist/library_management-*.whl
Performance Optimization
Optimize applications for production performance :
python
# hooks.py performance optimization
# Enable caching for custom pages
website_route_rules = [
{"from_route": "/library/<name>", "to_route": "library_page"},
]
# Configure asset bundling
app_include_js = [
"/assets/library_management/js/bundle.min.js"
]
Community Resources and Best Practices
Enhanced Development Resources
Continue your Frappe Framework v15 application development journey through GoERPNext platform resources :
- Comprehensive Guides: Access enhanced application development tutorials
- Community Forum: Connect with experienced Frappe developers
- Best Practices: Learn from community-contributed development patterns
- Code Examples: Explore real-world application implementations
Application Architecture Patterns
Follow established patterns for scalable application development:
- Modular Design: Organize functionality into logical modules
- Hook-Based Extensions: Use hooks for framework integration rather than core modifications
- Test-Driven Development: Implement comprehensive testing from the start
- Version Control: Maintain proper Git workflows for collaborative development
This comprehensive guide establishes the foundation for creating robust, scalable custom applications in Frappe Framework Version 15, enabling developers to leverage the framework’s powerful features while maintaining best practices for professional software development and deployment.