Backend Application Bootstrap
Relevant source files
The following files were used as context for generating this wiki page:
The Backend Application Bootstrap of the Nextcloud CAD Viewer defines the initialization, metadata, and service container configuration required to integrate the CAD viewing capabilities into the Nextcloud ecosystem. It bridges the PHP-based server environment with the Vue.js frontend by providing secure API endpoints for file metadata and content streaming.
The bootstrap process ensures that the application adheres to Nextcloud 33 standards, enforcing specific PHP version requirements and managing dependencies through Composer. It sets up the routing and controller logic necessary to handle DWG and DXF files while respecting Nextcloud's internal file permissions and user sessions.
Application Metadata and Dependencies
The core identity and requirements of the application are defined in the info.xml and composer.json files. These files dictate the application's compatibility range and its namespace within the Nextcloud autoloader.
App Manifest (info.xml)
The manifest identifies the app as cad_viewer and places it in the files category. It defines the navigation entry point and strict version constraints for the Nextcloud environment.
| Field | Value | Description |
|---|---|---|
| ID | cad_viewer | Unique application identifier |
| Namespace | CadViewer | PHP namespace used for PSR-4 autoloading |
| PHP Min Version | 8.2 | Minimum PHP requirement |
| Nextcloud Version | 33 | Specific Nextcloud version compatibility |
Sources: appinfo/info.xml:4-46, README.md:14-18
Dependency Management
The application uses Composer for backend dependency management, targeting the OCA\CadViewer\ namespace mapped to the lib/ directory.
"autoload": {
"psr-4": {
"OCA\\CadViewer\\": "lib/"
}
}
Sources: composer.json:24-28, AGENTS.md:10-15
Controller Architecture and Routing
The backend utilizes the Nextcloud App Framework to define controllers that handle incoming requests. There are two primary controller types: ViewController for rendering the application UI and FileController for data operations.
Service Relationships
The following diagram illustrates the relationship between the controllers and the Nextcloud core services they depend on for bootstrapping.
The FileController is responsible for validating file access and providing the binary streams required by the frontend cad-viewer library.
Sources: lib/Controller/FileController.php:33-52, lib/Controller/ViewController.php:15-25
Request Handling Flow
When a user opens a CAD file, the backend bootstrap sequence handles the transition from the Nextcloud Files app to the specialized CAD viewer interface.
Initialization Sequence
- The
ViewController::viewmethod is triggered with specificfileIds. - A
TemplateResponseis generated, which loads themainPHP template. - The frontend Vue app mounts and requests metadata via
FileController::getFile. - The
FileControllerverifies the user session and checks if the file MIME type is supported.
Security and Permission Checks
Security is enforced at the controller level using attributes and Nextcloud's IUserSession service.
- NoAdminRequired / NoCSRFRequired: Controllers use these attributes to allow standard user access to their own files via the API while relying on session tokens rather than CSRF for certain data streams.
- MIME Type Validation: The
FileControllermaintains a whitelist of supported CAD types (e.g.,application/dwg,image/vnd.dxf) to prevent unauthorized file processing. - User Folder Isolation: All file operations are scoped to the user's root folder via
IRootFolder->getUserFolder($user->getUID()).
Sources: lib/Controller/FileController.php:19-31, lib/Controller/FileController.php:61-75
Conclusion
The backend bootstrap of the Nextcloud CAD Viewer establishes a lightweight but secure foundation for CAD file interaction. By utilizing the Nextcloud App Framework and strict PSR-4 autoloading, it ensures that file metadata and binary content are served efficiently while maintaining the integrity of Nextcloud's multi-tenant file system.