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.
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
| Method | Route | Purpose |
|---|---|---|
GET | /api/meta | Legal statuses and numeric limits, for rendering the form |
GET | /api/cars | All cars |
GET | /api/cars?category=make&value=TOYOTA | Filtered — category is one of make, model, status |
GET | /api/cars/:id | One car (404 when absent) |
POST | /api/cars | Create. 201 with the saved car, or 400 with { errors: [...] } |
PUT | /api/cars/:id | Update |
DELETE | /api/cars/:id | Delete |
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.
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.
Java EE (car-inventory-javaee) | here |
|---|---|
Servlet mapped to /cars, forwards to JSPs | Hono routes returning JSON; React renders |
CarBean implements Serializable, getters/setters | plain Car interface |
CarDAO — PreparedStatement, ResultSet, SQLException | sqlite.execute({ sql, args }) |
MySQL DECIMAL(12,2) for money | SQLite REAL (see below) |
web.xml context-params | constants in lib/cars.ts, served at /api/meta |
AppContextListener creates the table at startup | ensureSchema(), memoised per instance |
response.sendRedirect after a POST | client 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.
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.