analyze-project-structure
v2.0.1
Published
CLI tool for analyzing and printing the folder structure of a project, extracting details about files (such as functions, variables, routes, and imports/exports), and summarizing the project's code organization.
Maintainers
Readme
Analyze Project Structure
A command-line tool to analyze and print the folder structure of JavaScript/TypeScript projects, extracting detailed insights about files, including functions, variables, routes, imports, and exports. It helps summarize the organization of your project’s codebase.
Features
- Recursively prints the folder structure starting from the current directory (or specified folder).
- Extracts detailed info from source files, including:
- Functions (regular and arrow functions)
- Variables (including constants)
- Routes (GET, POST, etc. with handler details)
- Imports and exports
- Supports popular frameworks with enhanced parsing:
- Angular (components, services, imports, functions)
- Express (routes, imports, classes, functions, variables)
- React (components, hooks, imports, functions)
- Outputs a clean, tree-like formatted text file or JSON file for easy reading.
- Default output file is
folder-structure-output.txtin text format, customizable via command line. - Supports output in JSON format by specifying the format argument.
Installation
Global Installation
Install the tool globally to run from anywhere:
npm install -g analyze-project-structureLocal Installation
Install as a development dependency in your project:
npm install analyze-project-structure --save-devUsage
Run the tool from your project root directory (where package.json and source folders like src exist):
analyze-project-structure [outputFile] [outputFormat]or using the alias:
aps [outputFile] [outputFormat]outputFile(optional): Specify a custom output file name. Defaults tofolder-structure-output.txt.outputFormat(optional): Specify the output format, eithertext(default) orjson.
Examples
Generate the default output file in text format:
analyze-project-structureor
apsGenerate output with a custom file name in text format:
analyze-project-structure my-output.txtor
aps my-output.txtGenerate output in JSON format with default file name:
analyze-project-structure folder-structure-output.json jsonor
aps folder-structure-output.json jsonGenerate output in JSON format with custom file name:
analyze-project-structure my-output.json jsonor
aps my-output.json jsonExample Output (Text)
The generated text file will show a detailed, nested folder and file structure with extracted code details. For example:
├── routes
│ ├── appointment.ts
│ │ ├── Routes
│ │ │ ├── /
│ │ │ │ ├── GET
│ │ │ │ │ ├── Handler Variables
│ │ │ │ │ │ └── user
│ │ │ │ │ └── Functions in Handler
│ │ │ │ │ └── Anonymous Arrow Function
│ │ │ │ └── POST
│ │ │ │ ├── Handler Variables
│ │ │ │ │ └── appointment
│ │ │ │ └── Functions in Handler
│ │ │ │ └── Anonymous Arrow Function
│ │ ├── Imports
│ │ │ ├── express
│ │ │ └── ../../db
│ │ ├── Exports
│ │ │ └── appointmentRouter
│
│ └── auth.ts
│ ├── Routes
│ │ └── /register
│ │ └── POST
│ ├── Imports
│ │ ├── express
│ │ ├── bcryptjs
│ │ ├── jsonwebtoken
│ │ ├── express-validator
│ │ └── ../../db
│ ├── Exports
│ │ └── authRoutes
│
├── server.ts
│ ├── Imports
│ │ ├── express
│ │ ├── helmet
│ │ ├── ./routes/auth
│ │ └── ./routes/appointmentExample Output (JSON)
The generated JSON file will contain the same structure in a JSON object format, suitable for programmatic consumption.
{
"routes": {
"appointment.ts": {
"routes": [
{
"path": "/",
"methods": [
{
"type": "GET",
"handlerVariables": ["user"],
"functions": ["Anonymous Arrow Function"]
},
{
"type": "POST",
"handlerVariables": ["appointment"],
"functions": ["Anonymous Arrow Function"]
}
],
"imports": ["express", "../../db"],
"exports": ["appointmentRouter"]
}
]
},
"auth.ts": {
"routes": [
{
"path": "/register",
"methods": [
{
"type": "POST"
}
],
"imports": [
"express",
"bcryptjs",
"jsonwebtoken",
"express-validator",
"../../db"
],
"exports": ["authRoutes"]
}
]
}
},
"server.ts": {
"imports": [
"express",
"helmet",
"./routes/auth",
"./routes/appointment"
]
}
}Supported Frameworks
- Angular: Detects components, services, imports, and functions by parsing decorators.
- Express: Detects routes, imports, classes, functions, and variables.
- React: Detects components, hooks, imports, and functions.
The tool automatically detects the project type from your package.json dependencies and adjusts parsing accordingly.
License
This project is licensed under the ISC License - see the LICENSE file for details.
Author
Prasad Dhule
