166 lines
7.3 KiB
Markdown
166 lines
7.3 KiB
Markdown
# MeshiTrack Monorepo Clean-up Blueprint
|
|
|
|
This playbook maps out the precise, incremental, batch-by-batch process to refactor all remaining active modules in both `@meshitrack/api` and `@meshitrack/web` to achieve complete ESLint compliance under our strict new guidelines, while keeping our **100.00% test coverage** pristine.
|
|
|
|
---
|
|
|
|
## 🚀 The Core Refactoring Strategy
|
|
|
|
For every class/module we clean up, we follow the established **Shopping Lists Reference Standard**:
|
|
1. **Repositories**:
|
|
* Add explicit type parameter annotations for return values (e.g. `: Promise<Document | null>`).
|
|
* Put private helper methods at the very bottom (under public methods) to satisfy `@typescript-eslint/member-ordering`.
|
|
* Type query filters explicitly rather than using `any`.
|
|
2. **Services**:
|
|
* Keep class properties explicit and `readonly` (e.g. `private readonly repository: Repository`).
|
|
* Add explicit return signatures (e.g. `: Promise<ShoppingListDocument>`).
|
|
* Avoid `any` completely; use precise casts (e.g. `as ServingUnit`) or type guards.
|
|
3. **Routes**:
|
|
* Cast Fastify inputs explicitly (`request.params as { ... }` and `request.body as ...`).
|
|
* Annotate serialization return contracts explicitly (e.g. `serializeList(doc: Document): SerializedContract`).
|
|
* Wrap WebSocket handshakes or un-typed third party plugins in local ESLint overrides.
|
|
|
|
---
|
|
|
|
## 📅 The Batch Playbook
|
|
|
|
### 🧱 Batch 1: Core Identity & Household Foundation
|
|
Enforces structural types on our identity schemas, auth profiles, and tenant containers.
|
|
|
|
* **Target Backend Files**:
|
|
* `packages/api/src/modules/users/users.repository.ts`
|
|
* `packages/api/src/modules/users/users.service.ts`
|
|
* `packages/api/src/modules/users/users.routes.ts`
|
|
* `packages/api/src/modules/households/households.repository.ts`
|
|
* `packages/api/src/modules/households/households.service.ts`
|
|
* `packages/api/src/modules/households/households.routes.ts`
|
|
* **Key Focus**:
|
|
* Ensure user keycloak sync mapping has explicit return contracts.
|
|
* Cast tenant properties safely across fastify injection boundaries.
|
|
* **Verification Runner**:
|
|
```bash
|
|
cd packages/api
|
|
npx eslint src/modules/users src/modules/households --fix
|
|
npx vitest run tests/modules/users tests/modules/households
|
|
```
|
|
|
|
---
|
|
|
|
### 💊 Batch 2: Medicine Cabinet & Consumption Logs
|
|
Refactors the active cabinet inventory, item counts, and historical events tracking.
|
|
|
|
* **Target Backend Files**:
|
|
* `packages/api/src/modules/medicines/medicines.repository.ts`
|
|
* `packages/api/src/modules/medicines/medicines.service.ts`
|
|
* `packages/api/src/modules/medicines/medicines.routes.ts`
|
|
* `packages/api/src/modules/cabinet/cabinet.repository.ts`
|
|
* `packages/api/src/modules/cabinet/cabinet.service.ts`
|
|
* `packages/api/src/modules/cabinet/cabinet.routes.ts`
|
|
* `packages/api/src/modules/cabinet-events/cabinet-events.repository.ts`
|
|
* `packages/api/src/modules/cabinet-events/cabinet-events.service.ts`
|
|
* `packages/api/src/modules/cabinet-events/cabinet-events.routes.ts`
|
|
* **Key Focus**:
|
|
* Clean up dosage calculations in the service layer, replacing implicit float types.
|
|
* Ensure strict sorting sequence in historical event queries.
|
|
* **Verification Runner**:
|
|
```bash
|
|
cd packages/api
|
|
npx eslint src/modules/medicines src/modules/cabinet src/modules/cabinet-events --fix
|
|
npx vitest run tests/modules/medicines tests/modules/cabinet tests/modules/cabinet-events
|
|
```
|
|
|
|
---
|
|
|
|
### 🏪 Batch 3: Store Catalog & Price Registry
|
|
Enforces type safety on retail outlets, product mappings, and historical pricing logs.
|
|
|
|
* **Target Backend Files**:
|
|
* `packages/api/src/modules/stores/stores.repository.ts`
|
|
* `packages/api/src/modules/stores/stores.service.ts`
|
|
* `packages/api/src/modules/stores/stores.routes.ts`
|
|
* `packages/api/src/modules/medicine-products/medicine-products.repository.ts`
|
|
* `packages/api/src/modules/medicine-products/medicine-products.service.ts`
|
|
* `packages/api/src/modules/medicine-products/medicine-products.routes.ts`
|
|
* `packages/api/src/modules/medicine-prices/medicine-prices.repository.ts`
|
|
* `packages/api/src/modules/medicine-prices/medicine-prices.service.ts`
|
|
* `packages/api/src/modules/medicine-prices/medicine-prices.routes.ts`
|
|
* **Key Focus**:
|
|
* Eradicate `any` structures used in price conversions and store tags.
|
|
* **Verification Runner**:
|
|
```bash
|
|
cd packages/api
|
|
npx eslint src/modules/stores src/modules/medicine-products src/modules/medicine-prices --fix
|
|
npx vitest run tests/modules/stores tests/modules/medicine-products tests/modules/medicine-prices
|
|
```
|
|
|
|
---
|
|
|
|
### ⏰ Batch 4: Regimens, Refills & Alert Scheduler
|
|
Tracks routines, alert thresholds, and automated refilling triggers.
|
|
|
|
* **Target Backend Files**:
|
|
* `packages/api/src/modules/regimens/regimens.repository.ts`
|
|
* `packages/api/src/modules/regimens/regimens.service.ts`
|
|
* `packages/api/src/modules/regimens/regimens.routes.ts`
|
|
* `packages/api/src/modules/refills/refills.repository.ts`
|
|
* `packages/api/src/modules/refills/refills.service.ts`
|
|
* `packages/api/src/modules/refills/refills.routes.ts`
|
|
* `packages/api/src/modules/organizer/organizer.repository.ts`
|
|
* `packages/api/src/modules/organizer/organizer.service.ts`
|
|
* `packages/api/src/modules/organizer/organizer.routes.ts`
|
|
* **Key Focus**:
|
|
* Explicitly handle routine status triggers and scheduling date windows.
|
|
* **Verification Runner**:
|
|
```bash
|
|
cd packages/api
|
|
npx eslint src/modules/regimens src/modules/refills src/modules/organizer --fix
|
|
npx vitest run tests/modules/regimens tests/modules/refills tests/modules/organizer
|
|
```
|
|
|
|
---
|
|
|
|
### 🧠 Batch 5: Nutrition, LLM Providers & Health
|
|
Enforces guidelines on target metrics, no-op mock LLM interfaces, and health endpoints.
|
|
|
|
* **Target Backend Files**:
|
|
* `packages/api/src/modules/nutrition-targets/nutrition-target.repository.ts`
|
|
* `packages/api/src/modules/nutrition-targets/nutrition-target.service.ts`
|
|
* `packages/api/src/modules/nutrition-targets/nutrition-target.routes.ts`
|
|
* `packages/api/src/modules/llm/no-op-llm.provider.ts`
|
|
* `packages/api/src/modules/health/health.routes.ts`
|
|
* **Key Focus**:
|
|
* Annotate mock responses in the LLM provider class explicitly.
|
|
* **Verification Runner**:
|
|
```bash
|
|
cd packages/api
|
|
npx eslint src/modules/nutrition-targets src/modules/llm src/modules/health --fix
|
|
npx vitest run tests/modules/nutrition-targets tests/modules/llm tests/modules/health
|
|
```
|
|
|
|
---
|
|
|
|
### 💻 Batch 6: Frontend API Client Services
|
|
Brings complete TypeScript strictness to our web fetch and Axios mock endpoints.
|
|
|
|
* **Target Frontend Files**:
|
|
* `packages/web/src/services/api-client.ts`
|
|
* `packages/web/src/services/cabinet.ts`
|
|
* `packages/web/src/services/cabinet-events.ts`
|
|
* `packages/web/src/services/households.ts`
|
|
* `packages/web/src/services/medicines.ts`
|
|
* `packages/web/src/services/medicine-prices.ts`
|
|
* `packages/web/src/services/nutrition-targets.ts`
|
|
* `packages/web/src/services/organizer.ts`
|
|
* `packages/web/src/services/refills.ts`
|
|
* `packages/web/src/services/regimens.ts`
|
|
* `packages/web/src/services/shopping-lists.ts`
|
|
* `packages/web/src/services/stores.ts`
|
|
* **Key Focus**:
|
|
* Annotate Axios return response structures explicitly as `Promise<AxiosResponse<T>>` or type mappers.
|
|
* Eliminate implicit parameters.
|
|
* **Verification Runner**:
|
|
```bash
|
|
cd packages/web
|
|
npx eslint src/services --fix
|
|
npx vitest run tests/services
|
|
```
|