Morocco has no reliable public reference for used-car prices. The existing price guides ("cotes") ask only for make, model, year and mileage, and they do not explain their numbers. Asking prices on listing sites run above what cars actually sell for. Qima estimates a used car's value in Moroccan dirhams (MAD) and shows how it got there:
- a price range: private sale, dealer trade-in and dealer retail;
- a confidence score;
- the list of factors that raised or lowered the price, each in % and in MAD.
It is for people buying or selling a used car in Morocco, and for developers who want a transparent, testable valuation engine to build on. The interface is in French and Arabic (right-to-left).
Estimates are indicative, not an expert appraisal. The valuation coefficients are explicit assumptions that still need calibrating against real sale prices (see docs/research/coverage-findings.md).
The form (step 1 of 3):
The result page, in French and in Arabic (right-to-left):
![]() |
![]() |
Example: Peugeot 308 1.5 BlueHDi 130 EAT8 (2022, 60 000 km), valued with the public sample seed.
- Valuation engine (
packages/engine), pure TypeScript with no I/O:- v1 rules: the new price at the time of first registration, adjusted for age (curve per segment and brand tier), mileage vs. the expected mileage for that age, condition and market factors (origin, owners, city, gearbox, colour, options);
- v2 comparables: blends comparable listings and reported sales into the rules estimate.
- Every output carries
engineVersion, a low/fair/high range,confidenceandfactors.
- Versioned coefficients: no valuation constant is hard-coded. Coefficients live in a database table, are versioned, and can be edited and re-activated from an admin page.
- Web app (
apps/web, Next.js):- 3-step form (identification, history, condition) and a result page, in French and Arabic;
- an "I sold / bought it at X" feedback form that collects real transaction prices.
- REST API:
POST /api/v1/valuate,GET /api/v1/catalog,POST /api/v1/feedback. All input is validated with zod schemas frompackages/shared. - Data pipeline (
scripts,packages/sources):- seed catalog import and checks;
- CSV import for partner and listing exports, which refuses files containing personal-data columns;
- a backtest (MAPE, range calibration, acceptance test, comparison against a simple rule-of-thumb baseline) and calibration of the depreciation curve.
- Mobile app (
apps/mobile): planned (Expo). The folder is a placeholder today.
TypeScript (strict) · pnpm workspaces + Turborepo · Next.js 15 (App Router) + React 19 · PostgreSQL + Drizzle ORM · zod · Vitest · ESLint + Prettier · Docker Compose for local Postgres.
| Path | What |
|---|---|
packages/engine |
Valuation engine, default coefficients, golden test cases (src/__golden__/). |
packages/shared |
zod schemas, enums, French/Arabic UI strings. |
packages/db |
Drizzle schema, migrations, repositories. |
packages/sources |
Listing ingestion adapters (CSV) and normalization to catalog versions. |
apps/web |
Next.js app: form, result page, admin, /api/v1/*. |
apps/mobile |
Placeholder for the Expo app. |
scripts |
Seed import/check, listings import, backtest, calibration and research CLIs. |
data/ |
Seed catalog, reference catalog and templates (see each folder's README). |
docs/ |
Product spec (docs/SPEC.md) and research notes. |
Requirements: Node.js ≥ 20, pnpm 10 (corepack enable), Docker.
pnpm install
docker compose up -d # local Postgres (needed by db integration tests and the app)
cp apps/web/.env.example apps/web/.env.local # then set ADMIN_PASSWORD
pnpm --filter @qima/db db:migrate # needs DATABASE_URL
pnpm seed:import # catalog + filled prices + default coefficients (needs DATABASE_URL)
pnpm --filter @qima/web dev # http://localhost:3000/fr
pnpm lint && pnpm testOther commands:
pnpm seed:check # validate data/seed CSVs
pnpm listings:import <file.csv> --source <slug> [--dry-run] # partner exports, listings (data/listings/README.md)
pnpm backtest [--cutoff YYYY-MM-DD] # MAPE, acceptance test, coverage, benchmarks → reports/
pnpm calibrate [--publish] # fit depreciation per segment from market data
pnpm hedonic # new-price model, leave-one-model-out error
pnpm priority # which unpriced models to license/price first
pnpm version-key # carte grise key → catalog version match rate
pnpm catalog:coverage # priced vs known models- Admin:
/fr/admin/coefficients, with HTTP basic auth (useradmin, passwordADMIN_PASSWORD). Saving creates a new coefficients version and activates it. Older versions can be re-activated. - A version with no row in
new_pricescannot be valued yet (the API returns422 NO_NEW_PRICE). - Integration tests use
TEST_DATABASE_URL(defaultpostgres://qima:qima@localhost:5432/qima_test). Create that database once.
fair = newPrice × age × mileage × condition × market
range = fair × (1 ± spread(confidence))
tradeIn = fair × (1 − dealerMargin(segment))
With market data, comparables of the same generation, fuel and gearbox are used:
- the selection window is year ±1 and km ±30 %;
- each comparable is normalized to the subject's age and mileage;
- listing (asking) prices are discounted to transaction level;
- the result is blended with the rules estimate, with weight
w = min(1, n / 20).
All of these parameters are coefficients (comps.*). Without market data, v2 returns exactly the v1 result. The full
design is in docs/SPEC.md.
Contributions are welcome: bug reports, coefficient calibration ideas backed by data, catalog fixes and code. Please read CONTRIBUTING.md first. Two project rules matter most:
- valuation coefficients are never hard-coded in logic;
- no personal data from listings (names, phone numbers) is ever stored.
Before adding any data source, check its terms of use.
MIT © 2026 bouchidocode


