Implementing Folder-like Structure with Limited Visible Records in FrappeErp

I’m trying to replicate a folder-like structure within Frappe, where only the latest 3 records are visible at any given time. Any new records exceeding this limit should be automatically moved to a backup location (another doctype).
Background:
In a shell script, I’ve successfully implemented this behavior with a backup folder and file. Essentially, when a 4th folder is created, the oldest one is moved to the backup. I’d like to achieve the same within Frappe, but I’m not sure about the best approach.