# Business Analysis - Shared Functions (v2 - Progressive Loading)

> **Ref:** This file contains common functions for all BA phases.
> **Version:** 2.0 - Optimized for progressive loading

---

## Architecture Progressive

Le skill BusinessAnalyse utilise le **chargement progressif** pour minimiser le contexte:

```
SKILL.md (entry point)
    ↓
steps/step-00-init.md (parse flags, create state)
    ↓
steps/step-01-discover.md (charge questionnaire/XX.md on-demand)
    ↓
steps/step-02-analyse.md (charge templates/frd-brd.md)
    ↓
steps/step-03-specify.md (charge templates/frd-spec.md)
    ↓
steps/step-04-validate.md (validation gate)
    ↓
steps/step-05-handoff.md (charge templates/frd-handoff.md)
    ↓
steps/step-06-doc-html.md (charge react/*.md on-demand)
```

**Benefit:** ~70% context reduction per phase

---

## Business Context Validation

```
validate_business_context(context):
  IF context IN ['platform', 'personal', 'system'] THEN
    ERROR "BA restricted to 'business' context. Contact: support@atlshub.ch"
    RETURN false
  END IF
  RETURN true
```

**CRITICAL:** BusinessAnalyze works ONLY for the `business` context.

---

## Feature Directory Structure

```
.business-analyse/
├── config.json                    # Global config
└── business/
    └── {application}/
        └── modules/
            └── {module}/
                └── features/
                    └── {FEAT-NNN}/
                        ├── 00-context.md      # State persistence
                        ├── 1-discovery.md
                        ├── 2-business-requirements.md
                        ├── 3-functional-specification.md
                        ├── validation.json
                        ├── 4-development-handoff.md
                        └── tracking/
                            ├── changes/
                            ├── bugs/
                            └── hotfixes/
```

---

## Feature ID Generation

```
generate_feature_id():
  last_id = read_config(".business-analyse/config.json", "lastFeatureId") OR 0
  new_id = last_id + 1
  update_config(".business-analyse/config.json", "lastFeatureId", new_id)
  RETURN format("FEAT-%03d", new_id)
```

---

## Models by Phase (Step)

| Step | Model | Reason |
|------|-------|--------|
| 00-init | Haiku | Quick structure setup |
| 01-discover | **Opus** | ULTRATHINK elicitation |
| 02-analyse | Sonnet | BRD modeling |
| 03-specify | Sonnet | FRD + Use Cases |
| 04-validate | Haiku | Binary gate |
| 05-handoff | **Opus** | Zero-ambiguity prompt |
| 06-doc-html | Sonnet | React + Context7 |

---

## ULTRATHINK

Behavioral mode for critical phases (01, 02, 03, 05):

```
ULTRATHINK MODE:
- Consider ALL edge cases
- Challenge EVERY assumption
- Anticipate UNEXPRESSED needs
- Validate completeness before output

DO NOT:
- Accept vague answers
- Skip question categories
- Assume stakeholder thought of everything
```

**DO NOT invoke** as a skill/tool - it is a thinking mode.

---

## Context7 (Step 06)

```
Prompt pattern:
"use context7 with /facebook/react and /i18next/react-i18next
 to generate {component} following SmartStack patterns"
```

Libraries:
- `/facebook/react` - React 19 patterns
- `/i18next/react-i18next` - Internationalization
- `/remix-run/react-router` - React Router v7
- `/lucide-icons/lucide-react` - Icons

---

## Permission Path Format

**Format:** `business.{application}.{module}.{action}`

| Action | Permission | Usage |
|--------|------------|-------|
| Read | `.read` | GET endpoints |
| Create | `.create` | POST endpoints |
| Update | `.update` | PUT endpoints |
| Delete | `.delete` | DELETE endpoints |
| Export | `.export` | Export data |
| Import | `.import` | Import data |
| Admin | `.admin` | Administrative |

---

## i18n (4 required languages)

| Language | File | Code |
|----------|------|------|
| French | `fr/docs-{app}-{module}.json` | fr |
| English | `en/docs-{app}-{module}.json` | en |
| Italian | `it/docs-{app}-{module}.json` | it |
| German | `de/docs-{app}-{module}.json` | de |

---

## Output Paths

| Type | Path |
|------|------|
| Documentation | `web/smartstack-web/src/pages/docs/business/{app}/{module}/` |
| i18n | `web/smartstack-web/src/i18n/locales/{lang}/` |
| Route | `/docs/business/{app}/{module}` |

---

## State Persistence

The `00-context.md` file persists state between steps:

```markdown
# Business Analysis: {{feature_id}}

## Progress
| Step | Status | Started | Completed |
|------|--------|---------|-----------|
| 00-init | Complete | ... | ... |
| 01-discover | In Progress | ... | - |
...

## State Variables
| Variable | Value |
|----------|-------|
| feature_id | FEAT-001 |
| application_name | Sales |
...
```

**Read:** Each step starts by reading 00-context.md
**Write:** Each step updates 00-context.md at the end

---

## Resume Workflow

```
resume_workflow(task_id):
  1. Search .business-analyse/ for matching feature
  2. Read 00-context.md
  3. Find last "Complete" step in Progress table
  4. Return next step to load

Example:
  /business-analyse -r FEAT-001
  → Reads .business-analyse/.../FEAT-001/00-context.md
  → Finds "01-discover: Complete, 02-analyse: Pending"
  → Loads step-02-analyse.md
```

---

## Standard Summary (End of Step)

```
{STEP_NAME} - {feature_id}
├── Status: {Complete/In Progress}
├── Key metric: {value}
├── Output: {file created}
└── Next: {next step name}
```

---

## Config Template

```json
{
  "project": "{Name}",
  "lastFeatureId": 0,
  "context": "business",
  "standards": ["BABOK-v3", "IEEE-830"],
  "contact": "support@atlshub.ch"
}
```

---

## Progressive Loading Benefits

| Aspect | Before | After | Gain |
|--------|--------|-------|------|
| Questionnaire | 283 L (all) | 40-60 L (per category) | ~75% |
| FRD Templates | 477 L (all) | 80-150 L (per type) | ~70% |
| React Templates | 580 L (all) | 250-350 L (per need) | ~45% |
| **Total/step** | ~1,340 L | ~300-400 L | **~70%** |

---

## Support

Contact: **support@atlshub.ch**
