# ArchGuard Configuration Generator

You are helping initialize an `archguard.yml` configuration file for a Salesforce SFDX project.

## Task
Analyze the repository rooted at `{{PROJECT_ROOT}}` and generate a well-formed `archguard.yml` at the project root.

## Steps
1. Read `sfdx-project.json` to find `packageDirectories`. If missing, default to `force-app`.
2. For every folder that contains standard SFDX metadata-type subfolders (classes/, triggers/, objects/, lwc/, aura/, flows/, etc.), treat its parent as a "package". Collect paths relative to the project root using forward slashes.
3. Infer architectural **layers** from package names and the Apex code inside them. Typical patterns:
   - Packages with "Controller", "Service", "Handler", "Manager" → service layer
   - Packages named after business entities/domains → domain layer
   - Packages with "Utils", "Common", "Helpers", "Shared" → shared layer
   - Packages with "API", "Integration", "Webhook", "REST", "Callout" → integration layer
4. Define layers with acyclic `dependsOn` relationships. Higher layers depend on lower layers; shared has no dependencies.
5. Assign each discovered package to a layer.
6. Write the resulting YAML to `{{PROJECT_ROOT}}/archguard.yml`. Do NOT overwrite it if it already exists — abort and tell the user instead.

## Schema (exact keys, 2-space indentation)
```yaml
layers:
  - name: <layer-name>
    dependsOn: [<other-layer-names>]

packages:
  <package-name>:
    path: <relative-path-from-project-root>
    layer: <layer-name>
    # dependsOn: [<other-package-names>]  # optional exceptions

rules:
  severity: error           # or "warning"
  enforcePackageBoundaries: true
  enforceObjectBoundaries: true
  exclude:
    - "**/*Test.cls"
    - "**/*Mock.cls"
    - "**/*TestDataFactory.cls"
```

## Validation Rules
- Layer names unique, `dependsOn` references existing layers, NO cycles.
- Package names unique, paths relative with forward slashes, every layer reference must exist.
- Include short header comments explaining layers and packages.
- Do NOT run the archguard CLI — only create the file.

## Output
After writing the file, print a brief summary: number of layers, number of packages, and any assumptions you made.
