# Onboarding Folder Management Feature

## Overview

The Developer Onboarding MCP automatically manages onboarding-related files in user-specific folders. All onboarding documentation is saved to a dedicated folder that is automatically excluded from git.

## How It Works

### Folder Creation

1. **With User Name**: When a user provides their name during role selection, a folder named after the user is created (sanitized for filesystem compatibility)
   - Example: User "John Doe" → Folder: `john-doe/`

2. **Without User Name**: If no user name is provided, files are saved to the default `onboarding/` folder

### Automatic .gitignore Management

- The onboarding folder is automatically added to `.gitignore`
- User-specific folders are added dynamically when created
- The default `onboarding/` folder is pre-configured in `.gitignore`

## Usage Examples

### Example 1: User Provides Name

```javascript
// Step 1: User selects role with name
identify-user-role({
  action: 'select_role',
  userName: 'Sarah Johnson',
  role: 'frontend',
  projectPath: './my-project'
})

// Result:
// - Folder created: ./my-project/sarah-johnson/
// - Folder added to .gitignore: /sarah-johnson/
// - Response includes folder information
```

### Example 2: Generate Documentation

```javascript
// Step 2: Generate documentation (automatically saves to user folder)
generate-documentation({
  projectPath: './my-project',
  role: 'frontend',
  documentType: 'overview',
  userName: 'Sarah Johnson'  // Optional - can also use userId
})

// Result:
// - File saved: ./my-project/sarah-johnson/frontend-overview.md
// - Returns file path and folder information
```

### Example 3: No User Name Provided

```javascript
// Generate documentation without user name
generate-documentation({
  projectPath: './my-project',
  role: 'frontend',
  documentType: 'overview'
  // No userName provided
})

// Result:
// - Folder created: ./my-project/onboarding/
// - File saved: ./my-project/onboarding/frontend-overview.md
// - Folder already in .gitignore (default)
```

## Folder Structure

```
my-project/
├── .gitignore          (includes /onboarding/ and user folders)
├── src/
├── package.json
└── onboarding/          (default folder if no user name)
    ├── frontend-overview.md
    ├── frontend-setup-guide.md
    └── ...
    
# OR with user name:

my-project/
├── .gitignore          (includes /sarah-johnson/)
├── src/
├── package.json
└── sarah-johnson/      (user-specific folder)
    ├── frontend-overview.md
    ├── frontend-setup-guide.md
    └── ...
```

## File Naming Convention

Generated files follow this naming pattern:
- `{role}-{documentType}.md`
- Examples:
  - `frontend-overview.md`
  - `backend-setup-guide.md`
  - `testing-learning-path.md`
  - `devops-reference.md`

## API Reference

### OnboardingFileManager Utility

The `OnboardingFileManager` utility class provides the following methods:

#### `getOrCreateOnboardingFolder(projectPath, userName?)`
Creates or retrieves the onboarding folder configuration.

**Parameters:**
- `projectPath` (string): Path to the project root
- `userName` (string, optional): User name for folder creation

**Returns:**
```typescript
{
  folderName: string;
  projectPath: string;
  fullPath: string;
}
```

#### `saveOnboardingFile(config, fileName, content, extension?)`
Saves an onboarding file to the user's folder.

**Parameters:**
- `config`: Folder configuration from `getOrCreateOnboardingFolder`
- `fileName`: Name of the file (without extension)
- `content`: File content
- `extension`: File extension (default: `.md`)

**Returns:** Full path to the saved file

## Integration Points

### Tools That Use This Feature

1. **identify-user-role** (select_role action)
   - Creates folder when user selects role
   - Returns folder information in response

2. **generate-documentation**
   - Saves all generated documentation to user folder
   - Accepts `userName` or `userId` parameter
   - Returns file path and folder information

### Future Integration

Other tools that generate onboarding files can use `OnboardingFileManager`:
- Learning modules output
- Progress reports
- Custom onboarding guides

## Security & Privacy

- **Local Storage**: All files are stored locally in the project directory
- **Git Exclusion**: Folders are automatically excluded from version control
- **User Privacy**: Each user gets their own folder, keeping onboarding data separate

## Folder Name Sanitization

User names are sanitized to ensure filesystem compatibility:
- Converted to lowercase
- Special characters replaced with hyphens
- Multiple hyphens collapsed
- Leading/trailing hyphens removed

**Examples:**
- "John Doe" → `john-doe`
- "Sarah O'Brien" → `sarah-o-brien`
- "User@123" → `user-123`

## Error Handling

The system gracefully handles errors:
- If folder creation fails, the operation continues (logs warning)
- If .gitignore update fails, the operation continues (logs warning)
- File save errors are returned to the caller

## Best Practices

1. **Always provide userName**: Use the user's name when available for better organization
2. **Check folder info**: The response includes folder information - use it to inform users
3. **Respect privacy**: Onboarding folders contain personal progress data - keep them private
4. **Regular cleanup**: Consider cleaning up old onboarding folders periodically

## Troubleshooting

### Folder Not Created
- Check file permissions on project directory
- Verify project path is correct
- Check logs for error messages

### Files Not Saved
- Verify `saveToFile` parameter is `true` (default)
- Check folder exists and is writable
- Review error messages in response

### .gitignore Not Updated
- Check write permissions on `.gitignore` file
- Verify folder name is valid
- Check logs for warnings

## Example Workflow

```javascript
// Complete workflow example

// 1. User selects role
const roleResult = await identifyUserRole({
  action: 'select_role',
  userName: 'Alice Smith',
  role: 'backend',
  projectPath: './my-api-project'
});

// Response includes:
// {
//   onboardingFolder: {
//     folderName: 'alice-smith',
//     folderPath: './my-api-project/alice-smith',
//     message: 'Your onboarding files will be saved here...'
//   }
// }

// 2. Generate documentation
const docResult = await generateDocumentation({
  projectPath: './my-api-project',
  role: 'backend',
  documentType: 'overview',
  userName: 'Alice Smith'  // Uses existing folder
});

// Response includes:
// {
//   filePath: './my-api-project/alice-smith/backend-overview.md',
//   folderPath: './my-api-project/alice-smith',
//   folderName: 'alice-smith'
// }

// 3. Files are automatically excluded from git
// .gitignore now contains: /alice-smith/
```

---

*Last Updated: Version 1.0.3*

