Skip to content

Commit 22c367b

Browse files
authored
Merge pull request #66 from nanoapi-io/feature/refactoring-audit
feature/refactoring audit
2 parents 53d6744 + ca67c72 commit 22c367b

File tree

203 files changed

+36924
-24485
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+36924
-24485
lines changed

.github/CONTRIBUTING.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,62 @@ $ npm install
7474

7575
### Running the Project
7676

77-
When running locally, the UI and CLI must be run separately to avoid having to recreate production builds of the UI on each change.
77+
When running locally, the UI must be built before the CLI can be run.
7878

79-
To run the UI:
79+
To build the UI:
8080

8181
```bash
82-
$ npm run dev:app
82+
$ npm run build
8383
```
8484

8585
To run the CLI:
8686

8787
```bash
88-
$ npm run dev:cli <command>
88+
$ npm start
8989
```
9090

91-
Running the `ui` command from the CLI will spin up a web server on your localhost. You can access the UI by navigating to `http://localhost:3000`.
91+
Running the `audit view` command from the CLI will spin up a web server on your localhost. You can access the UI by navigating to `http://localhost:3000`.
9292

9393
> **Note:** In case of port collisions, the UI will automatically switch to the next available port.
9494
95+
### Project Setup
96+
97+
You can use any project (in a supported language) to test the CLI. There are some steps that must be taken to set up the project:
98+
99+
1. Clone or CD to the repo you want to work on/test with. For this example we'll use Apache Airflow.
100+
```bash
101+
git clone https://github.com/apache/airflow.git
102+
cd airflow
103+
```
104+
105+
2. From the `napi` repo initialize the project using the CLI:
106+
```bash
107+
cd /path/to/napi # or just use a different terminal
108+
npm start -- init -- --workdir=/path/to/airflow
109+
```
110+
111+
3. This will create a `.napirc` file in root of the project. The file should look like the following. You can copy this content into the file and overwrite it if you are having issues.
112+
```json
113+
{
114+
"entrypoint": "app.py",
115+
"out": "napi_dist",
116+
"audit": {
117+
"language": "python",
118+
"include": ["airflow-core/src/airflow/**/*"],
119+
"exclude": [],
120+
"targetMaxCharInFile": 5000,
121+
"targetMaxLineInFile": 500,
122+
"targetMaxDepPerFile": 4
123+
}
124+
}
125+
```
126+
127+
4. Now the audit view can be run.
128+
```bash
129+
npm start -- audit view -- --workdir=/path/to/airflow
130+
```
131+
132+
5. The audit view will be available at `http://localhost:3000` and should automatically open in your default browser.
95133

96134
### Testing
97135

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@ dist
44
napi_dist
55
__pycache__
66
.ruff_cache
7-
.OPENAIKEY
7+
.OPENAIKEY
8+
examples/csharp/EndpointExample/obj
9+
examples/csharp/EndpointExample/bin
10+
packages/cli/src/languagePlugins/csharp/testFiles/csharpFiles/**/obj
11+
napi.sln
12+
examples/csharp/EndpointExample/bin
13+
auditResponse.json
14+
.extracted/

README.md

Lines changed: 17 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,52 @@
11
![NanoAPI Banner](/media/github-banner.png)
22

3-
# napi - Isolate and deploy APIs separately at build time
3+
# napi - Better Software Architecture for the AI Age
44

5-
`napi` is a versatile tool built by NanoAPI and designed to automatically refactor large monolithic codebases into smaller, more manageable microservices, while providing insights into the architectural complexity of your software.
5+
`napi` is a versatile tool built by NanoAPI and designed to automatically extract functionality from large, monolithic codebases into smaller units, while providing insights into the architectural complexity of your software.
66
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.
77

8-
Historically, tools like this have only been built by large consulting firms or contractors and kept behind the paywalls of consulting fees. `napi` aims to make these tools accessible to developers of all skill levels, without the cost. Our vision is to help you reduce your reliance on consultants and contractors, while gaining deeper insights into system architecture-level concerns. The added benefit? No more black-box consultant tools running on your code.
8+
Historically, tools like this have only been built by large consulting firms or contractors and kept behind the paywalls of consulting fees. `napi` aims to make these tools accessible to developers of all skill levels, without the cost. Our vision is to help you gain deeper insights into system architecture-level concerns before they become hundred-million-dollar problems. The added benefit? No more black-box tools running on your code.
99

1010
![NanoAPI UI Overview](/media/hero-app.png)
1111

1212
## Features
1313

