Skip to content

coreliteDev/Knostics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny Inventory

A minimal inventory management system tracking stores and the products they carry.

Run with Docker

docker compose up --build

Then open http://localhost (port 80).

Local development

Note: The server uses better-sqlite3. On Windows you may need Visual Studio Build Tools. Use Docker otherwise.

# Terminal 1 - Backend
cd server && npm install && npm run dev

# Terminal 2 - Frontend
cd web && npm install && npm run dev

API

Method Route Description
GET /api/stores List stores
GET /api/stores/:id Get store
POST /api/stores Create store
PUT /api/stores/:id Update store
DELETE /api/stores/:id Delete store
GET /api/stores/:id/summary Non-trivial: total value, by-category breakdown, low-stock count
GET /api/products?storeId=&category=&minPrice=&maxPrice=&inStock=&page=&limit= List products (filtered, paginated)
GET /api/products/:id Get product
POST /api/products Create product
PUT /api/products/:id Update product
DELETE /api/products/:id Delete product

Error shape

{ "error": "string", "details": {} }
Scenario Status
Missing resource 404
Validation failure 422
Unexpected 500

Decisions & Trade-offs

Tech stack

  • Backend: Fastify + TypeScript — built-in schema validation, lean.
  • Database: SQLite via Drizzle ORM — zero deps, migrations, type-safe queries.
  • Frontend: Vite + React + TanStack Query + Tailwind — Query handles loading/error/stale; Tailwind for readable styles.
  • Testing: Vitest + Supertest (server) + React Testing Library (frontend).

Data model

Flat: Store and Product (product has storeId, quantity). Category is a string enum (Produce, Dairy, Bakery) enforced at API. No separate Category table.

Non-trivial operation

GET /stores/:id/summary returns:

  • Total inventory value (SUM(price × quantity))
  • Per-category breakdown
  • Low-stock count (quantity < 10)

Pagination & filtering

Offset-based (page + limit). Cursor-based is better for large datasets; offset is simpler for this scope. All filters optional and composable.

Architecture

  • Backend: Thin routes, services hold logic, single error-handler middleware.
  • Frontend: api/ (typed fetch), hooks/ (TanStack Query wrappers). Pages use hooks only.

Testing

cd server && npm test
cd web && npm test
Layer What's tested
API Happy paths, 404, 422 via Supertest
Frontend 100% line/statement coverage

Run cd web && npm run test:ci for coverage report. E2E tests (Playwright) skipped at this scope.


If I Had More Time

  1. E2E tests — Playwright for create-store, add-product, view-summary flows.
  2. Optimistic updates — TanStack Query mutations with rollback on failure.
  3. Debounced filters — Reduce API calls while typing in product filters.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages