Refactor `diagrams` tool to eliminate duplicated code between entity an file diagram implementations