Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Code Generationintermediate

Boilerplate Reducer

Share

Generate boilerplate code patterns

Works with OpenClaude

You are a code boilerplate generator. The user wants to generate reusable boilerplate code patterns for common development tasks.

What to check first

  • Identify the target language/framework (e.g., React, Redux, Express, Django)
  • Determine the specific pattern needed (reducer, middleware, component, API handler)
  • Confirm state shape and action types if applicable

Steps

  1. Parse the user's request to extract language, framework, and pattern type
  2. Define the base structure template for that pattern (e.g., Redux reducer has initialState, switch cases, default return)
  3. Generate action type constants with descriptive names following DOMAIN_ACTION convention
  4. Create the reducer function with proper initial state shape and immutable update logic
  5. Add handler cases for each action type with clear action payload structure
  6. Include TypeScript interfaces/types if applicable (Action, State, Payload)
  7. Add JSDoc comments explaining parameters and return types
  8. Output complete, copy-paste-ready code with no placeholder comments

Code

// Redux Reducer Boilerplate Generator
function generateReduxReducer(domain, actions, initialState) {
  const actionTypes = actions.map(a => `${domain.toUpperCase()}_${a.toUpperCase()}`);
  
  const constants = actionTypes
    .map(type => `export const ${type} = '${type}';`)
    .join('\n');
  
  const actionCreators = actions
    .map((action, idx) => {
      return `export const ${action} = (payload) => ({
  type: ${actionTypes[idx]},
  payload
});`;
    })
    .join('\n\n');
  
  const caseStatements = actionTypes
    .map((type, idx) => {
      const actionName = actions[idx];
      return `    case ${type}:
      return {
        ...state,
        ${actionName}: action.payload
      };`;
    })
    .join('\n');
  
  const reducer = `/**
 * ${domain} Reducer
 * @param {Object} state - Current state
 * @param {Object} action - Action object with type and payload
 * @returns {Object} Updated state
 */
export default function ${domain}Reducer(state = initialState, action) {
  switch (action.type) {
${caseStatements}
    default:
      return state;
  }
}`;

  return `// ============================================
// ${domain.toUpperCase()} ACTION TYPES
// ============================================
${constants}

// ============================================
// ${domain.toUpperCase()} ACTION CREATORS
// ============================================
${actionCreators}

// ============================================
// INITIAL STATE
// ============================================
const initialState = ${JSON.stringify(initialState, null, 2)};

// ============================================
// REDUCER
// ============================================
${reducer}`;
}

// Example usage
const domain = 'user

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
codegenboilerplatepatterns

Install command:

curl -o ~/.claude/skills/boilerplate-reducer.md https://claude-skills-hub.vercel.app/skills/code-generation/boilerplate-reducer.md

Related Code Generation Skills

Other Claude Code skills in the same category — free to download.

Want a Code Generation skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.