BIKE-0

Open-source bicycle part compatibility engine + inventory system. Tells you if t

This is a fork of Burhanaddinzm/BIKE-0, kept for reference and contributions. It is not an original project.

Bike[0] — Core Inventory & Compatibility Graph API

The data layer and workshop UI for a budget bicycle-parts hub. It sells used parts from stripped donor bikes, Chinese generics and OEM parts under a no-return, zero-fault policy, so every compatibility answer has to be right, or it has to say it doesn't know.

Stack: Node 22 · TypeScript · Fastify 5 · PostgreSQL 16 · Zod 4 · React 19 + Vite. No ORM, no graph database, no paid services required.

Build check on a bike schematic Verification gate Overview
Build Gate Overview

Deploy (one command)

docker compose up -d --build     # → http://localhost:3000  (UI at /app, API docs at /docs)

That builds one image with the API and the workshop UI, starts Postgres, waits for it to be healthy, runs migrations, seeds the catalog only if the database is empty, and starts the API with a healthcheck. Data lives in the pgdata and uploads volumes, so rebuilds and restarts keep everything, including verifications you made. Optional settings go in .env (copy .env.example; every value has a default):

Setting Default
POSTGRES_PASSWORD bike0 Change for anything beyond your own machine
API_KEYS empty (auth off) Comma-separated keys; enter one in the UI under Settings
APP_PORT 3000 Host port
DEFAULT_CURRENCY USD ISO 4217 code for new donors and items; existing records keep theirs
SEED_ON_START if-empty always re-applies seed specs (overwrites edits to seed parts), false disables
DEMO_DATA false true loads demo donors, stock and builds into an empty inventory
AI_PROVIDER none anthropic (+ ANTHROPIC_API_KEY) or openai; Ollama on the host works via http://host.docker.internal:11434/v1
STORAGE local s3 with docker compose --profile s3 up -d --build for bundled MinIO (bucket created automatically)

Useful: docker compose logs -f api, docker compose exec api node_modules/.bin/tsx src/seed/demo.ts --if-empty, docker compose down (keeps data) / down -v (wipes it). Postgres is bound to 127.0.0.1 only.

Develop

docker compose up -d db          # just the database
cp .env.example .env
npm install
npm run seed                     # migrate + seed parts/bikes + build the graph
npm run dev                      # http://localhost:3000  → interactive docs at /docs
npm test                         # 48 unit + 27 integration tests (needs bike0_test DB)
npm run demo                     # optional: donors, listed stock, a blocked part, AI queue, two builds

Workshop UI

npm run web:build                # once: builds web/ → served by the API at http://localhost:3000/app/
# or, while changing the UI:
npm run web:dev                  # Vite on http://localhost:5173/app/ with hot reload, proxied to the API on :3000

A React + TypeScript admin app in web/ for testing every part of the core:

Section What you can do
Overview Inventory pipeline with the verification gate, catalog health, spend vs listed value, recent activity
Donor bikes Register a donor; strip it from a bike model (tick recovered parts) or describe each part for AI identification
Inventory Filter stock; per item: lifecycle, measurements checked live against the catalog spec, photo upload (drag and drop), grade/price, gated transitions with the exact blockers, which bikes it fits
AI review Accept a catalog match (variants matching the extracted specs are highlighted), correct and create, or reject
Builds Frankenstein builds on a bike schematic: every slot is a node coloured by its verdict; pick a slot to see what in stock (or in the catalog) fits and use it
Bike models Stock builds with self-check; "what fits my bike" per slot; start a build from a bike
Parts catalog Search, create/edit/duplicate with JSON specs + required-field list + allowed-values lookup, verify, graph neighbours
Interfaces Browse standard nodes and every part attached; export the graph
Tools Check two parts (load from catalog or type what-if specs), identify a part from text, rider fit
Settings API key and your name for the audit log, tyre/rim table editor, graph rebuild

1. Data model: a two-layer graph

            ┌──────────── interface nodes (physical standards) ────────────┐
            │  bb_shell=BSA:68   seatpost=27.2   freehub=HG_8_10   ...     │
            └──────▲──────────────▲───────────────▲────────────────────────┘
                   │ uses         │ uses          │ uses            (part_interfaces)
   ┌───────────────┴──┐   ┌───────┴──────┐  ┌─────┴────────┐
   │ frame (catalog)  │══▶│ seatpost     │  │ cassette     │       (compat_edges:
   └──────────────────┘fits└────────────┘  └──────────────┘        compatible | conditional
            ▲                                                       + required adapters)
            │ is-a
   ┌────────┴─────────┐
   │ inventory item   │  physical unit: measurements, grade, photos, price, status
   └──────────────────┘

2. The rule engine (src/domain/)

Verdict Meaning Sellable as "guaranteed fit"?
compatible Fits as-is ✅ (if all data is verified)
conditional Fits only with the listed adapter, shim, spacer or bench-tuning Only as a kit
unknown Required data is missing ❌ never treated as a fit
incompatible Does not fit ❌

Pairwise checks (55 connections)

Whole-bike rules (5)

