Newer
Older
CNCTools / ReferenceSurfaceGenerator / .gemini / prompt.md

Gemini CLI System Prompt for the DXF Curve Generator Project

You are an AI assistant specializing in this specific project. Adhere to the following architectural patterns, conventions, and operational procedures.

Project Overview

This is a web application that processes 3D mesh files into 2D DXF profiles. It consists of a Python backend and a React frontend. The overall architecture is asynchronous and job-based, designed to handle potentially long-running processing tasks without blocking the user interface.

Core Technologies

  • Backend: Python 3.11, FastAPI, Uvicorn, Trimesh, Ezdxf
  • Frontend: React (Create React App), React-Bootstrap, Three.js, @react-three/fiber, @react-three/drei
  • Deployment: Docker, Docker Compose
  • Testing: Pytest (backend), Jest/React Testing Library (frontend)

Backend Conventions

The backend is composed of two main processes: a FastAPI web server (app/main.py) and a background worker (app/worker.py).

  • Job Queue: Communication between the web server and the worker is file-based. When a file is uploaded, a job is created in the /data/jobs_metadata directory, and a corresponding .trigger file is placed in the /data/job_queue. The worker polls this directory for new jobs.
  • Persistence: All job-related information (status, file paths, etc.) is stored as individual JSON files in /data/jobs_metadata. Do not use a database.
  • Error Handling: The core processing logic in processing.py can have silent failures (e.g., from the trimesh library). It is critical that error handling is robust. Always prefer broad except Exception blocks within processing loops for individual layers to capture all possible errors, log them as warnings, and allow the job to complete if possible. The COMPLETE status should only be set if an output file is verified to exist on disk using os.path.exists().
  • Testing:
    • Backend tests are located in backend/app/tests.
    • To run tests, use the ./run_tests.sh script from the backend directory. This script correctly activates the Python virtual environment (backend/venv) and executes pytest.
    • API tests (test_api.py) require httpx and use TestClient. Pay close attention to Python import paths (sys.path) to avoid ImportError.

Frontend Conventions

The frontend is a standard Create React App.

  • State Management: The primary state is managed in the App.js component.
  • Component Structure: Components are being refactored into their own files (e.g., JobItem.js, DxfViewer.js). Continue this pattern.
  • 3D Viewer: The DXF viewer is implemented using @react-three/fiber. It fetches parsed DXF data as JSON from the backend's /api/jobs/{job_id}/view endpoint.
  • Testing:
    • Frontend tests are run using npm test.
    • To run tests in a non-interactive CI mode, you must use the command: CI=true npm test.
    • Mocking libraries like @react-three/fiber is complex. When testing components that use it, focus on testing the data fetching and conditional rendering logic, not the WebGL output itself.

Environment & Deployment

  • Local Development: Use the start_local_dev.sh script in the project root. This starts the backend and frontend servers independently.
  • Docker Deployment:
    • The Dockerfile is a multi-stage build.
    • The deploy.sh script handles deployment.
    • Permissions are critical. The application runs as a non-root user (appuser). The start.sh script (the container's entrypoint) runs as root to chown the /app/data volume mount, then uses gosu to step down to appuser before launching the application. When modifying deployment scripts, this permission-handling pattern must be maintained.