Skip to content

Ali-khan-786/Codalyze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Codalyze

Codalyze is a web-based C++ static code analyzer that estimates Time Complexity, Space Complexity, detects STL containers, STL algorithms, recursion, and provides optimization suggestions using Tree-sitter Abstract Syntax Trees (AST).

๐Ÿ”— Live Demo: https://codalyze-two.vercel.app/


๐Ÿ“Œ Features

  • ๐Ÿ“ˆ Estimates overall Time Complexity
  • ๐Ÿ’พ Estimates Auxiliary Space Complexity
  • ๐Ÿ”„ Detects loops and nested loops
  • ๐Ÿ” Detects recursive functions
  • ๐Ÿ“š Detects STL Containers
    • vector
    • map
    • unordered_map
    • set
    • unordered_set
    • queue
    • stack
    • priority_queue
  • โšก Detects common STL Algorithms
    • sort()
    • stable_sort()
    • reverse()
    • binary_search()
    • lower_bound()
    • upper_bound()
    • nth_element()
  • ๐Ÿ“ Generates Complexity Timeline
  • ๐Ÿ’ก Provides Optimization Suggestions
  • ๐ŸŽจ Clean and Interactive UI
  • ๐ŸŒ Fully Deployed (Frontend + Backend)

๐Ÿ—๏ธ Tech Stack

Frontend

  • HTML5
  • CSS3
  • JavaScript

Backend

  • Node.js
  • Express.js

Parser

  • Tree-sitter
  • tree-sitter-cpp

Deployment

  • Frontend: Vercel
  • Backend: Render

๐Ÿ“‚ Project Structure

Codalyze
โ”‚
โ”œโ”€โ”€ backend
โ”‚   โ”œโ”€โ”€ analyzer
โ”‚   โ”‚   โ”œโ”€โ”€ database
โ”‚   โ”‚   โ”œโ”€โ”€ visitors
โ”‚   โ”‚   โ”œโ”€โ”€ cppAnalyzer.js
โ”‚   โ”‚   โ”œโ”€โ”€ complexityCalculator.js
โ”‚   โ”‚   โ”œโ”€โ”€ optimizationEngine.js
โ”‚   โ”‚   โ”œโ”€โ”€ timelineGenerator.js
โ”‚   โ”‚   โ””โ”€โ”€ treeWalker.js
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ server.js
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ script.js
โ”œโ”€โ”€ style.css
โ”‚
โ”œโ”€โ”€ timeReport.html
โ”œโ”€โ”€ timeReport.js
โ”‚
โ”œโ”€โ”€ spaceReport.html
โ”œโ”€โ”€ spaceReport.js
โ”‚
โ”œโ”€โ”€ optimization.html
โ”œโ”€โ”€ optimization.js
โ”‚
โ””โ”€โ”€ README.md

โš™๏ธ How It Works

  1. User writes or pastes C++ code.
  2. Frontend sends the code to the Express backend.
  3. Tree-sitter parses the source code into an Abstract Syntax Tree (AST).
  4. Visitors traverse the AST to detect:
    • loops
    • recursion
    • STL containers
    • STL algorithms
    • function calls
  5. Complexity Engine estimates:
    • Time Complexity
    • Space Complexity
  6. Optimization Engine generates suggestions.
  7. Results are returned as JSON and displayed in interactive reports.

๐Ÿง  Detection Capabilities

Loops

  • for
  • while
  • do-while
  • nested loops

Recursion

  • Direct recursion

STL Containers

  • vector
  • map
  • unordered_map
  • set
  • unordered_set
  • queue
  • stack
  • priority_queue

STL Algorithms

  • sort
  • stable_sort
  • reverse
  • binary_search
  • lower_bound
  • upper_bound
  • nth_element

๐Ÿ“Š Example Output

Time Complexity

Overall : O(n log n)

Worst Case : O(n log n)

Average Case : O(n log n)

Best Case : O(log n)

Space Complexity

Overall : O(n)

Optimization Suggestions

Example suggestions include:

  • Reduce Nested Loops
  • Reserve Vector Capacity
  • Check Sorting Necessity
  • Consider unordered_map instead of map
  • Avoid Deep Recursion

๐Ÿš€ Running Locally

Clone Repository

git clone https://github.com/YOUR_USERNAME/Codalyze.git

Install Backend

cd backend

npm install

Run Server

npm start

Server runs on

http://localhost:5000

Run Frontend

Open

index.html

using Live Server or any static web server.


๐ŸŒ Deployment

Frontend

Hosted on Vercel

Backend

Hosted on Render


๐ŸŽฏ Current Capabilities

Codalyze is designed to accurately analyze many common competitive programming and interview-style C++ programs.

It currently focuses on:

  • Loop analysis
  • Nested loops
  • STL algorithm detection
  • STL container detection
  • Recursive functions
  • Basic complexity estimation

๐Ÿ”ฎ Future Improvements

  • Support for Graph algorithms
  • Dynamic Programming detection
  • Greedy algorithm recognition
  • Binary Search pattern detection
  • DFS/BFS recognition
  • Segment Tree detection
  • Fenwick Tree detection
  • Better recursion depth estimation
  • Multi-file project support
  • Additional programming languages

๐Ÿค Contributing

Contributions are welcome.

If you find bugs or have ideas for improvements, feel free to open an Issue or submit a Pull Request.


๐Ÿ‘จโ€๐Ÿ’ป Author

Ali Khan

GitHub:

https://github.com/Ali-khan-786


โญ If you like this project

Give this repository a โญ on GitHub.

It helps others discover the project and motivates future improvements.

About

C++ Code Complexity Analyzer using Tree-sitter AST(Abstract Syntax Tree)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors