napi
is a versatile tool built by NanoAPI and designed to automatically refactor large monolithic codebases into smaller, more manageable microservices.
With both a powerful CLI and an intuitive UI, napi
is compatible with all major CI/CD platforms, allowing seamless integration into your development and deployment pipelines.
It also provides a new auditing feature to identify parts of your codebase that could benefit from improvements.
- 🚨 Audit: Pinpoint areas of your code that need refactoring or cleanup.
- 📝 Refactor: Split your monolith into microservices using the UI and annotations in the code.
- 🏗️ Build: Generate modular microservices ready for deployment.
- ⚙️ Integrate: Use CLI commands compatible with all CI/CD workflows for automation.
- Identifies problematic code and potential improvements early.
- Simplifies the process of breaking down monoliths into microservices.
- Improves understanding, maintainability, and robustness at both the architecture and code level.
- Reduces dependency on consultants or contractors for complex refactoring tasks.
- Accelerates development with a "develop monolith, deploy microservice" approach.
If you have questions that aren't covered here, feel free to email us at [email protected].
NanoAPI does not modify your original code directly. Instead, it uses annotations to identify API endpoints, then generates new, isolated microservices based on these annotations. Your existing code remains untouched.
NanoAPI copies and restructures relevant parts of the codebase during the splitting process, ensuring that the refactored output exists alongside the original monolith.
If you're curious, take a look at our source code to explore how it works.
Before reaching out, check our FAQ section for answers to common questions.
napi
aims to support all major programming languages. Here is the current status:
Language/Framework | Status | Related Issues |
---|---|---|
JavaScript | ✅ Supported | Early Core Feature |
TypeScript | ✅ Supported | Early Core Feature |
Python | ✅ Supported | #28 |
PHP | 🚧 In Progress | #30 |
C# | 🚧 In Progress | #31 |
Java | 🚧 In Progress | #32 |
C | 🚧 In Progress | Not Tracked Yet |
C++ | 🚧 In Progress | Not Tracked Yet |
For the latest updates, visit our project board.
Ensure you have Node.js (>=18) and npm installed.
npm install -g @nanoapi.io/napi
napi
provides a streamlined Command-Line Interface (CLI) to interact with and refactor your software projects quickly and efficiently.
For a full list of commands, run:
napi --help
Initialize the project. This step is required before running any other command.
This will create a .napirc configuration file in the project root, storing paths and settings necessary for further commands.
Scan and audit your codebase for potential improvements, vulnerabilities, and maintainability issues. This command opens the NanoAPI UI in your default browser, providing a clear overview of what areas of your code would benefit most from refactoring or cleanup.
Important: Run napi audit view periodically, especially before major refactoring efforts, to ensure your code is in good shape. It will soon also be possible to integrate that command into CI/CD workflows to catch code-quality issues early.
Annotate your API automatically using OpenAI. This is a great way to get started quickly for large or complex codebases.
Important: LLMs can make mistakes. We recommend reviewing AI-generated annotations carefully before running
napi split run
to avoid unexpected behavior in the resulting microservices.
Important We recommand you to read Split with Annotations before generating annotations.
Open the NanoAPI UI in your default browser to configure and organize API endpoints visually. This interactive interface allows you to manage groups, refactor, and preview microservices before the split.
Important: This process relies on annotation (see Split with Annotations).
Split the codebase into smaller, more manageable pieces based on annotations. This is ideal for simplifying large monolithic projects.
Important: This process relies on annotation (see Split with Annotations).
NanoAPI uses annotations to simplify the process of splitting codebases.
Annotations define the structure of your API by marking endpoints, methods, and groups directly in the code. You add these annotations on top of blocks of code that are registering or handling endpoints. These annotations guide how your monolith will be split into microservices.
You can check the examples to see how you should annotate your codebases in the examples.
An annotation takes the form:
// @nanoapi path:/random method:GET group:Math
@nanoapi | Marks the comment as an annotation. |
path: | Defines the API endpoint path (e.g., /random/:length). |
method: (Optional) | Specifies the HTTP method (e.g., GET, POST). |
group: (Optional) | Organizes endpoints into services during the split. |
NanoAPI intelligently filters and organizes code by retaining relevant groups and discarding unused segments. This ensures that your microservices are lean and contain only necessary dependencies.
The process is as follows:
- Annotations matching the targeted group are kept.
- Annotations from different groups are removed. As well as all their dependents.
- Unused code gets removed.
You can view more examples in the examples
// src/api.js
// @nanoapi path:/api/v1/users method:GET group:Users
app.get("/api/v1/users", (req, res) => {
res.send("Users data");
});
// @nanoapi path:/api/v1/users/<id> method:GET group:Users
app.get("/api/v1/users/<id>", (req, res) => {
res.send("User data");
});
// @nanoapi path:/api/v1/orders method:POST group:Orders
app.post("/api/v1/orders", (req, res) => {
res.send("Order created");
});
// napi_dist/0/src.js
/// @nanoapi path:/api/v1/users method:GET group:Users
app.get("/api/v1/users", (req, res) => {
res.send("Users data");
});
// @nanoapi path:/api/v1/users/<id> method:GET group:Users
app.get("/api/v1/users/<id>", (req, res) => {
res.send("User data");
});
// napi_dist/1/src.js
// @nanoapi path:/api/v1/orders method:POST group:Orders
app.post("/api/v1/orders", (req, res) => {
res.send("Order created");
});
Running napi split run
with the following annotations will generate modular services based on these annotations. You'll have a Users
service and an Orders
service, each containing the respective endpoint.
There are two ways to annotate your code:
Add annotations directly above relevant code blocks.
Automatically generate annotations for large codebases using AI.
napi split annotate openai
napi
works seamlessly with CI/CD platforms like GitHub Actions, GitLab CI/CD, and Jenkins.
We welcome contributions from the community. Please read our contributing guide for details on how to get involved.
napi
is licensed under the Sustainable Use License.
- Automating the Strangler Pattern with Microlithic Development
- Rise of the "Microlith": Rethinking Microservices for Modern Developers
NanoAPI is a fair-source project. Because of this, we feel it would be unethical to keep any donations to ourselves. Instead, here is how we will handle donations:
- Donations go into a pool
- Money from the pool will be distributed to contributors
- At the end of the year, any remaining money will be donated to a charity of the community's choice
We will post regular updates on how much money is in the pool and how it is being distributed.