1414
- **🚨 Audit**: Pinpoint areas of your code that need refactoring or cleanup.
15-
- **📝 Refactor**: Split your monolith into microservices using the UI and annotations in the code.
15+
- **📝 Refactor**: Extract functionality using the UI to improve architecture.
1616
- **🏗️ Build**: Generate modular microservices ready for deployment.
1717
- **⚙️ Integrate**: Use CLI commands compatible with all CI/CD workflows for automation.
18+
- **🔍 Architecture**: Get a live view of all your software and their interactions; scoped to a specific moment in time.
19+
- **📖 History**: Track changes to architecture through time using a git-history-style tool.
20+
- **📈 Graphs**: Understand if your software is improving or degrading over time.
1821

1922
## Why `napi`?
2023

2124
- Identifies problematic code and potential improvements early.
22-
- Simplifies the process of breaking down monoliths into microservices.
25+
- Simplifies the process of extracting functionality using non-AI strangler refactoring.
2326
- Improves understanding, maintainability, and robustness at both the architecture and code level.
24-
- Reduces dependency on consultants or contractors for complex refactoring tasks.
25-
- Accelerates development with a "develop monolith, deploy microservice" approach.
26-
27-
## FAQs
28-
29-
If you have questions that aren't covered here, feel free to email us at [email protected].
30-
31-
#### Does NanoAPI edit my code?
32-
33-
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.
34-
35-
NanoAPI copies and restructures relevant parts of the codebase during the splitting process, ensuring that the refactored output exists alongside the original monolith.
36-
37-
If you're curious, take a look at our source code to explore how it works.
38-
39-
## Support
40-
41-
Before reaching out, check our [FAQ section](#faqs) for answers to common questions.
42-
43-
<div align="center">
44-
<p>For questions or issues, feel free to open an issue on GitHub or join us on our server on Discord.</p>
45-
<table>
46-
<tr>
47-
<td valign="center">
48-
<a href="https://github.com/nanoapi-io/napi/issues/new/choose" target="_blank">
49-
<img src="https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg" alt="GitHub Logo" width="50" />
50-
</a>
51-
</td>
52-
<td valign="center">
53-
<a href="https://discord.gg/4ZaQ347ZmQ" target="_blank">
54-
<img src="https://cdn.prod.website-files.com/6257adef93867e50d84d30e2/653714c1c2d8d50382c7df8a_636e0b5061df29d55a92d945_full_logo_blurple_RGB.svg" alt="Discord Logo" width="100" height="100" />
55-
</a>
56-
</td>
57-
</tr>
58-
</table>
59-
</div>
27+
- Reduces dependency on outside sources for complex refactoring tasks.
28+
- Gain a deeper trust of what your system is doing today - even in the face of AI-generated code.
6029

6130
## Supported Languages
6231

6332
`napi` aims to support all major programming languages. Here is the current status:
6433

6534
| Language/Framework | Status | Related Issues |
6635
| ------------------ | -------------- | --------------------------------------------------- |
67-
| JavaScript | ✅ Supported | Early Core Feature |
68-
| TypeScript | ✅ Supported | Early Core Feature |
6936
| Python | ✅ Supported | [#28](https://github.com/nanoapi-io/napi/issues/28) |
7037
| C# | 🚧 In Progress | [#31](https://github.com/nanoapi-io/napi/issues/31) |
7138
| PHP | 🚧 In Progress | [#30](https://github.com/nanoapi-io/napi/issues/30) |
7239
| Java | 🚧 In Progress | [#32](https://github.com/nanoapi-io/napi/issues/32) |
7340
| C | 🚧 In Progress | Not Tracked Yet |
7441
| C++ | 🚧 In Progress | Not Tracked Yet |
42+
| JavaScript | 🚧 In Progress | Not Tracked Yet |
43+
| TypeScript | 🚧 In Progress | Not Tracked Yet |
7544

7645
For the latest updates, visit our [project board](/projects).
7746

7847
## Installation
7948

80-
Ensure you have Node.js (>=18) and npm installed.
49+
Ensure you have Node.js (>=22) and npm installed.
8150

8251
https://nodejs.org/en
8352

@@ -107,136 +76,13 @@ This will create a .napirc configuration file in the project root, storing paths
10776

10877
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.
10978

110-
> **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.
111-
112-
### `napi split annotate openai`
113-
114-
Annotate your API automatically using OpenAI. This is a great way to get started quickly for large or complex codebases.
115-
116-
> **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.
117-
118-
> **Important** We recommand you to read [Split with Annotations](#split-with-annotations) before generating annotations.
119-
120-
### `napi split configure`
121-
122-
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.
123-
124-
> **Important:** This process relies on annotation (see [Split with Annotations](#split-with-annotations)).
125-
126-
### `napi split run`
127-
128-
Split the codebase into smaller, more manageable pieces based on annotations. This is ideal for simplifying large monolithic projects.
129-
130-
> **Important:** This process relies on annotation (see [Split with Annotations](#split-with-annotations)).
131-
132-
## Split with Annotations
133-
134-
NanoAPI uses annotations to simplify the process of splitting codebases.
135-
136-
Annotations define the structure of your API by marking endpoints, methods, and groups directly in the code.
137-
You add these annotations on top of blocks of code that are registering or handling endpoints.
138-
These annotations guide how your monolith will be split into microservices.
139-
140-
You can check the examples to see how you should annotate your codebases in the [examples](/examples/).
141-
142-
### Annotation Structure
143-
144-
An annotation takes the form:
145-
146-
```javascript
147-
// @nanoapi path:/random method:GET group:Math
148-
```
149-
150-
### Breakdown of the Annotation:
151-
152-
| | |
153-
| ------------------------------ | ------------------------------------------------------ |
154-
| **@nanoapi** | Marks the comment as an annotation. |
155-
| **path:<path>** | Defines the API endpoint path (e.g., /random/:length). |
156-
| **method:<method>** (Optional) | Specifies the HTTP method (e.g., GET, POST). |
157-
| **group:<group>** (Optional) | Organizes endpoints into services during the split. |
158-
159-
### How does napi split based on the annotation
160-
161-
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.
162-
163-
The process is as follows:
164-
165-
- Annotations matching the targeted group are kept.
166-
- Annotations from different groups are removed. As well as all their dependents.
167-
- Unused code gets removed.
168-
169-
### Example
170-
171-
You can view more examples in the [examples](/examples/)
172-
173-
#### Input
174-
175-
```js
176-
// src/api.js
177-
178-
// @nanoapi path:/api/v1/users method:GET group:Users
179-
app.get("/api/v1/users", (req, res) => {
180-
res.send("Users data");
181-
});
182-
183-
// @nanoapi path:/api/v1/users/<id> method:GET group:Users
184-
app.get("/api/v1/users/<id>", (req, res) => {
185-
res.send("User data");
186-
});
187-
188-
// @nanoapi path:/api/v1/orders method:POST group:Orders
189-
app.post("/api/v1/orders", (req, res) => {
190-
res.send("Order created");
191-
});
192-
```
193-
194-
#### Resulting output ➡️
195-
196-
```js
197-
// napi_dist/0/src.js
198-
199-
/// @nanoapi path:/api/v1/users method:GET group:Users
200-
app.get("/api/v1/users", (req, res) => {
201-
res.send("Users data");
202-
});
203-
204-
// @nanoapi path:/api/v1/users/<id> method:GET group:Users
205-
app.get("/api/v1/users/<id>", (req, res) => {
206-
res.send("User data");
207-
});
208-
```
209-
210-
```js
211-
// napi_dist/1/src.js
212-
213-
// @nanoapi path:/api/v1/orders method:POST group:Orders
214-
app.post("/api/v1/orders", (req, res) => {
215-
res.send("Order created");
216-
});
217-
```
218-
219-
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.
220-
221-
### How to Annotate my codebase
222-
223-
There are two ways to annotate your code:
224-
225-
#### 1. Manual Annotation
226-
227-
Add annotations directly above relevant code blocks.
228-
229-
#### 2. AI Annotation
230-
231-
Automatically generate annotations for large codebases using AI.
232-
233-
```bash
234-
napi split annotate openai
235-
```
79+
> **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 architectural-level-quality issues early.
23680
23781
## CI/CD Integration
23882

239-
`napi` works seamlessly with CI/CD platforms like GitHub Actions, GitLab CI/CD, and Jenkins.
83+
`napi` works seamlessly with CI/CD platforms like GitHub Actions, GitLab CI/CD, and Jenkins. This allows us to build the code manifest needed for visualization and refactoring in the background, without needing to wait for it to run locally in the case of very large codebases (>1M lines of code).
84+
85+
More information
24086

24187
## Contributing
24288

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"audit": {
3+
"language": "c-sharp",
4+
"include": ["**/*"],
5+
"exclude": ["bin/**", "obj/**"],
6+
"manifestoJsonOutputPath": "./"
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="FastEndpoints" Version="5.35.0" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using FastEndpoints;
2+
3+
var bld = WebApplication.CreateBuilder();
4+
bld.Services.AddFastEndpoints();
5+
6+
var app = bld.Build();
7+
app.UseFastEndpoints();
8+
app.Run();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "http://localhost:5288",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": true,
17+
"applicationUrl": "https://localhost:7299;http://localhost:5288",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}

0 commit comments

Comments
 (0)