Guide to Using Static Assets in the Empress Framework

Introduction

The development and deployment of applications require the efficient use of static assets. The Empress Framework, a full-stack web application framework written in Python & JavaScript with MariaDB as the database, provides a comprehensive approach to managing these assets. This guide will provide a deep dive into the functionality and usage of static assets in the Empress Framework.

assets Folder

The assets folder is the primary location for static files served in the Empress Framework. Positioned at frappe-bench/sites/assets, Nginx serves this folder directly for production deployment. All static file URLs begin with /assets.

For instance, a file located at frappe-bench/sites/assets/hero.png is publicly accessible through the URL /assets/hero.png.

<img src="/assets/hero.png" alt="Hero image">

public Folder

Each app within the Empress Framework has a unique public folder for serving static assets. This folder creates a symbolic link to frappe-bench/sites/assets/[appname].

For example, if the tree command is executed on the assets folder, it would yield:

~/frappe-bench
$ tree sites/assets -L 1
sites/assets
├── erpnext -> ~/frappe-bench/apps/erpnext/erpnext/public
└── frappe -> ~/frappe-bench/apps/frappe/frappe/public

This structure indicates if a file exists at [appname]/public/images/favicon.png, it is also symbolically linked at assets/[appname]/images/favicon.png and publicly accessible through the URL /assets/[appname]/images/favicon.png.

Bundled Assets

Bundled assets are generated at assets/[appname]/dist/js and assets/[appname]/dist/css, making them accessible through the URL /assets/[appname]/dist/js/main.bundle.[hash].js.

Site Assets

Beyond the static files provided by apps, each site can host its static files, which may include user uploads or site backups.

User Uploads

Public files uploaded by users are stored at frappe-bench/sites/[sitename]/public/files. For example, a file stored at frappe-bench/sites/[sitename]/public/files/profile.png is publicly accessible via the URL /files/profile.png.

Private user-uploaded files are stored at frappe-bench/sites/[sitename]/private/files. A file stored at frappe-bench/sites/[sitename]/private/files/profile.png is accessible via the URL /private/files/profile.png. Private files can only be accessed by authorized users.

Backups

Local backups for the site are stored as frappe-bench/sites/[sitename]/private/backups/20210502_182223-[sitename]-database.sql.gz. They are accessible via the URL /backups/20210502_182223-[sitename]-database.sql.gz and can only be downloaded by authorized users.

~/frappe-bench
$ ls -l sites/site1.test/private/backups
total 6160
-rw-r--r--  1 farisansari  staff  2429268 May  2 18:22 20210502_182223-site1_test-database.sql.gz
-rw-r--r--  1 farisansari  staff      278 May  2 18:22 20210502_182223-site1_test-site_config_backup.json

In conclusion, the Empress Framework provides a robust solution for managing and serving static assets. Understanding these concepts and functionalities will enable developers to integrate and effectively use these elements in software development and customization. The system architecture considers user roles and permissions, providing a secure environment for accessing private assets.