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.
- 🔍 Inspect: Analyze your codebase to identify API endpoints, middleware, and other API-specific components.
- 📝 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.
- 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 init
This will initialize the .napirc
configuration file, which is essential for managing your project’s paths and settings. All future CLI commands, including code splitting and UI configuration, rely on this file.
NanoAPI relies on annotations to split your codebase. Annotations mark API endpoints, methods, and groups in your code, guiding how monolithic projects are refactored into microservices.
Important: Before running
napi split run
, you need to annotate your codebase. If you're not familiar with the process, see Split with Annotations for a detailed guide and examples.
napi split configure
This will launch the configuration UI. It allows you to configure and preview how your codebase will be split.
napi split run
This command allow you to split your codebase. You can use this in your CI pipeline if needed.
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 and generate the .napirc configuration file. This step is required before running any other command.
napi init
This will create a .napirc configuration file in the project root, storing paths and settings necessary for further commands.
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.
napi split configure
The UI relies on the .napirc configuration file.
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).
napi split run
Note: This command uses the .napirc configuration file.
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.
// 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");
});
There are three ways to annotate your code:
Add annotations directly above relevant code blocks.
Automatically generate annotations for large codebases using the CLI with AI support.
napi split annotate openai --apiKey="sk-**"
Note: LLMs can make mistakes. We recommend reviewing AI-generated annotations carefully before running napi split run
to avoid unexpected behavior in the resulting microservices.
You can use annotations to specify how to split your code. Simply add them above blocks of code that is handling or registering an endpoint Here’s an example:
// src/api.js
// @nanoapi endpoint:/api/v1/users method:GET group:Users
app.get("/api/v1/users", (req, res) => {
res.send("User data");
});
// @nanoapi endpoint:/api/v1/orders method:POST group:Orders
app.post("/api/v1/orders", (req, res) => {
res.send("Order created");
});
You can view more examples in the examples
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.
The UI allows you to organize and preview your microservices visually before finalizing the split through the CLI.
napi split configure
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.