Rule What it checks
rd-capacity Derailleur wrap ≥ cassette spread + chainring spread
steerer-length Threadless: steerer ≥ head tube + headset stack + stem − 3. Threaded: steerer ≈ head tube + stack (too short = locknut won't engage; too long = spacers), and thread length reaches the top cup
chainline Derailleur: crank chainline (shifted by BB spindle length) vs frame design, which is derived from rear spacing if not stated (130→43.5, 135→48.5, 148 Boost→52, 157→55). Single/fixed/IGH: ring line vs sprocket line within 1.5mm
chain-tension Single/IGH on vertical dropouts needs a tensioner; fixed on vertical dropouts is refused; horizontal/track/sliding dropouts or an eccentric BB pass
ebike-system One motor; no BB with a mid-drive; one voltage; one system

Required slots adapt to the bike: derailleur vs single/fixed/IGH, coaster brake (no rear brake or lever needed), disc (rotors), dropper (remote), e-bike (battery and display; no BB with a mid-drive).

3. Zero-fault inventory lifecycle

intake ─▶ categorized ─▶ measured ─▶ verified ─▶ listed ─▶ reserved ─▶ sold

verified is refused (HTTP 422 ZERO_FAULT_GATE, with a list of blockers) unless:

  1. The catalog part is human-verified and complete (a per-type completeness gate with conditional fields).
  2. It has a condition grade and ≥ MIN_PHOTOS_FOR_LISTING uploaded photos.
  3. For used and new_china items, every required measurement matches the catalog spec within tolerance and every wear limit passes. Wear limits now cover battery resting voltage, battery capacity test (≥70%) and a motor bench run, alongside chains, rotors, tyres, pads and true.

Re-verification audit: when the completeness gate grows, as it did in this release (chainline, rotor thickness, fork A2C and so on), previously verified parts that no longer pass drop to draft. Their listed items go back to measured. This runs automatically on boot after a rules-version change, and every downgrade is written to audit_log.

4. AI categorization (text + photos)

text/photos ─▶ rule parser (offline) ─▶ part-number match ─▶ LLM / vision (optional) ─▶ merge ─▶ review queue

5. Photos

POST /v1/inventory/:id/photos (multipart field file). JPEG/PNG/WebP are detected from the file's bytes rather than trusting the client. Photos are size-limited and SHA-256 hashed, and stored in STORAGE=local (UPLOAD_DIR) or STORAGE=s3 (AWS, MinIO, R2, B2). They are served at GET /v1/photos/:id and locked once the item is verified.

6. Rider fit (mechanical feasibility, not a bike fit)

POST /v1/fit/check and POST /v1/fit/frames check standover clearance per discipline, plus whether the seatpost can reach saddle height (inseam × 0.883, or a supplied saddle height) without breaching minimum insertion or bottoming out. Every assumption is returned with the answer. Reach and stack preference is deliberately not judged.

7. Seed data — read this

npm run seed loads 135 catalog parts (72 verified definitional, 63 needs_review) and 9 bikes:

Generic/definitional parts are seeded as verified. Branded and bike-specific values were entered from general knowledge and are needs_review. That includes derailleur capacities, frame/fork geometry and A2C, chainlines, caliper rotor-thickness ranges, BBS02 specs and the Nexus hub's spacing. Verify them against manufacturer sheets before relying on the no-return promise.

8. API (v1)

Workshop UI: /app/ (see above). Interactive docs: open http://localhost:3000/docs (Swagger UI, "Try it out" enabled). The OpenAPI JSON is at /docs/json; import it into Postman/Insomnia or generate a typed client for the e-commerce app. Request schemas are generated from the same Zod schemas the handlers validate with, so they can't drift, and a test fails if a route is added without docs. GET / returns a JSON index, or redirects browsers to /docs.

GET /v1/registry Part types, slots, required fields, measurements, standards, connections
POST /v1/compat/check Stateless pair or whole-build check
GET/POST /v1/catalog-parts, GET/PATCH /:id, POST /:id/verify, GET /:id/neighbours Catalog + graph neighbours
GET /v1/graph/interfaces[/:port/:value], GET /v1/graph/export?compat=true, POST /v1/graph/rebuild Graph
GET/POST /v1/bike-models, GET /:id, GET /:id/fits?slot=, POST /:id/builds Retail bikes and archetypes
GET/POST /v1/donor-bikes, GET /:id, POST /:id/strip Intake
GET/POST /v1/inventory, GET/PATCH /:id, POST /:id/{categorize,link,measurements,transition}, GET /:id/{sellability,compatible-bikes} Stock lifecycle
POST /v1/inventory/:id/photos, GET/DELETE /v1/photos/:id Photos
POST /v1/categorize, GET /v1/categorizations, POST /:id/{accept,reject} AI queue
POST /v1/builds, GET /:id, PUT/DELETE /:id/slots/:slot, GET /:id/candidates?slot= Frankenstein builds (scanned / truncated reported)
POST /v1/fit/check, POST /v1/fit/frames Rider fit
GET/PUT /v1/settings/tire-rim-table Load your verified ETRTO chart (persisted; graph rebuilt)

Send x-api-key when API_KEYS is set and x-actor for the audit trail. Prices are integers in minor units (cents). New records use DEFAULT_CURRENCY (USD unless set); each donor and item stores its own currency.

9. Honest limits

Contributing

Contributions are welcome, from new compatibility rules to catalog corrections with a source. Start with CONTRIBUTING.md and the step-by-step guide to adding a rule; open work is listed in docs/ROADMAP.md and on issues labelled good first issue. Please report security issues privately (see SECURITY.md).

License

Apache License 2.0. See NOTICE for attribution and bundled third-party components.