|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Working With Claude |
| 4 | + |
| 5 | +Whenever the user says "No" or corrects an approach, update this file with the relevant rule so the same mistake is not repeated. |
| 6 | + |
| 7 | +## Project Overview |
| 8 | + |
| 9 | +Aligent's TypeScript monorepo for microservice development utilities. Managed by **Nx 22** with **npm workspaces**. Node.js v22 required (see `.nvmrc`). |
| 10 | + |
| 11 | +## Packages |
| 12 | + |
| 13 | +| Package | Purpose | |
| 14 | +|---------|---------| |
| 15 | +| `packages/appbuilder-util-lib` | Adobe App Builder utilities (logging, DB, files, state, auth) | |
| 16 | +| `packages/create-workspace` | CLI scaffolding tool for new Nx workspaces | |
| 17 | +| `packages/microservice-util-lib` | Core utilities (AWS SDK, OAuth, OpenAPI clients) | |
| 18 | +| `packages/nx-cdk` | Nx plugin with generators for AWS CDK projects | |
| 19 | +| `packages/nx-openapi` | Nx plugin with generators for OpenAPI client generation | |
| 20 | + |
| 21 | +## Common Commands |
| 22 | + |
| 23 | +```bash |
| 24 | +# Install dependencies |
| 25 | +npm install |
| 26 | + |
| 27 | +# Build / Test / Lint / Type-check — affected packages only |
| 28 | +npm run build |
| 29 | +npm test |
| 30 | +npm run lint |
| 31 | +npm run check-types |
| 32 | + |
| 33 | +# Run across all packages |
| 34 | +npm run build:all |
| 35 | +npm run test:all |
| 36 | +npm run lint:all |
| 37 | +npm run check-types:all |
| 38 | + |
| 39 | +# Single package |
| 40 | +npx nx build @aligent/microservice-util-lib |
| 41 | +npx nx test @aligent/nx-cdk |
| 42 | + |
| 43 | +# Preview generator changes without writing files |
| 44 | +npx nx g @tools/generators:package --dry-run |
| 45 | +npx nx g @aligent/nx-cdk:service --dry-run |
| 46 | +``` |
| 47 | + |
| 48 | +## Testing |
| 49 | + |
| 50 | +- Framework: **Vitest** with v8 coverage provider |
| 51 | +- Coverage threshold: **80%** across branches, functions, lines, and statements |
| 52 | +- Tests live alongside source in `src/` or under `tests/`, matching `**/*.{test,spec}.ts` |
| 53 | +- Files prefixed with `/* v8 ignore start */` are excluded from coverage |
| 54 | + |
| 55 | +## Code Style |
| 56 | + |
| 57 | +- **4-space indentation** (2 for YAML/JSON — see `.editorconfig`) |
| 58 | +- **LF** line endings, **100-char** max line width |
| 59 | +- Linting via `@aligent/ts-code-standards` (ESLint + Prettier) |
| 60 | +- Run `npm run lint` before committing; pre-commit hooks are configured via `prepare` |
| 61 | + |
| 62 | +### TypeScript |
| 63 | + |
| 64 | +- **Never use the non-null assertion operator (`!`)**. Use explicit runtime checks instead so errors surface with a clear message rather than a runtime crash. |
| 65 | + |
| 66 | + ```ts |
| 67 | + // Bad |
| 68 | + const content = tree.read(path, 'utf-8')!; |
| 69 | + |
| 70 | + // Good |
| 71 | + const content = tree.read(path, 'utf-8'); |
| 72 | + if (content === null) { |
| 73 | + throw new Error(`Failed to read file: ${path}`); |
| 74 | + } |
| 75 | + ``` |
| 76 | + |
| 77 | +## Architecture Notes |
| 78 | + |
| 79 | +### NX Generators |
| 80 | + |
| 81 | +Generators in `packages/nx-cdk` and `packages/nx-openapi` must route **all file I/O through the NX `Tree`** object — never use `fs` or third-party APIs (e.g. `ts-morph`'s `.save()`) to write directly to disk. This ensures `--dry-run` works correctly, as NX handles dry-run by not flushing the Tree. |
| 82 | + |
| 83 | +- Use `tree.read()` / `tree.write()` / `tree.exists()` instead of `fs.*` / `existsSync` |
| 84 | +- When using `ts-morph` for AST manipulation, use `InMemoryFileSystemHost` and write the result back via `tree.write()` |
| 85 | + |
| 86 | +### TypeScript Project References |
| 87 | + |
| 88 | +The root `tsconfig.json` uses project references. When adding a new package or service, the reference must be added via `addTsConfigReference()` (which updates `tsconfig.json` through the Tree). |
| 89 | + |
| 90 | +### Release Process |
| 91 | + |
| 92 | +Independent versioning per package using **Nx Version Plans**. |
| 93 | + |
| 94 | +1. Create a `releases/*` branch from `main` |
| 95 | +2. Run `npm run release-plan` to generate a version plan file in `.nx/version-plans/` |
| 96 | +3. Push — the `release` workflow bumps versions, removes the plan file, and opens a "Publish" PR |
| 97 | +4. Merge the Publish PR → `publish` workflow builds and publishes to npm |
| 98 | + |
| 99 | +> Only one version plan file should exist at a time. Multiple plans produce unpredictable results. |
| 100 | +
|
| 101 | +## Branch Naming |
| 102 | + |
| 103 | +- Features: `feat/MI-{issue}-{description}` |
| 104 | +- Fixes: `fix/MI-{issue}-{description}` |
| 105 | +- Releases: `releases/{package-name}-{version}` |
| 106 | + |
| 107 | +## Local Registry Testing |
| 108 | + |
| 109 | +```bash |
| 110 | +npx nx start-local-registry microservice-development-utilities |
| 111 | +npx nx release publish # publish to local Verdaccio registry |
| 112 | +npx nx stop-local-registry microservice-development-utilities |
| 113 | +``` |
0 commit comments