# Naming Conventions - SmartStack

> **Loaded by:** business-analyse steps when generating codes and routes
> **Purpose:** Define transformation rules between code identifiers (PascalCase) and URL routes (kebab-case)

---

## Module & Application Codes

### In JSON files

- `modules[].code` = **PascalCase** (e.g., `"HumanResources"`, `"TimeManagement"`)
- `metadata.application` = **PascalCase** (e.g., `"HumanResources"`)
- Used for: C# namespaces, file paths, class names, folder structure

### In Directory Names (BA docs structure)

- **Project directories**: kebab-case slug chosen by user (e.g., `projet-rh`, `commande-repas`)
- **Application directories**: kebab-case derived from PascalCase code (e.g., `HumanResources` → `human-resources`)
- **Module directories**: kebab-case derived from PascalCase code (e.g., `Employees` → `employees`, `TimeManagement` → `time-management`)
- **"My*" modules**: treated as normal modules (e.g., `MyFollowUp` → `my-follow-up`)
- Path pattern: `docs/{project-slug}/v{X.Y}/{app-kebab}/{module-kebab}/`

### In URL Routes

- **kebab-case lowercase** (e.g., `"/human-resources/employees"`)
- Transform: `PascalCase` → `kebab-case` via helper function
- Used for: Web URLs, navigation routes, API paths

---

## Transformation Rules

| Source | Format | Example | Usage |
|--------|--------|---------|-------|
| Module code | `PascalCase` | `HumanResources` | C# files, classes, namespaces |
| Application code | `PascalCase` | `HumanResources` | Namespaces, folders |
| Route path | `kebab-case` | `/human-resources` | Web URLs, navigation |
| Section code | `kebab-case` | `time-tracking`, `approve` | URLs, API paths, sections |
| Resource code | `kebab-case` | `repair-grid`, `employee-form` | Component IDs, resources |

---

## Why These Conventions?

### PascalCase for Code
- **C# Standard**: Namespaces, classes, properties follow PascalCase
- **File Structure**: Matches .NET project conventions
- **Compile-time**: Enforced by compiler and naming analyzers

### kebab-case for URLs
- **Web Standard**: Readable, SEO-friendly, case-insensitive
- **REST API Convention**: Lowercase routes with hyphens
- **Frontend Compatibility**: React Router, Vue Router expect lowercase
- **Database Storage**: Navigation routes stored lowercase prevent case mismatch errors

### Separation of Concerns
- **Code Identity** ≠ **URL Identity**
- Backend uses PascalCase internally
- URLs transform to kebab-case at persistence layer (seed data)
- Frontend consumes kebab-case routes from database

---

## Helper Functions

### C# (Backend Seed Data)

**Location:** `NavigationSeedData.cs` templates in core-seed-data.md

**Usage:**
```csharp
Route = ToKebabCase($"/{appCode}/{moduleCode}")
```

**Transformation Examples:**
- `HumanResources` → `human-resources`
- `TimeManagement` → `time-management`
- `Projects` → `projects` (single word, no change)
- `AI` → `ai` (acronym lowercase)

**Implementation:** See `templates/skills/business-analyse-develop/references/core-seed-data.md` line 162

### JavaScript (BA Handoff Generation)

**Location:** Used in /business-analyse-html when building seedDataCore

**Usage:**
```javascript
const route = `/${toKebabCase(appCode)}/${toKebabCase(moduleCode)}`;
```

**Implementation:**
```javascript
function toKebabCase(code) {
  return code
    .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
    .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
    .toLowerCase();
}
```

### TypeScript (Frontend MCP)

**Location:** Used in scaffold_routes and validate_frontend_routes

**Usage:**
```typescript
const webPath = `/${navRoute.split('.').map(toKebabCase).join('/')}`;
```

**Implementation:**
```typescript
function toKebabCase(str: string): string {
  return str
    .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
    .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
    .toLowerCase();
}
```

---

## Validation

### During Generation (business-analyse-develop)

POST-CHECK after NavigationSeedData generation:

```bash
# Detect routes with uppercase
grep -E 'Route = "?/[^"]*[A-Z]' Infrastructure/Persistence/Seeding/Data/*/NavigationSeedData.cs
```

If match found → ERROR, routes not transformed to kebab-case.

### Via MCP

```bash
validate_frontend_routes
```

**Detects:**
- Routes with uppercase in URLs
- Seed data routes not matching frontend expectations
- PascalCase URLs without kebab-case conversion

**Output Example:**
```
❌ Case mismatch detected (1 routes with uppercase):
   Route "humanresources" uses PascalCase in URL.
   Found: HumanResources → Expected: human-resources
   Fix: Use ToKebabCase() in NavigationSeedData route generation
```

---

## Common Pitfalls

### ❌ Generating Routes Without Transformation

**Wrong (causes 404 on menu click):**
```csharp
Route = $"/{appCode}/{moduleCode}"
// Result: /HumanResources/Projects
```

**Correct:**
```csharp
Route = ToKebabCase($"/{appCode}/{moduleCode}")
// Result: /human-resources/projects
```

### ❌ Hardcoding Routes in lowercase

**Wrong (loses traceability to code):**
```csharp
Route = "/humanresources"  // Flattens multi-word into single word
```

**Correct:**
```csharp
Route = ToKebabCase($"/{appCode}")
// If appCode = "HumanResources" → /human-resources
```

### ❌ Inconsistent Section/Resource Codes

**Wrong (mixing conventions):**
```json
{
  "code": "TimeTracking",  // PascalCase
  "route": "/time-tracking"  // kebab-case route doesn't match
}
```

**Correct:**
```json
{
  "code": "time-tracking",  // kebab-case from start
  "route": "/human-resources/time-tracking"
}
```

Sections and resources ALWAYS use kebab-case (no transformation needed).

---

## Examples

### Full Hierarchy Example

**BA Input (index.json):**
```json
{
  "metadata": {
    "application": "HumanResources"
  },
  "modules": [
    { "code": "TimeManagement" },
    { "code": "Projects" }
  ]
}
```

**Generated Routes (seed data):**
```
Application: /human-resources
Module 1:    /human-resources/time-management
Module 2:    /human-resources/projects
```

**C# Code Structure:**
```
src/Domain/Entities/HumanResources/TimeManagement/TimeEntry.cs
src/Application/Services/HumanResources/TimeManagement/TimeEntryService.cs
src/API/Controllers/HumanResources/TimeManagementController.cs
```

**Frontend Routes (React Router):**
```tsx
<Route path="/human-resources/time-management" element={<TimeManagementPage />} />
<Route path="/human-resources/projects" element={<ProjectsPage />} />
```

---

## References

- **Template:** `templates/skills/business-analyse-develop/references/core-seed-data.md`
- **Validation:** `src/mcp/tools/validate-frontend-routes.ts`
- **POST-CHECK:** `templates/skills/business-analyse-develop/steps/step-02-execute.md` (section 5)
- **Handoff:** `/business-analyse-handoff` skill (handoff section)
