Guide

Why Does Your Node.js AI Agent Keep Making the Same Architecture Mistakes?

AI

AI Skills Team

7/7/2026 8 min

The Problem: Your AI Agent's Node.js Code Looks Like It's From 2020

You've built an AI agent that writes code. It can generate entire Express.js applications, set up middleware, and even write database queries. But when you look at the output, something feels off. The agent consistently picks Express for new serverless projects, uses require statements in a TypeScript codebase, and structures business logic directly inside route handlers. It's not that the code is broken—it's that it's making the same outdated decisions every single time, regardless of the project's actual needs.

This is a common frustration for developers using AI coding agents. The models are trained on vast amounts of existing code, much of which follows patterns that were standard years ago but are no longer optimal. The agent doesn't understand the why behind architectural choices. It doesn't ask: "Is this going to be deployed on the edge?" or "Does the team have experience with Fastify?" Instead, it defaults to the most frequently seen pattern in its training data, which is often Express.js with CommonJS modules and a monolithic structure.

The result is code that works but isn't well-suited for modern deployment targets, is harder to maintain, and may have security or performance anti-patterns baked in. You end up spending time refactoring the agent's output instead of building features. The core issue isn't the agent's ability to write syntax; it's its lack of contextual decision-making principles for the Node.js ecosystem in 2025.

What a Good Solution Should Change

A useful tool or skill for this problem shouldn't just provide code snippets to copy. Copying a Fastify boilerplate doesn't teach the agent when to use Fastify. Instead, a good solution should:

  1. Inject decision-making frameworks into the agent's workflow, so it asks the right questions before generating code.
  2. Provide clear, context-aware selection criteria for tools like frameworks, runtimes, and libraries.
  3. Establish modern architectural principles (like layered architecture, proper error handling, and validation boundaries) as a baseline.
  4. Help the agent recognize and avoid common anti-patterns that are prevalent in legacy codebases.

The goal is to shift the agent from being a pattern-mimicker to a context-aware problem-solver. It should be able to justify its choices based on the project's requirements, not just its training data frequency.

Introducing the nodejs-best-practices Skill

One potential resource to address this is the nodejs-best-practices skill from the antigravity-awesome-skills repository. This isn't a library or a framework. It's a curated set of principles and decision trees designed to be consumed by an AI agent to guide its Node.js development choices.

The skill's core philosophy is stated clearly: "Teaches thinking, not copying." It's structured as a knowledge base that an agent can reference to make informed decisions. For example, instead of just providing a code sample for a REST API, it presents a decision tree for framework selection based on deployment target, performance needs, and team familiarity.

How It Works in Practice

When integrated into an agent's workflow, this skill acts as a set of guidelines. The agent would consult it when faced with a decision. Let's say the user prompt is: "Build a high-performance API for a real-time dashboard."

A naive agent might immediately start generating Express code. An agent equipped with this skill would instead follow the decision tree:

  1. What are you building? → High Performance API.
  2. Consult the skill: The skill's framework selection section suggests Fastify for high-performance APIs, noting it's "2-3x faster than Express."
  3. Consider context: The skill also prompts the agent to ask: "Is cold start time critical?" If the answer is yes (e.g., for a serverless function), it might steer towards Hono.
  4. Make a justified choice: The agent can now generate Fastify code and explain why it chose it over Express, based on the performance requirement.

This process moves the agent from a default behavior to a reasoned one. The skill provides the "why" that was missing.

Evaluating Whether This Skill Fits Your Workflow

Before considering this skill, it's important to understand what it is and what it isn't. It's a community-sourced knowledge base, not a magic bullet. Here’s how to evaluate it.

What It Provides

  • Decision Frameworks: Clear trees and comparison tables for choosing between frameworks (Hono, Fastify, NestJS, Express), runtimes (Node.js, Bun, Deno), and module systems (ESM vs. CommonJS).
  • Architectural Principles: Guidance on structuring applications with layers (Controller, Service, Repository) for better testability and separation of concerns.
  • Modern Patterns: Principles for async/await usage, error handling, input validation, and security checklists.
  • Anti-Pattern Awareness: Explicit lists of what not to do (e.g., "Don't use Express for new edge projects").

