- Database path resilience: The SQLite database points to
data/parts.db, but thedatadirectory may not exist on a fresh deployment, causing startup errors. Consider creating the directory during startup (e.g.,os.makedirs("data", exist_ok=True)) before initializing the engine inlifespan. - Bulk add logic: The
/add/bulkhandler currently nests two loops overpart_number, redefiningsafe_stron each pass and only adds the last constructedPartper outer loop. Flattening to a single loop that constructs and commits eachPartonce would prevent duplicated iteration and ensure every row is saved. - Usage logging consistency:
use_one_partappends a timestamped note while/scan/remove_onewrites plain text. Standardizing note formatting (e.g., always timestamping) would make history entries easier to read and audit. - Input validation: Several forms accept raw strings for price and quantity. Adding server-side validation (e.g., clamping negatives, defaulting empty strings to
None) can prevent invalid records and database errors. - Query efficiency: The
/searchendpoint loads all parts into memory and filters in Python. Using SQLILIKEfilters similar to/findwould offload work to the database and scale better for large datasets. - Error handling for missing parts: Some routes assume
partexists (e.g.,/scan/resultand/scan/remove_one). Returning 404 or user feedback when a part is missing can avoid silent failures and confusing redirects.