# Code Analysis Framework for Tools Documentation

**Last Updated:** 2026-01-05

## Overview

This framework provides a standardized approach to code analysis for comprehensive tool documentation. Use this checklist to extract all functions, formulas, constants, and code structure from each tool.

## Code Analysis Checklist Template

### File Structure Analysis

**PHP File:**

- [ ] Read complete PHP file
- [ ] Document file size (lines)
- [ ] Document includes/requires
- [ ] Document inline JavaScript (if any)
- [ ] Document inline CSS (if any)
- [ ] Document meta tags structure
- [ ] Document schema markup structure
- [ ] Document form structure
- [ ] Document result display structure

**JavaScript File(s):**

- [ ] Identify all JS files
- [ ] Read each JS file completely
- [ ] Document file size (lines)
- [ ] Document modular structure (if applicable)
- [ ] Document dependencies
- [ ] Document external libraries used
- [ ] Document API calls (if any)

**CSS File(s):**

- [ ] Identify CSS files used
- [ ] Document shared CSS files
- [ ] Document tool-specific CSS
- [ ] Document inline styles

### Function Extraction

**Alpine.js Component:**

- [ ] Identify main Alpine.js component function
- [ ] Document component name
- [ ] Extract all data properties
- [ ] Extract all computed properties
- [ ] Extract all methods
- [ ] Extract all watchers
- [ ] Extract all lifecycle hooks (init, etc.)

**Calculation Functions:**

- [ ] Identify all calculation functions
- [ ] Document function names
- [ ] Document function parameters
- [ ] Document function return values
- [ ] Document function logic
- [ ] Document function dependencies
- [ ] Document function side effects

**Helper Functions:**

- [ ] Identify all helper functions
- [ ] Document helper function purposes
- [ ] Document helper function parameters
- [ ] Document helper function return values

**Export Functions:**

- [ ] Identify Excel export functions
- [ ] Identify PDF export functions
- [ ] Identify CSV export functions
- [ ] Document export function parameters
- [ ] Document export data structure
- [ ] Document export formatting

**Utility Functions:**

- [ ] Identify formatting functions
- [ ] Identify validation functions
- [ ] Identify conversion functions
- [ ] Document utility function purposes

### Formula Extraction

**Primary Formulas:**

- [ ] Extract main calculation formulas
- [ ] Document formulas in mathematical notation
- [ ] Document formula variables
- [ ] Document formula constants
- [ ] Document formula steps

**Mode-Specific Formulas:**

- [ ] Extract formulas for each mode
- [ ] Document mode-specific variations
- [ ] Document mode-specific constants

**Derived Formulas:**

- [ ] Extract intermediate calculations
- [ ] Extract breakdown formulas
- [ ] Extract percentage calculations

### Constants Extraction

**Calculation Constants:**

- [ ] Extract all numeric constants
- [ ] Extract all rate constants
- [ ] Extract all threshold constants
- [ ] Extract all limit constants
- [ ] Document constant values
- [ ] Document constant sources
- [ ] Document constant year (2025/2026)

**Configuration Constants:**

- [ ] Extract default values
- [ ] Extract configuration options
- [ ] Extract validation rules

### State Management Analysis

**Alpine.js State:**

- [ ] Document all state variables
- [ ] Document state initialization
- [ ] Document state updates
- [ ] Document state dependencies

**localStorage:**

- [ ] Identify localStorage usage
- [ ] Document stored keys
- [ ] Document stored data structure
- [ ] Document storage triggers

**URL Parameters:**

- [ ] Identify URL parameter usage
- [ ] Document parameter names
- [ ] Document parameter parsing
- [ ] Document parameter restoration

### Event Handler Analysis

**Form Events:**

- [ ] Document input change handlers
- [ ] Document form submit handlers
- [ ] Document button click handlers
- [ ] Document select change handlers
- [ ] Document toggle handlers

**Calculation Triggers:**

- [ ] Document auto-calculation triggers
- [ ] Document manual calculation triggers
- [ ] Document debouncing/throttling

**Export Triggers:**

- [ ] Document export button handlers
- [ ] Document export flow
- [ ] Document email gating triggers

### API Integration Analysis

**External APIs:**

- [ ] Identify external API calls
- [ ] Document API endpoints
- [ ] Document API request format
- [ ] Document API response format
- [ ] Document API error handling

**Internal APIs:**

- [ ] Identify internal API calls
- [ ] Document API endpoints
- [ ] Document API usage

### Code Organization Analysis

**Modular Structure:**

- [ ] Document module organization
- [ ] Document module dependencies
- [ ] Document module exports
- [ ] Document module imports

**Code Patterns:**

- [ ] Document common patterns used
- [ ] Document design patterns
- [ ] Document code conventions

**Code Quality:**

- [ ] Document code comments
- [ ] Document code documentation
- [ ] Document code organization
- [ ] Document code maintainability

## Function Documentation Template

For each function, document:

````markdown
### Function Name

**Location:** `file.js:line-range`

**Purpose:** [What the function does]

**Parameters:**

- `param1` (type): Description
- `param2` (type): Description

**Returns:** (type) Description

**Dependencies:**

- Function/constant dependencies

**Side Effects:**

- State changes
- DOM changes
- API calls

**Example:**

```javascript
// Example usage
```
````

**Notes:**

- Additional notes

````

## Formula Documentation Template

For each formula, document:

```markdown
### Formula Name

**Location:** `file.js:line-range`

**Mathematical Notation:**
````

Formula = expression

```

**Variables:**
- `var1`: Description
- `var2`: Description

**Constants:**
- `const1`: Value (source)

**Step-by-Step:**
1. Step 1
2. Step 2
3. Step 3

**Legal Basis:**
- Law/regulation reference

**Example Calculation:**
- Input: values
- Calculation: steps
- Output: result

**Edge Cases:**
- Edge case 1: How handled
- Edge case 2: How handled
```

## Code Flow Documentation

**Calculation Flow:**

- Document input → processing → output flow
- Document mode-specific flows
- Document error handling flow

**State Flow:**

- Document state initialization
- Document state updates
- Document state dependencies

**Event Flow:**

- Document event triggers
- Document event handlers
- Document event propagation

## Code Analysis Output Format

For each tool, document:

1. **File Structure**

   - PHP file structure
   - JavaScript file structure
   - CSS file structure
   - Dependencies

2. **Functions Inventory**

   - All functions listed
   - Function purposes
   - Function locations

3. **Formulas Inventory**

   - All formulas listed
   - Formula locations
   - Formula purposes

4. **Constants Inventory**

   - All constants listed
   - Constant values
   - Constant sources

5. **State Management**

   - State variables
   - State initialization
   - State updates

6. **Event Handlers**

   - All event handlers
   - Event triggers
   - Event flows

7. **Code Organization**
   - Code structure
   - Code patterns
   - Code quality

## Analysis Workflow

1. **File Reading**

   - Read all files completely
   - Don't skip sections
   - Take notes as you read

2. **Function Extraction**

   - Identify all functions
   - Document each function
   - Don't miss helper functions

3. **Formula Extraction**

   - Identify all calculations
   - Extract formulas
   - Document formula logic

4. **Constant Extraction**

   - Identify all constants
   - Document values
   - Document sources

5. **Flow Analysis**

   - Trace calculation flow
   - Trace state flow
   - Trace event flow

6. **Documentation**
   - Document all findings
   - Organize by category
   - Be thorough

## Notes

- Read code completely, don't skim
- Extract everything, don't assume
- Document locations (file:line)
- Be systematic and thorough
- Don't skip helper functions
- Don't skip utility functions
