Development Conventions and Common Tasks
This guide supplements AGENTS.en.md with implementation checklists, debugging commands, and code conventions.
Common Development Tasks
Add an API Endpoint
- Create
xxx_handler.goundercmd/server/and export the handler. - Register the route in the appropriate subrouter (
api,protected, oradmin) inmain.go. - Add the client call to
frontend/src/utils/api.jsand use it from the view. - For a write endpoint, confirm the frontend
fetchincludes theX-CSRF-Tokenheader.
Change the Database Schema
- Change or add the model in
internal/store/. - In
store.go::migrate(), appendCREATE TABLE IF NOT EXISTS ...for a new table, or calladdColumnIfMissing(ctx, db, "<table>", "<column_def>")to add a column to an existing table. - Update the affected CRUD functions.
- Use
sqlite3 data/cups-web.dbto check that the migration works with a fresh database and with old data.
Add a Frontend Page
- Add a
.vuesingle-file component tofrontend/src/views/using the Composition API. - Add a route in
frontend/src/router/index.js. Usemeta: { requiresAuth: true }for authenticated pages and addrequiresAdmin: truefor administrator pages. - Add a navigation entry in the
App.vueheader when needed. The Print, Drivers, and Admin entries for administrators appear as segmented controls on desktop and in the hamburger menu on mobile.
Add a Supported File Type
- Add a
fileKindinfile_utils.go::detectFileKind. - Implement conversion in
convert_utils.goorpdf_utils.go. - Handle the type in the
switch kindinprint_handlers.go. - Update
estimateHandlerandconvertHandler. Cover both the single-filefileand multi-filefilesinputs inconvertHandler.
Add a Printer Driver
See Driver management for the implementation details and known issues.
- Add the installation script. Use
scripts/driver/install-<name>.sh, where<name>is the canonical driver name. The Dockerfile'sCOPY scripts/driver/install-*.sh /opt/cups-drivers/scripts/automatically includes the script. - Use the expected exit codes. Return
0for success,3when the current architecture is unsupported, and another nonzero exit code for failure. Returning0for an unsupported architecture creates a manifest and makes the UI report a false installation. Detect the architecture withdpkg --print-architecture. The runtime image omitsdpkg-devand thereforedpkg-architecture. - Use a single exit trap for source builds. When building or installing build dependencies, use one
trap _cleanup EXIT. Put temporary directory cleanup andapt-get purge -y --auto-remove ${BUILD_DEPS}in branches of_cleanup(). UseCUPS_AIOto distinguish runtime container installation and image builds. Bothdriver-installand Go'srunDriverCommandsupplyCUPS_AIO=1. Keep/var/lib/apt/lists/*in AIO mode so later driver installations can use the apt index. - Choose a persistence mechanism.
- Use package-level snapshots for vendor
.debfiles and packages installed byapt-get install. After downloading a vendor package, hand the original file todriver-installbeforedpkg -i:
Apt's# The archive attempt preserves installation outcomes and exit codes. # The guard preserves behavior for builds and manual runs. if [ -n "${DRIVER_PKG_DIR:-}" ]; then cp -a "${DEB_PATH}" "${DRIVER_PKG_DIR}/" 2>/dev/null || true ficapture-debshook automatically captures apt-installed packages and their transitive dependencies. Avoid resolving the vendor package'scupsmetapackage dependency throughapt-get -f install. Debian'scups-core-driverswould overwrite components built from CUPS source. Usedpkg -i --force-depends. Keep archive cleanup under the existing trap. - Use file-level snapshots for assets produced by a source build, manual copy, or unzip. Keep outputs in an allowed path such as
/usr/lib/cups,/usr/share/cups,/usr/share/ppd,/usr/share/foomatic,/lib/firmware,/usr/lib/firmware, or/usr/lib/<multiarch>. Autoconf defaults--libdirto the bare/usr/lib. Explicitly move shared libraries to the multiarch directory so they are captured. driver-installfails when both the file manifest and the package archive are empty.
- Use package-level snapshots for vendor
- Register the driver in
driver_registry.go::driversRegistry. SetNameto<name>. SetDisplayName,Description,Arch({"all"}or a list of Debian architecture names),NeedCompile, andMatchPatterns. The UI usesArchto enable installation, and/drivers/detectuses the case-insensitive(?i)regular expressions to recommend a driver. Generic drivers can leaveMatchPatternsempty. - Use the repository's GitHub Releases mirror under the
cups-drivertag for third-party downloads. Vendor endpoints from Epson and Sharp often return HTTP 403 in CI because of user-agent and TLS-fingerprint checks. Exit with a nonzero status promptly when a download fails. - Verify installation and removal. Run
driver-listinside the container and check that the available driver showsRestore: package/files/hybridas appropriate. Rundriver-install <name>. Inspect/opt/cups-drivers/data/<name>/manifest.txtand confirm that it excludes system files, especially CUPS's backends and filters. Afterdriver-remove <name>, confirmlpstat -rsucceeds and/usr/lib/cups/backend/*remains present. - Verify restoration with a fresh container.
docker rm -f <ct> && docker run -d --name <ct> -v "$PWD/.drivers:/opt/cups-drivers/data" <image>docker restartpreserves the writable layer and gives a false pass when the original installation is still present. In the new container, confirm that the filter, shared libraries, PPD, and vendor data directory are restored. Checklddfor missing dependencies.
Debugging and Testing
Backend Tests
go test ./... # Run all tests.
go test -cover ./... # Include coverage.
go vet ./... # Run static checks.
The repository mainly relies on manual tests and logs.
test/contains temporary test cases outside CI. Add a_test.gofile when introducing a core module.
Frontend Checks
cd frontend
bun run build # Check the production build and syntax.
bun run dev # Start local development.
Inspect the Database
sqlite3 data/cups-web.db
.tables
SELECT * FROM users;
SELECT id, filename, status, is_duplex, is_color, created_at FROM print_jobs ORDER BY id DESC LIMIT 20;
SELECT * FROM settings;
Code Style
Go
- Follow Go naming conventions and format with
gofmt. - Use
appStore.WithTx(ctx, readOnly, func(tx) error { ... })to set transaction boundaries in handlers. - Use
writeJSONError(w, status, msg)for errors andwriteJSON(w, v)for successful responses. - Store relative file paths after
filepath.ToSlash. Usefilepath.FromSlashandfilepath.Join(uploadDir, ...)to resolve them on access.
Vue
- Use single-file components and the
<script setup>Composition API. - Prefer
@nuxt/uicomponents. The global prefix isUinvite.config.js. - Use Tailwind utilities and Nuxt UI semantic classes such as
bg-defaultandtext-mutedfor light and dark themes. cachedSessioninrouter/index.jskeeps routes from refetching/api/sessionon every navigation.
Git Commits
- Write commit messages in Chinese using a prefix such as
feat:,fix:, orrefactor:followed by a brief description. - Omit
Co-Authored-Byand AI attribution lines.