refactor(api): regroupe lib/ par sous-domaine au lieu d'un dossier à plat

9 fichiers à plat -> recipe-sources/ (recipe-source-adapter, recipe-source-
errors, recipe-source-registry) et recipe-matching/ (recipe-translation,
ingredient-matcher, tech-step-matcher). jwt.ts, safe-profile.ts et
logger.service.ts restent à la racine de lib/ (pas de sous-domaine
partagé avec les autres).

Chemins relatifs corrigés dans les fichiers déplacés (profondeur +1 vers
db/) et chez tous leurs importeurs (modules/sources, modules/recipe,
sources/*, db/recipe-source-sync.ts, 12 fichiers de test), doc mise à
jour (specs/backend-architecture.md, specs/batch-cooking-architecture.md).

Vérifié : tsc --noEmit, biome check, build complet, 303 tests API.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Nicolas 2026-08-21 11:21:49 +02:00
parent ae80537b7c
commit 4db8e1369f
26 changed files with 89 additions and 47 deletions

View file

@ -1,5 +1,5 @@
import type { PrismaClient } from "@prisma/client";
import { listRecipeSources } from "../lib/recipe-source-registry.js";
import { listRecipeSources } from "../lib/recipe-sources/recipe-source-registry.js";
/**
* Upserts one `Source` row (schema.prisma) per adapter currently in

View file

@ -3,7 +3,7 @@ import {
INGREDIENT_LABELS_EN,
UNIT_LABELS_EN,
} from "@batch-cooking/shared";
import { prisma } from "../db/prisma.js";
import { prisma } from "../../db/prisma.js";
import { normalizeText } from "./tech-step-matcher.js";
/**

View file

@ -1,4 +1,9 @@
import type { UnitType } from "@batch-cooking/shared";
import type {
ParsedRecipe,
ParsedRecipeIngredient,
ParsedRecipeStep,
} from "../recipe-sources/recipe-source-adapter.js";
import {
extractQuantity,
type IngredientMatchEntry,
@ -8,11 +13,6 @@ import {
matchUnit,
type UnitMatchEntry,
} from "./ingredient-matcher.js";
import type {
ParsedRecipe,
ParsedRecipeIngredient,
ParsedRecipeStep,
} from "./recipe-source-adapter.js";
import {
loadTechStepMappingRules,
matchTechSteps,

View file

@ -1,4 +1,4 @@
import { prisma } from "../db/prisma.js";
import { prisma } from "../../db/prisma.js";
/**
* Auto-detects which cooking techniques (`TechStep`) a free-text recipe

View file

@ -14,7 +14,10 @@ import {
} from "@batch-cooking/shared";
import type { Prisma } from "@prisma/client";
import { prisma } from "../../db/prisma.js";
import { loadTechStepMappingRules, matchTechStepSpans } from "../../lib/tech-step-matcher.js";
import {
loadTechStepMappingRules,
matchTechStepSpans,
} from "../../lib/recipe-matching/tech-step-matcher.js";
// No user-language preference exists anywhere in the app yet (a single
// "fr" translation file, no locale field on User/UserProfile) — steps are

View file

@ -15,15 +15,21 @@ import {
loadIngredientCatalog,
loadUnitCatalog,
type UnitMatchEntry,
} from "../../lib/ingredient-matcher.js";
import { markAlreadyImported, type RecipeSourceAdapter } from "../../lib/recipe-source-adapter.js";
import { RecipeSourceError } from "../../lib/recipe-source-errors.js";
import { getRecipeSource } from "../../lib/recipe-source-registry.js";
} from "../../lib/recipe-matching/ingredient-matcher.js";
import {
mergeDuplicateIngredients,
translateRecipeIngredients,
} from "../../lib/recipe-translation.js";
import { loadTechStepMappingRules, matchTechStepSpans } from "../../lib/tech-step-matcher.js";
} from "../../lib/recipe-matching/recipe-translation.js";
import {
loadTechStepMappingRules,
matchTechStepSpans,
} from "../../lib/recipe-matching/tech-step-matcher.js";
import {
markAlreadyImported,
type RecipeSourceAdapter,
} from "../../lib/recipe-sources/recipe-source-adapter.js";
import { RecipeSourceError } from "../../lib/recipe-sources/recipe-source-errors.js";
import { getRecipeSource } from "../../lib/recipe-sources/recipe-source-registry.js";
import { getHouseSourceIds } from "../house/house.service.js";
import { createImportedRecipe } from "../recipe/recipe.service.js";
import { getIngredients, getUnits } from "../reference/reference.service.js";

View file

@ -1,4 +1,4 @@
import { registerRecipeSource } from "../lib/recipe-source-registry.js";
import { registerRecipeSource } from "../lib/recipe-sources/recipe-source-registry.js";
import { theMealDbAdapter } from "./the-meal-db.js";
/**

View file

@ -2,8 +2,11 @@ import type {
ParsedRecipe,
ParsedRecipeIngredient,
RecipeSourceAdapter,
} from "../lib/recipe-source-adapter.js";
import { RecipeSourceFetchError, RecipeSourceParseError } from "../lib/recipe-source-errors.js";
} from "../lib/recipe-sources/recipe-source-adapter.js";
import {
RecipeSourceFetchError,
RecipeSourceParseError,
} from "../lib/recipe-sources/recipe-source-errors.js";
const SOURCE_KEY = "jsonLdRecipe";

View file

@ -3,8 +3,11 @@ import type {
RecipeSourceAdapter,
RecipeSourceListParams,
RecipeSourceListResult,
} from "../lib/recipe-source-adapter.js";
import { RecipeSourceFetchError, RecipeSourceParseError } from "../lib/recipe-source-errors.js";
} from "../lib/recipe-sources/recipe-source-adapter.js";
import {
RecipeSourceFetchError,
RecipeSourceParseError,
} from "../lib/recipe-sources/recipe-source-errors.js";
const SOURCE_KEY = "theMealDb";

View file

@ -6,8 +6,11 @@ import request from "supertest";
import { createApp } from "../src/app.js";
import { prisma } from "../src/db/prisma.js";
import { syncRecipeSources } from "../src/db/recipe-source-sync.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-source-adapter.js";
import { clearRecipeSources, registerRecipeSource } from "../src/lib/recipe-source-registry.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-sources/recipe-source-adapter.js";
import {
clearRecipeSources,
registerRecipeSource,
} from "../src/lib/recipe-sources/recipe-source-registry.js";
import { resetDatabase } from "../test-support/reset-db.js";
function buildSignupPayload(): SignupInput {

View file

@ -9,7 +9,7 @@ import {
matchIngredientName,
matchUnit,
type UnitMatchEntry,
} from "../src/lib/ingredient-matcher.js";
} from "../src/lib/recipe-matching/ingredient-matcher.js";
import { resetDatabase } from "../test-support/reset-db.js";
describe("ingredient-matcher", () => {

View file

@ -1,5 +1,8 @@
import { expect } from "chai";
import { RecipeSourceFetchError, RecipeSourceParseError } from "../src/lib/recipe-source-errors.js";
import {
RecipeSourceFetchError,
RecipeSourceParseError,
} from "../src/lib/recipe-sources/recipe-source-errors.js";
import { jsonLdRecipeAdapter } from "../src/sources/json-ld-recipe.js";
/** Stubs `globalThis.fetch` to return `html` as the response body — same reasoning/pattern as `the-meal-db.test.ts`'s `stubFetch`, just returning text instead of JSON. */

View file

@ -5,8 +5,11 @@ import request from "supertest";
import { createApp } from "../src/app.js";
import { prisma } from "../src/db/prisma.js";
import { findImportedRecipeIds, syncRecipeSources } from "../src/db/recipe-source-sync.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-source-adapter.js";
import { clearRecipeSources, registerRecipeSource } from "../src/lib/recipe-source-registry.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-sources/recipe-source-adapter.js";
import {
clearRecipeSources,
registerRecipeSource,
} from "../src/lib/recipe-sources/recipe-source-registry.js";
import { resetDatabase } from "../test-support/reset-db.js";
/** See `recipe.test.ts` — generated rather than hardcoded, no test fixture looks like a real person's data. */

View file

@ -5,19 +5,19 @@ import type {
RecipeSourceListItem,
RecipeSourceListParams,
RecipeSourceListResult,
} from "../src/lib/recipe-source-adapter.js";
import { markAlreadyImported } from "../src/lib/recipe-source-adapter.js";
} from "../src/lib/recipe-sources/recipe-source-adapter.js";
import { markAlreadyImported } from "../src/lib/recipe-sources/recipe-source-adapter.js";
import {
RecipeSourceError,
RecipeSourceFetchError,
RecipeSourceParseError,
} from "../src/lib/recipe-source-errors.js";
} from "../src/lib/recipe-sources/recipe-source-errors.js";
import {
clearRecipeSources,
getRecipeSource,
listRecipeSources,
registerRecipeSource,
} from "../src/lib/recipe-source-registry.js";
} from "../src/lib/recipe-sources/recipe-source-registry.js";
interface FakeRawRecipe {
externalId: string;

View file

@ -1,7 +1,9 @@
import { expect } from "chai";
import { prisma } from "../src/db/prisma.js";
import type { IngredientMatchEntry, UnitMatchEntry } from "../src/lib/ingredient-matcher.js";
import type { ParsedRecipe, ParsedRecipeIngredient } from "../src/lib/recipe-source-adapter.js";
import type {
IngredientMatchEntry,
UnitMatchEntry,
} from "../src/lib/recipe-matching/ingredient-matcher.js";
import {
mergeDuplicateIngredients,
type TranslatedRecipeIngredient,
@ -9,8 +11,12 @@ import {
translateRecipeIngredients,
translateRecipeSteps,
type UnitConversionEntry,
} from "../src/lib/recipe-translation.js";
import type { TechStepMappingRule } from "../src/lib/tech-step-matcher.js";
} from "../src/lib/recipe-matching/recipe-translation.js";
import type { TechStepMappingRule } from "../src/lib/recipe-matching/tech-step-matcher.js";
import type {
ParsedRecipe,
ParsedRecipeIngredient,
} from "../src/lib/recipe-sources/recipe-source-adapter.js";
import { resetDatabase } from "../test-support/reset-db.js";
/** A minimal fixture `ParsedRecipe` — only `steps` (built from `descriptions`) matters for most tests here, the rest is filler to prove it survives translation untouched. */

View file

@ -6,8 +6,11 @@ import request from "supertest";
import { createApp } from "../src/app.js";
import { prisma } from "../src/db/prisma.js";
import { syncRecipeSources } from "../src/db/recipe-source-sync.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-source-adapter.js";
import { clearRecipeSources, registerRecipeSource } from "../src/lib/recipe-source-registry.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-sources/recipe-source-adapter.js";
import {
clearRecipeSources,
registerRecipeSource,
} from "../src/lib/recipe-sources/recipe-source-registry.js";
import { resetDatabase } from "../test-support/reset-db.js";
/** A minimal `RecipeSourceAdapter` — only `key`/`name`/`official`/`iconUrl` matter for `syncRecipeSources` fixtures here. */
@ -60,7 +63,7 @@ async function techStepId(key: string): Promise<number> {
return techStep.id;
}
/** A step's detected technique sequence, in order — mirrors `matchTechSteps`' return shape (`../src/lib/tech-step-matcher.js`) so tests can assert on it directly. */
/** A step's detected technique sequence, in order — mirrors `matchTechSteps`' return shape (`../src/lib/recipe-matching/tech-step-matcher.js`) so tests can assert on it directly. */
async function stepTechStepIds(stepId: number): Promise<number[]> {
const links = await prisma.stepTechStep.findMany({
where: { stepId },

View file

@ -4,8 +4,11 @@ import { createApp } from "../src/app.js";
import { prisma } from "../src/db/prisma.js";
import { syncRecipeSources } from "../src/db/recipe-source-sync.js";
import { seedReferenceData } from "../src/db/reference-seed-data.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-source-adapter.js";
import { clearRecipeSources, registerRecipeSource } from "../src/lib/recipe-source-registry.js";
import type { RecipeSourceAdapter } from "../src/lib/recipe-sources/recipe-source-adapter.js";
import {
clearRecipeSources,
registerRecipeSource,
} from "../src/lib/recipe-sources/recipe-source-registry.js";
import { resetDatabase } from "../test-support/reset-db.js";
/** A minimal `RecipeSourceAdapter` — only `key`/`name`/`official`/`iconUrl` matter for `syncRecipeSources` fixtures here. */

View file

@ -3,7 +3,7 @@ import {
clearRecipeSources,
getRecipeSource,
listRecipeSources,
} from "../src/lib/recipe-source-registry.js";
} from "../src/lib/recipe-sources/recipe-source-registry.js";
import { registerAllRecipeSources } from "../src/sources/index.js";
// Not exercised by any other test file — `registerAllRecipeSources` is

View file

@ -11,9 +11,12 @@ import type {
RecipeSourceAdapter,
RecipeSourceListParams,
RecipeSourceListResult,
} from "../src/lib/recipe-source-adapter.js";
import { RecipeSourceFetchError } from "../src/lib/recipe-source-errors.js";
import { clearRecipeSources, registerRecipeSource } from "../src/lib/recipe-source-registry.js";
} from "../src/lib/recipe-sources/recipe-source-adapter.js";
import { RecipeSourceFetchError } from "../src/lib/recipe-sources/recipe-source-errors.js";
import {
clearRecipeSources,
registerRecipeSource,
} from "../src/lib/recipe-sources/recipe-source-registry.js";
import { resetDatabase } from "../test-support/reset-db.js";
/** See `recipe.test.ts` — generated rather than hardcoded, no test fixture looks like a real person's data. */

View file

@ -6,7 +6,7 @@ import {
matchTechSteps,
normalizeText,
type TechStepMappingRule,
} from "../src/lib/tech-step-matcher.js";
} from "../src/lib/recipe-matching/tech-step-matcher.js";
import { resetDatabase } from "../test-support/reset-db.js";
describe("tech-step-matcher", () => {

View file

@ -1,5 +1,8 @@
import { expect } from "chai";
import { RecipeSourceFetchError, RecipeSourceParseError } from "../src/lib/recipe-source-errors.js";
import {
RecipeSourceFetchError,
RecipeSourceParseError,
} from "../src/lib/recipe-sources/recipe-source-errors.js";
import { type TheMealDbMeal, theMealDbAdapter } from "../src/sources/the-meal-db.js";
/**

View file

@ -286,7 +286,7 @@ Le module « Import d'une recette » du plan initial (voir
[batch-cooking-architecture.md](./batch-cooking-architecture.md)) est
implémenté. Pièces principales :
### `RecipeSourceAdapter` (`apps/api/src/lib/recipe-source-adapter.ts`)
### `RecipeSourceAdapter` (`apps/api/src/lib/recipe-sources/recipe-source-adapter.ts`)
Contrat générique que chaque source concrète implémente : `list(params)`
(parcours paginé, `query`/`cursor` optionnels), `fetchDetail(externalId)`

View file

@ -56,7 +56,7 @@ Logique de calcul du batch-cooking (optimisation du planning/des recettes selon
1. **Import depuis source** — chaque source concrète (aujourd'hui : TheMealDB,
API officielle) implémente le contrat `RecipeSourceAdapter`
(`apps/api/src/lib/recipe-source-adapter.ts` — `list`/`fetchDetail`/`parse`),
(`apps/api/src/lib/recipe-sources/recipe-source-adapter.ts` — `list`/`fetchDetail`/`parse`),
enregistré dans un registre en mémoire et synchronisé vers la table
`sources`. Un scraper générique JSON-LD/schema.org (`json-ld-recipe.ts`)
existe aussi, en briques réutilisables par un futur adaptateur dédié à un