"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateClaudeMd = generateClaudeMd;
/**
 * Generates the CLAUDE.md file content for a generated project.
 * This file provides guidance to Claude Code when working with the generated codebase.
 */
function generateClaudeMd(params) {
    const { schema, isWorkspaceProject } = params;
    const projectName = schema.name || schema.slug;
    return `# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

**${projectName}** is a full-stack TypeScript application generated by PostXL. ${schema.description ? `${schema.description}` : ''}

**Key Technologies:**
- **Backend**: NestJS with Fastify, Prisma ORM, tRPC
- **Frontend**: Vite, React 19, TanStack Router/Query/Form/Table, Tailwind CSS
- **Testing**: Jest (backend), Vitest (frontend), Playwright (E2E)
- **Database**: PostgreSQL with Prisma
- **Authentication**: Keycloak (when enabled)
- **Package Manager**: pnpm (required)

## Project Structure

\`\`\`
${projectName}/
├── backend/                 # NestJS backend application
│   ├── apps/api/           # Main API entry point
│   └── libs/               # Generated and custom libraries
│       ├── actions/        # Business logic action handlers
│       ├── authentication/ # Auth configuration
│       ├── repositories/   # Data access layer (Prisma/InMemory)
│       ├── router-trpc/    # tRPC API routers
│       ├── types/          # TypeScript types and DTOs
│       ├── view/           # View/query services
│       └── ...             # Other generated libraries
├── frontend/               # Vite + React frontend
│   └── src/
│       ├── components/     # React components
│       ├── pages/          # Page components
│       ├── routes/         # TanStack Router file-based routes
│       ├── hooks/          # Custom React hooks
│       ├── lib/            # Utilities and tRPC client
│       └── stories/        # Storybook stories
├── e2e/                    # Playwright E2E tests
├── postxl-schema.json      # Project schema definition
├── generate.ts             # Generator configuration
└── postxl-lock.json        # Tracks generated files
\`\`\`

## Quick Start

\`\`\`bash
# Install dependencies and set up environment
pnpm run setup

# Start database and Keycloak (Docker required)
docker compose up -d db keycloak

# Apply database migrations
pnpm prisma migrate dev

# Start backend (in one terminal)
cd backend && pnpm run dev

# Start frontend (in another terminal)
cd frontend && pnpm run dev
\`\`\`

## Common Commands

### Project Root

\`\`\`bash
# Initial setup (installs deps, copies .env files)
pnpm run setup

# Run code generation
pnpm run generate

# Force regenerate all files
pnpm run generate -f

# Regenerate specific files (glob pattern)
pnpm run generate -f -p 'backend/libs/types/**/*.ts'

# Ignore manually modified generated files during generation
pnpm run generate -i

# Watch mode for development
pnpm run generate:watch

# Run linting across project
pnpm run lint

# Start Docker services
pnpm run docker
# or
docker compose up -d db keycloak
\`\`\`

### Backend Commands

\`\`\`bash
cd backend

# Development modes
pnpm run dev              # Stateless, no auth (fastest startup)
pnpm run dev:auth         # With authentication
pnpm run dev:stateful     # With database persistence
pnpm run dev:stateful:auth # Full mode with auth and persistence

# Build and test
pnpm run build            # Build backend
pnpm run test:jest        # Run unit tests
pnpm run test:types       # Type checking
pnpm run lint             # Lint backend code

# E2E backend modes
pnpm run e2e:stateless    # For E2E testing without DB
pnpm run e2e:stateful     # For E2E testing with DB
\`\`\`

### Frontend Commands

\`\`\`bash
cd frontend

# Development
pnpm run dev              # Start Vite dev server
pnpm run dev:noAuth       # Dev mode without authentication

# Build and test
pnpm run build            # Production build
pnpm run preview          # Preview production build
pnpm run test:types       # Type checking
pnpm run lint             # Lint frontend code

# Storybook
pnpm run storybook:start  # Start Storybook
pnpm run storybook:build  # Build Storybook
pnpm run test:storybook   # Run Storybook tests
\`\`\`

### E2E Testing

\`\`\`bash
cd e2e

# Run E2E tests
pnpm run e2e:stateless    # Stateless mode (in-memory)
pnpm run e2e:stateful     # Stateful mode (with database)

# Interactive mode with Playwright UI
pnpm run e2e:ui:stateless
pnpm run e2e:ui:stateful

# Update snapshots
pnpm run e2e:update-snapshots:stateless
pnpm run e2e:update-snapshots:stateful

# Run specific test
pnpm pw test path/to/test.spec.ts
pnpm pw test -g "test title pattern"
\`\`\`

### Database Commands

\`\`\`bash
# Apply migrations (creates tables)
pnpm prisma migrate dev

# Generate Prisma client
pnpm run generate:prisma

# Open Prisma Studio (database GUI)
pnpm prisma studio

# Reset database
pnpm prisma migrate reset
\`\`\`

## Custom Code Preservation

When you extend generated files with custom code, use special comment markers to preserve your additions during regeneration:

\`\`\`typescript
import { Injectable } from '@nestjs/common'

// @custom-start:additionalImports
import { CustomLogger } from './logger'
// @custom-end:additionalImports

@Injectable()
export class UserService {
  // Generated methods here...

  // @custom-start:customMethods
  customBusinessLogic() {
    return 'custom implementation'
  }
  // @custom-end:customMethods
}
\`\`\`

**How it works:**
1. Mark custom code blocks with \`// @custom-start\` and \`// @custom-end\` comments
2. Optionally add a name: \`// @custom-start:myFeature\` and \`// @custom-end:myFeature\`
3. When the generator runs and detects changes:
   - Custom blocks are extracted from your modified file
   - They are automatically re-inserted into the generated output
   - Only actual conflicts (outside custom blocks) will show merge conflict markers

**Supported marker styles:**
\`\`\`typescript
// Line comment style
// @custom-start:featureName
// ... custom code ...
// @custom-end:featureName

/* Block comment style */
/* @custom-start:featureName */
/* ... custom code ... */
/* @custom-end:featureName */
\`\`\`

**Tips:**
- Place custom blocks after identifiable "anchor" lines (like method signatures or imports)
- If a custom block cannot be automatically placed, it will appear at the end with a warning
- Names are optional but help with clarity when you have multiple custom blocks

## Generated File Management

- Generated files are tracked in \`postxl-lock.json\`
- When you manually modify a generated file, it becomes "ejected" - you are responsible for maintaining it
- Use \`pnpm run generate -i\` to ignore ejected files during generation
- Use \`pnpm run generate -f -p 'pattern'\` to forcefully regenerate specific files

## Schema-Driven Development

The project is defined in \`postxl-schema.json\` which specifies:
- **Models**: Data models with fields, relationships, and validation
- **Enums**: Enumerated types
- **Actions**: Standard and custom business logic actions
- **Repositories**: Data access configuration (Prisma/InMemory)
- **Authentication**: Auth and authorization rules
- **Faker rules**: Test data generation configuration

To modify the application:
1. Edit \`postxl-schema.json\` to add/modify models
2. Run \`pnpm run generate\` to regenerate code
3. Create new migration if needed: \`pnpm prisma migrate dev\`
4. Extend generated code using custom blocks if needed

## Environment Configuration

The project uses \`.env\` files for configuration:
- \`/.env\` - Root environment variables
- \`/backend/apps/api/.env\` - Backend-specific configuration

Copy \`.env.example\` files to \`.env\` if not done by setup:
\`\`\`bash
cp .env.example .env
cp backend/apps/api/.env.example backend/apps/api/.env
\`\`\`

## UI Components

${isWorkspaceProject
        ? `**IMPORTANT**: This project uses the shared \`@postxl/ui-components\` package.

When creating UI elements:
1. **Always** import components from \`@postxl/ui-components\`
2. **Never** create custom button, input, modal, card, or other generic UI components
3. Use Tailwind classes with \`className\` prop for custom styling
4. Use \`DataGrid\` for all interactive tables

\`\`\`tsx
// Correct - use ui-components package
import { Button, Input, Dialog, Card, DataGrid } from '@postxl/ui-components'

// Wrong - don't create generic UI primitives
function CustomButton({ children }) { ... }  // Never do this
\`\`\`

For component reference, see \`/packages/ui-components/CLAUDE.md\` in the PostXL monorepo.`
        : `The frontend uses Tailwind CSS for styling. Components are located in \`frontend/src/components/\`.`}

