Skip to content

JameelaJabir/Code-Analyzer-Backend

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Static Code Analyzer — Backend

A REST API that parses JavaScript source files and returns code quality metrics including lines of code, cyclomatic complexity, and maintainability index. Built with Node.js, Express, and MongoDB.


Features

  • JWT Authentication — register, login, and protected routes
  • Code Analysis — paste or upload a .js file and receive:
    • LOC (Lines of Code)
    • LLOC (Logical Lines of Code)
    • SLOC (Source Lines of Code)
    • Comment count and comment percentage
    • Code-to-comment ratio
    • Cyclomatic Complexity (via AST traversal using Esprima)
    • Maintainability Index (0–100 scale)
  • Rules Management — create, read, update, delete, and toggle custom analysis rules
  • Project Management — organize analyses into named projects
  • Folder Management — group files within projects
  • Analysis History — retrieve and manage past analysis records

Tech Stack

Layer Technology
Runtime Node.js
Framework Express.js
Database MongoDB + Mongoose
Auth JSON Web Tokens (JWT) + bcryptjs
Parser Esprima (AST-based JS parser)
File Upload Multer
Logging Morgan

Project Structure

Code-Analyzer-Backend/
├── config/
│   ├── config.env          # Environment variables
│   └── db.js               # MongoDB connection
├── controllers/
│   ├── folderController.js
│   ├── projectController.js
│   └── ruleController.js
├── middlewares/
│   ├── auth.js             # JWT verification middleware
│   └── upload.js           # Multer configuration
├── models/
│   ├── Analyzer.js
│   ├── Folder.js
│   ├── Project.js
│   ├── Rules.js
│   └── User.js
├── routes/
│   ├── analyzerRouter.js   # Code analysis endpoints
│   ├── auth.js             # Register / login / me
│   ├── folderRoutes.js
│   ├── projectRoutes.js
│   └── ruleRoute.js
└── app.js                  # Entry point

Getting Started

Prerequisites

  • Node.js v18+
  • MongoDB (local or Atlas)

Installation

git clone <repo-url>
cd Code-Analyzer-Backend
npm install

Environment Variables

Create config/config.env:

PORT=4000
MONGO_URI=mongodb://localhost:27017/static-code-analyzer
JWT_SECRET=your_jwt_secret_here

Run

# Development (auto-restart with nodemon)
npm run dev

The server starts on http://localhost:4000.


API Endpoints

Auth

Method Endpoint Description Auth Required
POST /api/register Create account No
POST /api/login Login, receive JWT No
GET /api/me Get current user Yes

Code Analysis

Method Endpoint Description
POST /api/home Analyze a JS file
GET /api/home Get all analysis records
GET /api/home/:id Get single analysis
PATCH /api/home/:id Update analysis
DELETE /api/home/:id Delete analysis

Rules

Method Endpoint Description
POST /api/ Create rule
GET /api/ Get all rules (supports ?searchTerm=)
PUT /api/:id Update rule
DELETE /api/:id Delete rule
PUT /api/toggleStatus/:id Toggle active/inactive

Projects

Method Endpoint Description
POST /api/projects Create project
GET /api/projects Get all projects
PUT /api/projects/:id Update project
DELETE /api/projects/:id Delete project

Folders

Method Endpoint Description
POST /api/folders Create folder
GET /api/folders Get all folders
PUT /api/folders/:id Update folder
DELETE /api/folders/:id Delete folder

Metrics Explained

Metric Description
LOC Total number of lines including blanks and comments
LLOC Lines containing a logical statement (;, {, })
SLOC Non-blank, non-comment lines
Cyclomatic Complexity Number of linearly independent paths; counts if, for, while, switch, catch, ternary, etc.
Maintainability Index Score 0–100 derived from the formula 171 − 5.2·log(CC) − 0.23·SLOC − 16.2·log(SLOC). Higher is better.

About

REST API for a JavaScript static code analyzer computes LOC, cyclomatic complexity, and maintainability index via AST parsing with Esprima. Built with Node.js, Express, and MongoDB.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages