Skip to main content

Frappe Framework Version 15 Tutorial: Build a Complete Library Management System

This comprehensive tutorial guides developers through building a complete web application from scratch using Frappe Framework Version 15, demonstrating core concepts through a practical Library Management System implementation.​

Tutorial Overview and Objectives

Target Audience

This tutorial is designed for software developers familiar with web application development who want to master Frappe Framework v15. Developers should have foundational knowledge of Python, JavaScript, and basic web technologies, though proficiency in all supporting tools isn’t required to begin.​

Technology Stack Prerequisites

Frappe Framework v15 leverages a comprehensive technology stack that powers the tutorial application:

Core Technologies:

  • Python (server-side application logic and controllers)
  • JavaScript (client-side interactions and form scripting)
  • MariaDB/PostgreSQL (database management and data persistence)
  • Redis (caching, job queues, and real-time updates)
  • Jinja (templating engine for web views and print formats)

Development Tools:

  • Git (version control and bench-managed updates)
  • Bench CLI (application management and deployment)

Library Management System Architecture

Application Requirements

The tutorial builds a comprehensive Library Management System enabling librarians to manage library operations through Frappe’s built-in Desk interface efficiently. The system provides role-based permissions, standard views (List, Form, Report), and public web interfaces for library members.​

Core Models and DocTypes

Primary DocTypes Structure

The application implements five essential DocTypes that demonstrate different Frappe Framework v15 capabilities:

Article DocType:

  • Represents books and rental items
  • Implements basic field types and validation
  • Demonstrates standard DocType functionality

Library Member DocType:

  • Manages user subscriptions and memberships
  • Links to system users and membership records
  • Showcases relationship modeling

Library Transaction DocType:

  • Handles article issue and return operations
  • Implements submittable DocType functionality
  • Demonstrates workflow and status management

Library Membership DocType:

  • Represents active membership periods
  • Includes membership validation logic
  • Shows advanced controller methods

Library Settings DocType:

  • Stores system configuration parameters
  • Implements Single DocType pattern
  • Demonstrates settings management

Project Setup and Development Environment

Initial Bench Configuration

Begin the tutorial by setting up a dedicated Frappe v15 development environment with proper configuration:

bash
# Create new bench with Frappe v15
bench init library-bench --frappe-branch version-15
# Navigate to bench directory
cd library-bench/
# Enable developer mode for DocType tracking
bench set-config -g developer_mode true
# Start development server
bench start

Creating the Library Management App

Generate the application scaffold using Bench CLI tools specifically for Version 15:

bash
# Create new Frappe app
bench new-app library_management
# Confirm app creation
cd apps/library_management/
ls -la # Verify app structure

Site Setup and App Installation

Configure a development site for testing the Library Management application:

bash
# Create development site
bench new-site library.test
# Install library management app
bench --site library.test install-app library_management
# Set as default site
bench use library.test

DocType Development Workflow

Enabling Developer Mode

Activate developer mode to enable DocType creation and version control integration:​

bash
# Enable developer mode globally
bench set-config -g developer_mode true
# Restart bench for changes to take effect
bench restart

Creating the Article DocType

Basic DocType Configuration

Access the DocType List through the Awesomebar and create the Article DocType with comprehensive field configuration:

Article DocType Fields:

  • Article Name (Data, Mandatory) – Primary identifier
  • Image (Attach Image) – Visual representation
  • Author (Data) – Book author information
  • Description (Text Editor) – Detailed article description
  • ISBN (Data) – International standard identifier
  • Status (Select) – Options: “Issued”, “Available”
  • Publisher (Data) – Publishing house information

Field Types and Properties

Frappe Framework v15 provides extensive field type options for different data requirements:

Common Field Types:

  • Data: Single-line text input with character limits
  • Text Editor: Rich text editing with formatting options
  • Select: Dropdown with predefined options
  • Attach Image: File upload with image preview
  • Link: References to other DocTypes
  • Table: Child table for related records

Advanced DocType Features

Library Member Implementation

Create the Library Member DocType with user linking and validation logic:

python
# library_member.py controller
import frappe
from frappe.model.document import Document
class LibraryMember(Document):
def validate(self):
# Custom validation logic
self.validate_email_uniqueness()
def validate_email_uniqueness(self):
# Ensure email addresses are unique
existing = frappe.db.exists("Library Member", {
"email": self.email,
"name": ("!=", self.name)
})
if existing:
frappe.throw("Email address already registered")

Submittable DocType Pattern

Implement the Library Transaction as a submittable DocType demonstrating workflow capabilities:

python
# library_transaction.py controller
import frappe
from frappe.model.document import Document
class LibraryTransaction(Document):
def validate(self):
# Validate transaction before submission
self.validate_membership()
self.validate_article_availability()
def on_submit(self):
# Update article status after submission
if self.type == "Issue":
self.update_article_status("Issued")
def on_cancel(self):
# Revert article status on cancellation
if self.type == "Issue":
self.update_article_status("Available")

Controller Methods and Business Logic

Python Controller Development

Validation and Lifecycle Methods

Implement comprehensive validation logic using Frappe v15’s controller methods:

python
# library_membership.py controller
import frappe
from frappe.model.document import Document
from frappe.utils import getdate, add_months
class LibraryMembership(Document):
def validate(self):
# Validate membership dates
self.validate_dates()
# Check for overlapping memberships
self.validate_no_active_membership()
def validate_dates(self):
if getdate(self.from_date) >= getdate(self.to_date):
frappe.throw("To Date cannot be before From Date")
def validate_no_active_membership(self):
# Prevent overlapping active memberships
active_memberships = frappe.db.sql("""
SELECT name FROM `tabLibrary Membership`
WHERE library_member = %s
AND docstatus = 1
AND %s BETWEEN from_date AND to_date
""", (self.library_member, self.from_date))
if active_memberships:
frappe.throw("Member already has active membership")

Client-Side JavaScript Development

Form Scripts and User Interactions

Enhance user experience with JavaScript form scripts for dynamic behavior:

javascript
// article.js client script
frappe.ui.form.on('Article', {
refresh: function(frm) {
// Add custom buttons based on status
if (frm.doc.status === 'Available') {
frm.add_custom_button(__('Issue Article'), function() {
frappe.new_doc('Library Transaction', {
article: frm.doc.name,
type: 'Issue'
});
});
}
},
status: function(frm) {
// Update form styling based on status
if (frm.doc.status === 'Issued') {
frm.dashboard.set_headline_alert(
__('This article is currently issued'),
'orange'
);
}
}
});

Single DocType Implementation

Library Settings Configuration

Create a Single DocType for system-wide configuration management:

python
# library_settings.py controller
import frappe
from frappe.model.document import Document
class LibrarySettings(Document):
def validate(self):
# Validate configuration parameters
if self.loan_period <= 0:
frappe.throw("Loan period must be greater than 0")
if self.max_articles_issued <= 0:
frappe.throw("Maximum articles must be greater than 0")

Library Settings Fields:

  • Loan Period (Integer) – Default lending period in days
  • Maximum Articles Issued (Integer) – Concurrent borrowing limit
  • Fine Amount per Day (Currency) – Late return penalty calculation

Web Views and Portal Development

Public Article Browsing

Create public web views enabling library members to browse available articles without administrative access:

python
# web_article_list.py
import frappe
from frappe.website.utils import get_comment_list
def get_context(context):
# Get available articles for public display
context.articles = frappe.get_all('Article',
filters={'status': 'Available'},
fields=['name', 'article_name', 'author', 'image', 'description'],
order_by='creation desc'
)
context.title = "Available Articles"
return context

Portal Integration

Implement member portal functionality for self-service operations:

xml
<!-- article_portal.html template -->
{% extends "templates/web.html" %}
{% block content %}
<div class="container">
<h2>Available Articles</h2>
<div class="row">
{% for article in articles %}
<div class="col-md-4">
<div class="card">
{% if article.image %}
<img src="{{ article.image }}" class="card-img-top">
{% endif %}
<div class="card-body">
<h5 class="card-title">{{ article.article_name }}</h5>
<p class="card-text">{{ article.author }}</p>
<p class="card-text">{{ article.description[:100] }}...</p>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}

Advanced Features and Customization

Naming Series Configuration

Implement systematic document naming for professional document management:

python
# Configure naming series in DocType settings
# Library Membership: LMS-.######
# Library Transaction: LTN-.######

Permissions and Role Management

Configure role-based access control for different user types

Librarian Role:

  • Full access to all DocTypes
  • Create, read, update, delete permissions
  • Administrative interface access

Library Member Role:

  • Read access to Article and own membership records
  • Portal access for article browsing
  • Limited transaction visibility

Testing and Validation

Development Testing Workflow

Verify application functionality through comprehensive testing procedures:

bash
# Clear cache after DocType changes
bench clear-cache
# Restart development server
bench restart
# Test DocType creation
bench --site library.test console

Data Validation Testing

Create test records to verify business logic implementation:

  1. Create Library Members with valid email addresses
  2. Add Articles with complete field information
  3. Test Membership Validation with overlapping dates
  4. Verify Transaction Workflows through issue/return cycles

Production Deployment Considerations

Performance Optimization

Implement production-ready configurations for Frappe v15 applications:

Database Optimization:

  • Configure proper indexes for frequently queried fields
  • Implement database connection pooling
  • Enable query optimization features

Caching Strategy:

  • Configure Redis for session and data caching
  • Implement page-level caching for web views
  • Enable browser caching for static assets

Security Configuration

Establish security best practices for production deployment.

  • SSL Certificate Installation for HTTPS communication
  • Database Security Hardening with restricted access
  • User Authentication Configuration with strong password policies
  • File Upload Restrictions to prevent security vulnerabilities

Community Resources and Next Steps

Enhanced Learning Resources

Continue your Frappe Framework v15 journey through GoERPNext platform resources:

  • Comprehensive Documentation: Access enhanced tutorials and guides
  • Community Forum: Connect with experienced developers and users
  • Best Practices: Learn from community-contributed solutions
  • Advanced Topics: Explore complex customization patterns

Application Extension Opportunities

Expand the Library Management System with additional features.

  • Advanced Reporting with custom queries and visualizations
  • Email Notifications for due dates and overdue items
  • Fine Calculation with automated penalty management
  • Inventory Management with supplier and purchase tracking
  • Mobile Application integration using REST APIs

This tutorial demonstrates Frappe Framework Version 15’s powerful capabilities for rapid application development while maintaining enterprise-grade functionality, security, and scalability standards that enable building comprehensive business solutions with minimal development effort.

Click to rate this post!
[Total: 1 Average: 5]