Public
Car inventory web app: CRUD + make/model/status filters
carsinventorysqlite
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

Car Inventory Management System — Val Town edition

A working car inventory web app: add, search, update, delete, and filter cars by make, model, or status, with the same validation rules as the original console CarInventoryApp. Live, deployed, and backed by a real SQLite database.

This is the runnable half of a pair. The other half — the Java EE / Tomcat 9 WAR version (Servlet + JSP + JSTL + JDBC + MySQL) that matches the stack your coursework asks for — lives at abdou/car-inventory-javaee, where it can be read and downloaded but not built, because Val Town has no JVM. This val is what a demo needs instead: something that actually loads.

What's here

index.ts                         Hono server: HTML shell + JSON API
lib/cars.ts                      domain layer: types, validation, SQLite CRUD
frontend/root.tsx                HTML shell (stamps versioned asset URLs)
frontend/index.tsx               React entrypoint
frontend/components/App.tsx      page layout, filters, data fetching
frontend/components/CarTable.tsx inventory table
frontend/components/CarForm.tsx  add/edit form + client-side validation

API

MethodRoutePurpose
GET/api/metaLegal statuses and numeric limits, for rendering the form
GET/api/carsAll cars
GET/api/cars?category=make&value=TOYOTAFiltered — category is one of make, model, status
GET/api/cars/:idOne car (404 when absent)
POST/api/carsCreate. 201 with the saved car, or 400 with { errors: [...] }
PUT/api/cars/:idUpdate
DELETE/api/cars/:idDelete

Rules enforced

Unchanged from the original CarInventoryApp:

  • License plate — one uppercase letter followed by digits, max 7 characters
  • Make — letters, spaces, hyphens. Model — also digits
  • Year — 2000–2025
  • Mileage — non-negative, and it may never run backwards
  • Price — non-negative, at most two decimals
  • Status — one of UNDEFINED, AVAILABLE, RESERVED, SOLD, MAINTENANCE
  • Plate is unique — surfaced as a validation message, not a 500

The behaviour changes I made to the original logic (silently rewriting an out-of-range year to MAX_YEAR, keeping the old mileage after warning, an unguarded Integer.parseInt) are documented in the Java val's README under "Bugs fixed during the port" — they apply here too, since both versions share the rules.

Validation is layered, and only one layer is trusted

Rendering mermaid diagram...

CarForm.tsx duplicates the rules so common mistakes never cost a network round trip. That duplication is a real cost, accepted deliberately: client-only validation is not validation, and server-only validation means every typo is a round trip. Post directly to /api/cars with a bad plate and you'll get a 400 with the same messages — that path is the reason layer B exists.

Where a JVM app and this one diverge

Java EE (car-inventory-javaee)here
Servlet mapped to /cars, forwards to JSPsHono routes returning JSON; React renders
CarBean implements Serializable, getters/settersplain Car interface
CarDAO — PreparedStatement, ResultSet, SQLExceptionsqlite.execute({ sql, args })
MySQL DECIMAL(12,2) for moneySQLite REAL (see below)
web.xml context-paramsconstants in lib/cars.ts, served at /api/meta
AppContextListener creates the table at startupensureSchema(), memoised per instance
response.sendRedirect after a POSTclient updates its own state

One thing the Java version does better: DECIMAL(12,2) stores money exactly, where SQLite has only REAL (an IEEE double). For prices under about nine trillion with two decimals the difference never surfaces in practice, and the column is formatted to two decimals at the edges — but if this were handling real invoices, that's the reason to prefer MySQL, or to store integer cents.

Database

Val Town's built-in SQLite, scoped to this val — nothing to provision. The cars table is created on first use and seeded with three sample rows if empty. Columns: id, license_plate (unique), make, model, year, mileage, price, status, with indexes on make, model, and status.