Understanding NanoAPI Concepts

NanoAPI is built around several key concepts that allow our tool to examine and perform functionality extraction on your codebases. This documentation delves into the fundamental concepts behind NanoAPI, focusing on the Code Manifest, Symbol Extraction, and Architecture History.

Code Manifest

The Code Manifest serves as a comprehensive blueprint or map of your project's structure. It details various components such as files, classes, functions, and their interdependencies. By generating a Code Manifest, NanoAPI provides developers with a clear overview of their codebase, facilitating better understanding and management.

Using these manifests, we can generate views like the following for Apache Airflow.


Symbol Extraction

Symbol Extraction in NanoAPI refers to the process of identifying and isolating specific symbols—such as classes and functions—from your codebase to create smaller units of functionality such as microservices or serverless functions. This approach enables the decomposition of a monolithic application into smaller, more manageable services that can be deployed and scaled independently.

For instance, consider a Node.js Express server with multiple endpoints. By utilizing NanoAPI's Symbol Extraction feature, each endpoint can be transformed into a standalone service, encapsulating its respective functionality. This modularization enhances scalability and maintainability, and can assist in large lift-and-shift operations.

What are symbols?

Symbols are how our tool recognizes definitions within any programming language. The following items within a programming language fall within this definition:

  • Imports/Exports: Any imports into a file, or exports out of a file, are read by our system to define file-level dependencies within or across your system.

  • Namespaces: Similar to imports/exports, namespaces are considered by our system to fully map out relationships within a codebase — allowing for classes and functions with the same name to be considered separately.

  • Functions: Any function definition within the relevant programming language is also understood by our system, as well as a graph of all the dependencies required to run that function.

  • Classes: Any class not defined by external dependencies (language libs, frameworks) is also ingested into the manifest, much in the same way as functions.

Example Case

Let’s examine a simple case.

The code below represents a simple Node.js/Express app.

// src/api.js

app.get("/api/v1/users", (req, res) => {
  res.send("Users data");
});

app.get("/api/v1/users/<id>", (req, res) => {
  res.send("User data");
});

app.post("/api/v1/orders", (req, res) => {
  res.send("Order created");
});

Let’s use napi to extract the /api/v1/orders symbol definition. After running the CLI command, you would have two output projects in napi_dist (or whatever your output folder is):

// This is the output of the system without the /api/v1/orders functionality
// napi_dist/0/src.js

app.get("/api/v1/users", (req, res) => {
  res.send("Users data");
});

app.get("/api/v1/users/<id>", (req, res) => {
  res.send("User data");
});

And:

// This contains ONLY the functionality required for the selected symbol
// 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");
});

While this is a massively oversimplified example, it should be sufficient to show what we enable: the ability to extract functionality from codebases either locally or at run time — allowing for smaller, more robust systems while also tracking how your software architecture is impacted.


Architecture History

Architecture History allows developers to track and visualize changes in the Code Manifest over time, akin to a version control system for your project's architecture. By integrating with Git, NanoAPI enables you to:

  • Navigate Through Architectural Changes: Review how your codebase's structure has evolved across different commits.

  • Compare Versions: Identify additions, deletions, or modifications in classes, functions, and their relationships between various points in time.

This feature provides valuable insights into the development trajectory of your project, aiding in refactoring decisions and ensuring consistency in architectural design.

By leveraging the Code Manifest, Symbol Extraction, and Architecture History features of NanoAPI, developers can effectively transform and manage their applications, promoting a more modular, scalable, and maintainable architecture.

Inter-service Interaction (coming soon)

In the near future, NanoAPI will also track the interactions between your services to provide system-wide visualizations while helping you track potential service brittleness or bottlenecks. Contact us for a demo.

Updated on