nanoapi-io / napi

Transpile your monolithic codebases to microservices in seconds
https://nanoapi.io
Other
171 stars 3 forks source link
apis cli code-analysis code-visualization csharp devtools hacktoberfest java legacy-code-refactoring live-documentation microservices monolith monolith-to-microservices node php python refactoring software-modernization source-code-analysis system-design

napi

Powerful CLI + UI for inspecting and refactoring an API codebase in any language and web framework.

This project is under ongoing development. Check the status section for more information on supported languages and frameworks.

Features

Motivation

To understand better what we mean by the above, please take a look at our documentation.

Design goals

Quick Start

Ensure you have NodeJS >= 18 and NPM installed on your machine.

$ npm install -g @nanoapi.io/napi

To open the UI for your codebase, run the following commands:

$ napi init
$ napi ui

Examples

We are building a collection of example API repositories in each language so you can explore the project. This list will grow over time.

examples

Usage

Installation

We are working on a binary release, but for now, you can install it via this github repository:

$ git clone https://github.com/nanoapi-io/napi.git
$ cd napi
$ npm install

Usage

To open the UI and inspect your codebase, run the following commands:

$ napi init
$ napi ui

Commands:

  init                  Initialize the NanoAPI project
  ui [entrypoint]       Inspect the codebase and understand the API endpoints, middleware, and other API-specific code
  split <entrypoint>    Transform the codebase into smaller, more manageable pieces at build time

Using the UI

The easiest way to refactor your API endpoints is to do it through our UI. You can group endpoints and create builds from here.

Building with Annotations

You can also refactor your codebase by adding annotations to your code. Here is an example of how you can do it:

// src/api.js

import * as express from "express";

import * as service from "./service.js";

const app = express();
const port = 3000;

app.use(express.json());

// @nanoapi endpoint:/api/v2/maths/time method:GET group:Time
app.get("/api/v2/maths/time", (req, res) => {
  const result = service.time();
  return res.json({
    result,
  });
});

// @nanoapi endpoint:/api/v2/maths/addition method:POST group:Maths
app.post("/api/v2/maths/addition", (req, res) => {
  const { body } = req;
  const result = service.addition(body.a, body.b);
  return res.json({
    result,
  });
});

// @nanoapi endpoint:/api/v2/maths/subtraction method:POST group:Maths
app.post("/api/v2/maths/subtraction", (req, res) => {
  const { body } = req;
  const result = service.subtraction(body.a, body.b);
  return res.json({
    result,
  });
});

app.listen(port, () => {
  console.log(`App listening on port: ${port}`);
});

Output

From the exmaple above, you will get the following output from running a build:

// dist/Time/src/api.js

import * as express from "express";

import * as service from "./service.js";

const app = express();
const port = 3000;

app.use(express.json());

app.get("/api/v2/maths/time", (req, res) => {
  const result = service.time();
  return res.json({
    result,
  });
});

app.listen(port, () => {
  console.log(`App listening on port: ${port}`);
});

Contributing and Development

We welcome contributions from the community. Please read our contributing guide for more information.

Status

This project is in the early stages of development. We are actively working on the project and will be releasing new features and improvements regularly, which may include a rewrite into a more efficient and generic language like Rust or Go. Please check our issues and project board for more information, and don't for.

On Donating

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:

We will post regular updates on how much money is in the pool and how it is being distributed.