How riddleroseheart/polyprint3d works
Project Type & Purpose
• PolyPrint 3D is a full-stack application with two clear halves:
• A Python/Flask-based backend that handles API endpoints, slicing logic, printer control (integrated with OctoPrint), authentication, file management, and database operations.
• A JavaScript-based frontend built with Three.js providing the web UI.
• Key functionality revolves around automatically slicing 3D models into smaller parts and distributing print jobs to multiple 3D printers.
Analyzing the File Structure
• Backend:
• Contains the core Flask application (backend/main.py) that initializes the server.
• The “routes” directory defines various API endpoints (e.g., alert_routes, auth_routes, file_routes, printer_routes, slicer_routes, etc.).
• The “services” directory encapsulates business logic – with specialized services for alerts, authentication, notifications, file handling, and printing (including a deeper printer service hierarchy).
• The “database” subdirectory manages database configuration, models and includes the local database file (polyprint.db) as well as config settings.
• The “slicer” folder houses the slicing logic, including configuration files (in backend/slicer/config) and scripts (in backend/slicer/scripts) to manage slicing operations.
• Additional utility functions and email templates for notifications are present in backend/utils and backend/templates respectively.
• Frontend:
• Built in JavaScript (React structure indicated by components, src, public folders) and employs Three.js.
• API configuration and endpoints references (in frontend/src/api) show clear integration with backend services.
• Support files:
• Setup scripts (setup.sh/setup.bat) and run scripts (run.sh/run.bat) provide instructions for environment configuration and deployment.
• Environment variable template (.env.template) is essential for configuration (e.g., FLASK_APP, DATABASE_URL).
Architectural Overview
a. Main Components:
• Frontend:
• Web UI (React components, Three.js visualization)
• API Communication layer (axiosConfig with endpoints for auth, alert, printer, file, slicer, etc.)
• Backend:
• API Server (Flask) that handles incoming HTTP requests.
• Routing Layer (under backend/routes) maps endpoints to business logic.
• Service Layer:
▪ Core business logic including Alert, Auth, File, Notification, Printer control (with further subdivisions: connection, job, management, etc.), Slicer, and Octoprint integration.
• Database:
▪ Database configuration and models housed in backend/database.
• Slicer Engine:
▪ Slicing operations via dedicated scripts and configuration files.
• External Services:
• OctoPrint for printer control/integration.
• Email notification system (using templates in backend/templates/emails).
b. Relationships and Interactions:
• The Frontend communicates with the Backend via HTTP requests to the defined API endpoints.
• The API server routes requests to the appropriate service layer components.
• Services interact with the database for data persistence (configuration, job statuses, user data, etc.).
• Printer services interact with external services such as OctoPrint to manage print jobs.
• The Slicer component processes 3D models, communicating with both the database (for configuration and status tracking) and printer services (for job distribution).
c. Architectural Patterns & Design Principles:
• Layered Architecture: Clear separation between presentation (Frontend), API (Routes), business logic (Services), and data (Database).
• Modular Design: Separate directories for routes, services, and database operations to promote maintainability.
• Integration & Extensibility: Integration with external printer control via OctoPrint, and use of configuration files/scripts for the slicer.
• Micro-modularity even within services – particularly for the printer where there are multiple subservices handling different aspects (connection, file handling, job management).
d. Key Technologies & Frameworks:
• Backend: Python, Flask, and possibly SQLAlchemy (for database models) along with custom code for slicing.
• Frontend: JavaScript, React (implied by file structure), and Three.js for 3D visualization.
• External: OctoPrint for interfacing with printers.