Capability Boundaries and Best Use Cases

This skill is most effective for:

  • Greenfield Projects: When starting a new Node.js project and making foundational technology choices.
  • Architecture Reviews: When an agent is asked to review or refactor existing code, it can use these principles to identify improvements.
  • Educational Contexts: When the goal is to have the agent explain why it made certain choices, not just produce code.

It is less useful for:

  • Deep, Framework-Specific Debugging: It won't help solve a complex NestJS dependency injection issue or a Fastify plugin conflict.
  • Performance Profiling: It provides principles ("offload CPU work") but not tools to measure or fix specific bottlenecks.
  • Providing Copy-Paste Code: Its value is in the thinking process, not in providing ready-made, production-hardened code snippets.

What to Inspect Before Using It

If you're considering integrating this skill into your agent's toolkit, here are practical steps:

  1. Review the Source Repository: The skill is hosted in the antigravity-awesome-skills repository. Examine the SKILL.md file directly. Is the advice current? Does it align with your team's standards? The repository has significant community traction (42k+ stars), which suggests broad validation, but always verify against your own context.
  2. Check the "Risk" and "Source" Fields: The skill metadata lists risk: unknown and source: community. This is a signal to treat it as a starting point for your agent's knowledge, not as an infallible authority. You may need to supplement or override its advice with your organization's specific guidelines.
  3. Test with a Sample Prompt: Before full integration, give your agent a complex prompt (e.g., "Design a secure, scalable API for a fintech app") with and without the skill active. Compare the output. Does the skilled agent ask clarifying questions? Does it choose a more appropriate framework? Does its architecture include proper validation and error handling layers?
  4. Understand the Integration Model: This skill is designed for AI agent workflows, particularly those using tools like Cursor, Claude Code, or Gemini CLI. It's not a traditional npm package. You need to understand how your specific agent platform ingests and uses such skill files.

Practical Implementation: A Decision-Making Example

Let's walk through a concrete scenario. Your agent receives this prompt:

"Create a Node.js service that processes uploaded CSV files, validates the data, and stores it in a PostgreSQL database. It needs to handle large files efficiently."

Without the skill, the agent might generate a single Express.js file that uses multer for uploads, reads the entire file into memory with fs.readFileSync, processes it synchronously, and uses raw SQL strings for database insertion. This code would work for small files but would crash on large ones, block the event loop, and have SQL injection vulnerabilities.

With the nodejs-best-practices skill, the agent's thought process changes:

  1. Framework Choice: The skill's decision tree asks about the deployment target. For a standard server-based service, Express or Fastify are options. Given the need for performance with large files, the agent might lean towards Fastify, citing its performance characteristics from the skill's comparison table.
  2. Async Patterns: The skill's section on async patterns highlights that file I/O is I/O-bound and should use async methods. It also warns against blocking the event loop. The agent would choose fs.createReadStream and a streaming CSV parser instead of readFileSync.
  3. Architecture: The skill advocates for layered architecture. The agent would separate concerns: a controller layer to handle the HTTP upload, a service layer for the business logic (parsing, validation), and a repository layer for database operations.
  4. Validation & Security: The skill's validation principles say to "validate at boundaries." The agent would add validation for the CSV structure and data types before processing. The security checklist would prompt it to use parameterized queries (via an ORM like Prisma or Knex) to prevent SQL injection.
  5. Error Handling: The skill's error handling principles would guide the agent to create custom error classes (e.g., InvalidCsvError) and implement centralized error handling middleware to return consistent, safe error responses.

The resulting code would be more robust, scalable, and secure—not because the agent copied a better template, but because it applied better decision-making principles.

Final Considerations

The nodejs-best-practices skill is a valuable resource for steering AI agents towards more thoughtful Node.js development. Its strength lies in promoting a decision-first mindset over pattern copying. However, it is a community guide, not a certified standard. Use it as a foundation to build upon, and always validate its recommendations against your project's specific requirements and your team's expertise. The goal is to make your agent a better collaborator, not just a faster typist.

延伸閱讀