# Module Wiring Parity Check

## Context

App: {{APP_NAME}}
Resolver docs: {{RESOLVER_DOCS}}
Backend modules file: {{BACKEND_MODULES}}
Backend modules-db file: {{BACKEND_MODULES_DB}}
Backend config file: {{BACKEND_CONFIG}}

## Instructions

1. Read ALL resolver docs at the paths above
2. Read the modules file (`src/modules.ts`) and the modules-db file (`src/modules-db.ts`)
3. Read the config file (`tailor.config.ts`)
4. Verify all required modules are wired and configured
5. Return results as JSON per the Output Format section

## Extraction: Resolver Docs

From each resolver doc, extract:

- Module it depends on (which `defineXxxModule` it needs)
- Commands it calls (which module command functions)

## Extraction: modules.ts and modules-db.ts

From `modules.ts`, extract:

- All `defineXxxModule()` calls
- Inter-module dependency wiring (e.g., primitives passed to item-management)
- Exported module objects (`umModules`, `imModules`, etc.)

From `modules-db.ts`, extract:

- Individual DB table exports (destructured from module objects)
- This file must NOT be imported by resolvers

## Extraction: tailor.config.ts

From the config file, extract:

- DB namespace configuration
- Resolver/executor glob patterns
- Auth configuration (IdP, Auth, user profile)
- Generator configuration

## Parity Checks

| Check ID             | Question                                                         |
| -------------------- | ---------------------------------------------------------------- |
| module_wired         | Is every module referenced by resolvers wired in modules.ts and exported in modules-db.ts? |
| dependency_order     | Are inter-module dependencies passed correctly?                  |
| exports_complete     | Are db, commands, and executors all exported?                    |
| config_resolver_glob | Does the resolver glob in config cover all resolver directories? |
| config_executor_glob | Does the executor glob in config cover all executor files?       |
| config_db_namespace  | Is the DB namespace configured?                                  |
| config_auth          | Is auth configured with IdP, Auth, and user profile?             |

### How to Check

1. Build a set of required modules from resolver docs
2. Check each required module appears as a `defineXxxModule()` call in modules.ts and its DB types are exported in modules-db.ts
3. Verify dependency wiring (e.g., if item-management resolvers exist, primitives must be wired into it)
4. Check tailor.config.ts db.files references modules-db.ts and resolver glob pattern covers all resolver directories
5. Verify auth is configured if any resolver requires authentication

## Common Gap Patterns

- **Missing module**: Resolver references a module not wired in modules.ts or not exported in modules-db.ts
- **Missing dependency**: Module wired but not given required dependencies
- **Glob mismatch**: Config resolver glob doesn't cover a module's resolvers directory
- **Missing auth**: Resolvers exist but no auth configured
- **Missing executors**: Module has event handlers but no executor glob configured

## Output Format

Return a JSON object:

```json
{
  "check_type": "module-wiring-parity",
  "app": "{{APP_NAME}}",
  "gaps": [...],
  "inconsistencies": [...],
  "summary": { "total_checks": N, "passed": N, "failed": N, "skipped": N }
}
```

See [impl-parity-report-format.md](impl-parity-report-format.md) for field definitions.
