Close Menu
    Trending
    • How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1
    • From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025
    • Using Graph Databases to Model Patient Journeys and Clinical Relationships
    • Cuba’s Energy Crisis: A Systemic Breakdown
    • AI Startup TML From Ex-OpenAI Exec Mira Murati Pays $500,000
    • STOP Building Useless ML Projects – What Actually Works
    • Credit Risk Scoring for BNPL Customers at Bati Bank | by Sumeya sirmula | Jul, 2025
    • The New Career Crisis: AI Is Breaking the Entry-Level Path for Gen Z
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Artificial Intelligence»How to Use an LLM-Powered Boilerplate for Building Your Own Node.js API
    Artificial Intelligence

    How to Use an LLM-Powered Boilerplate for Building Your Own Node.js API

    Team_AIBS NewsBy Team_AIBS NewsFebruary 21, 2025No Comments7 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email

    For a very long time, one of many widespread methods to begin new Node.js tasks was utilizing boilerplate templates. These templates assist builders reuse acquainted code constructions and implement customary options, akin to entry to cloud file storage. With the most recent developments in LLM, venture boilerplates seem like extra helpful than ever.

    Constructing on this progress, I’ve prolonged my present Node.js API boilerplate with a brand new device LLM Codegen. This standalone function permits the boilerplate to robotically generate module code for any objective primarily based on textual content descriptions. The generated module comes full with E2E checks, database migrations, seed information, and essential enterprise logic.

    Historical past

    I initially created a GitHub repository for a Node.js API boilerplate to consolidate the very best practices I’ve developed over time. A lot of the implementation is predicated on code from an actual Node.js API operating in manufacturing on AWS.

    I’m keen about vertical slicing structure and Clear Code rules to maintain the codebase maintainable and clear. With latest developments in LLM, notably its help for big contexts and its means to generate high-quality code, I made a decision to experiment with producing clear TypeScript code primarily based on my boilerplate. This boilerplate follows particular constructions and patterns that I imagine are of top quality. The important thing query was whether or not the generated code would comply with the identical patterns and construction. Based mostly on my findings, it does.

    To recap, right here’s a fast spotlight of the Node.js API boilerplate’s key options:

    • Vertical slicing structure primarily based on DDD & MVC rules
    • Companies enter validation utilizing ZOD
    • Decoupling software parts with dependency injection (InversifyJS)
    • Integration and E2E testing with Supertest
    • Multi-service setup utilizing Dockercompose

    Over the previous month, I’ve spent my weekends formalizing the answer and implementing the required code-generation logic. Beneath, I’ll share the small print.

    Implementation Overview

    Let’s discover the specifics of the implementation. All Code Generation logic is organized on the venture root degree, contained in the llm-codegen folder, guaranteeing straightforward navigation. The Node.js boilerplate code has no dependency on llm-codegen, so it may be used as an everyday template with out modification.

    It covers the next use instances:

    • Producing clear, well-structured code for brand spanking new module primarily based on enter description. The generated module turns into a part of the Node.js REST API software.
    • Creating database migrations and lengthening seed scripts with primary information for the brand new module.
    • Producing and fixing E2E checks for the brand new code and guaranteeing all checks move.

    The generated code after the primary stage is clear and adheres to vertical slicing structure rules. It contains solely the required enterprise logic for CRUD operations. In comparison with different code technology approaches, it produces clear, maintainable, and compilable code with legitimate E2E checks.

    The second use case entails producing DB migration with the suitable schema and updating the seed script with the required information. This job is especially well-suited for LLM, which handles it exceptionally properly.

    The ultimate use case is producing E2E checks, which assist affirm that the generated code works accurately. Throughout the operating of E2E checks, an SQLite3 database is used for migrations and seeds.

    Primarily supported LLM purchasers are OpenAI and Claude.

    Find out how to Use It

    To get began, navigate to the foundation folder llm-codegen and set up all dependencies by operating:

    npm i

    llm-codegen doesn’t depend on Docker or another heavy third-party dependencies, making setup and execution straightforward and easy. Earlier than operating the device, make sure that you set no less than one *_API_KEY surroundings variable within the .env file with the suitable API key to your chosen LLM supplier. All supported surroundings variables are listed within the .env.pattern file (OPENAI_API_KEY, CLAUDE_API_KEY and many others.) You should use OpenAI, Anthropic Claude, or OpenRouter LLaMA. As of mid-December, OpenRouter LLaMA is surprisingly free to make use of. It’s potential to register here and procure a token free of charge utilization. Nevertheless, the output high quality of this free LLaMA mannequin might be improved, as a lot of the generated code fails to move the compilation stage.

    To start out llm-codegen, run the next command:

    npm run begin

    Subsequent, you’ll be requested to enter the module description and identify. Within the module description, you may specify all essential necessities, akin to entity attributes and required operations. The core remaining work is carried out by micro-agents: Developer, Troubleshooter, and TestsFixer.

    Right here is an instance of a profitable code technology:

    Profitable code technology

    Beneath is one other instance demonstrating how a compilation error was mounted:

    The next is an instance of a generated orders module code:

    A key element is which you could generate code step-by-step, beginning with one module and including others till all required APIs are full. This method means that you can generate code for all required modules in just some command runs.

    How It Works

    As talked about earlier, all work is carried out by these micro-agents: Developer, Troubleshooter and TestsFixer, managed by the Orchestrator. They run within the listed order, with the Developer producing a lot of the codebase. After every code technology step, a test is carried out for lacking recordsdata primarily based on their roles (e.g., routes, controllers, providers). If any recordsdata are lacking, a brand new code technology try is made, together with directions within the immediate concerning the lacking recordsdata and examples for every position. As soon as the Developer completes its work, TypeScript compilation begins. If any errors are discovered, the Troubleshooter takes over, passing the errors to the immediate and ready for the corrected code. Lastly, when the compilation succeeds, E2E checks are run. At any time when a take a look at fails, the TestsFixer steps in with particular immediate directions, guaranteeing all checks move and the code stays clear.

    All micro-agents are derived from the BaseAgent class and actively reuse its base technique implementations. Right here is the Developer implementation for reference:

    Every agent makes use of its particular immediate. Try this GitHub link for the immediate utilized by the Developer.

    After dedicating important effort to analysis and testing, I refined the prompts for all micro-agents, leading to clear, well-structured code with only a few points.

    Throughout the improvement and testing, it was used with numerous module descriptions, starting from easy to extremely detailed. Listed here are a number of examples:

    - The module accountable for library guide administration should deal with endpoints for CRUD operations on books.
    - The module accountable for the orders administration. It should present CRUD operations for dealing with buyer orders. Customers can create new orders, learn order particulars, replace order statuses or data, and delete orders which are canceled or accomplished. Order should have subsequent attributes: identify, standing, positioned supply, description, picture url
    - Asset Administration System with an "Property" module providing CRUD operations for firm property. Customers can add new property to the stock, learn asset particulars, replace data akin to upkeep schedules or asset areas, and delete data of disposed or bought property.

    Testing with gpt-4o-mini and claude-3-5-sonnet-20241022 confirmed comparable output code high quality, though Sonnet is costlier. Claude Haiku (claude-3–5-haiku-20241022), whereas cheaper and comparable in value to gpt-4o-mini, usually produces non-compilable code. Total, with gpt-4o-mini, a single code technology session consumes a mean of round 11k enter tokens and 15k output tokens. This quantities to a price of roughly 2 cents per session, primarily based on token pricing of 15 cents per 1M enter tokens and 60 cents per 1M output tokens (as of December 2024).

    Beneath are Anthropic utilization logs exhibiting token consumption:

    Based mostly on my experimentation over the previous few weeks, I conclude that whereas there should be some points with passing generated checks, 95% of the time generated code is compilable and runnable.

    I hope you discovered some inspiration right here and that it serves as a place to begin to your subsequent Node.js API or an improve to your present venture. Ought to you’ve got options for enhancements, be happy to contribute by submitting PR for code or immediate updates.

    In the event you loved this text, be happy to clap or share your ideas within the feedback, whether or not concepts or questions. Thanks for studying, and pleased experimenting!

    UPDATE [February 9, 2025]: The LLM-Codegen GitHub repository was up to date with DeepSeek API help. It’s cheaper than gpt-4o-mini and provides almost the identical output high quality, nevertheless it has an extended response time and generally struggles with API request errors.

    Until in any other case famous, all pictures are by the writer



    Source link
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous Article“Linear Regression vs Decision Tree — Which Machine Learning Model to Use?” | by Yee | Feb, 2025
    Next Article Training AI Is ‘Perfect’ Work for Introverts. Here’s Why.
    Team_AIBS News
    • Website

    Related Posts

    Artificial Intelligence

    How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1

    July 1, 2025
    Artificial Intelligence

    STOP Building Useless ML Projects – What Actually Works

    July 1, 2025
    Artificial Intelligence

    Implementing IBCS rules in Power BI

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1

    July 1, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Dr. A.P.J. Abdul Kalam (1931–2015) was an Indian aerospace scientist and the 11th President of India, serving from 2002 to 2007. Known as the “Missile Man of India” for his pivotal role in developing the nation’s missile and nuclear programs, he was instrumental in advancing India’s defense capabilities. | by KAMLESH | Jan, 2025

    January 2, 2025

    Why Great Products Still Get Ignored — and How to Get Noticed

    June 30, 2025

    Carvana, a Used Car Retailer, Thinks Trump’s Tariffs Could be Good for Business

    May 13, 2025
    Our Picks

    How to Access NASA’s Climate Data — And How It’s Powering the Fight Against Climate Change Pt. 1

    July 1, 2025

    From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025

    July 1, 2025

    Using Graph Databases to Model Patient Journeys and Clinical Relationships

    July 1, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.