How wgr-sa/strapi-plugin-collection-tree works
Project Type & Purpose
• This is a Strapi plugin designed to add a collection tree functionality that allows users to drag and drop and sort their collections.
• The plugin is split between an Admin UI portion (the “admin” folder with React components, pages, translations, etc.) and a backend portion (the “server” folder with controllers, routes, services, configurations, and utilities).
File Structure
• Admin Frontend:
• The “admin” directory contains the src folder with its own subdirectories:
– api (for API configuration files),
– components (reusable React components like Initializer, PluginIcon, SortElement, etc.),
– pages (pages for settings, sorting views, and related interfaces),
– translations (for language support, e.g., en.json, fr.json),
– utils (auxiliary modules such as axiosInstance, getTrad, and a serverRestartWatcher).
• Backend Server:
– config (for various plugin configurations),
– controllers (with business logic for model, settings, and sort actions),
– routes (defining API endpoints to interact with the plugin’s features),
– services (which implement operations like retrieving and updating collections, sorting elements),
– middlewares and policies (for request handling, security checks, etc.),
– utilities (for actions such as schema update and tree transformation).
• Additional Files:
• Files such as “strapi-admin.js” and “strapi-server.js” indicate integration with the Strapi ecosystem.
• The presence of TypeScript configuration files (tsconfig.json, tsconfig.server.json) suggests that strong typing and a build process are used.
• Main Components:
• Frontend Admin UI: Built with React (components, pages, translations, API interactions).
• Backend API: Comprises controllers, routes, and services that handle business logic (sorting, settings, data manipulation).
• Configuration & Integration: Configuration files and bootstrap scripts ensure the plugin is integrated with Strapi.
• Relationships:
• The Admin UI communicates with the backend by issuing API calls (using the axiosInstance utility).
• The server routes direct requests to appropriate controllers which, in turn, communicate with services to perform operations on the data.
• Utility modules (both on the admin and server) assist in tasks such as schema updates, tree transformations, and internationalization.
• The configuration files and bootstrap scripts initialize server settings for the plugin upon startup.
• Architectural Patterns/Design Principles:
• Separation of concerns: Clear division between client (admin UI) and server handling.
• MVC-like organization on the server side: Routes (as the entry point), Controllers (business logic), and Services (data manipulation).
• Plugin modularity: The design encapsulates its own API, admin interface, and configuration, adhering to a modular plugin architecture for Strapi.