## Testing Strategy

- **Backend unit tests**: Jest (\`.spec.ts\` files in \`backend/\`)
- **Frontend unit tests**: Vitest (\`.test.ts\` files in \`frontend/\`)
- **E2E tests**: Playwright (in \`e2e/\` directory)
- **Visual testing**: Storybook for component development

Run tests:
\`\`\`bash
# Backend tests
cd backend && pnpm run test:jest

# Frontend tests
cd frontend && pnpm run test:storybook

# E2E tests
cd e2e && pnpm run e2e:stateless
\`\`\`

## Troubleshooting

### Prisma Errors
\`\`\`
The table 'X' does not exist in the current database.
\`\`\`
**Solution**: Run \`pnpm prisma migrate dev\` to apply migrations.

### Backend Fails to Start
\`\`\`
Zod validation error for missing config values
\`\`\`
**Solution**: Ensure \`.env\` file exists in \`backend/apps/api/\`. Copy from \`.env.example\`.

### Type Errors After Generation
**Solution**: Run \`pnpm run build\` from project root to rebuild dependencies.

### Generated File Conflicts
If you see merge conflict markers (\`<<<<<<<\`, \`=======\`, \`>>>>>>>\`) in generated files:
\`\`\`bash
pnpm run generate -f -p 'path/to/file.ts'
\`\`\`

### Docker Issues
Ensure Docker is running and ports are available:
\`\`\`bash
docker compose down
docker compose up -d db keycloak
\`\`\`

### Node Version Issues
This project requires pnpm 10.14+. pnpm automatically manages Node.js version via \`devEngines.runtime\` in package.json.

## Best Practices

1. **Never modify generated files directly** - Use custom blocks or eject the file
2. **Run type checks frequently**: \`pnpm run test:types\` in backend/frontend
3. **Use the generator**: Modify \`postxl-schema.json\` instead of hand-writing boilerplate
4. **Keep custom code minimal**: Let the generator handle standard patterns
5. **Use stateless mode for development**: Faster startup with \`pnpm run dev\`
6. **Test with E2E**: Validate full flows with Playwright tests
`;
}
//# sourceMappingURL=claudemd.generator.js.map