Rev Dev Code Review Backend

This backend is built using Express.js and LangChain, providing an efficient solution for developers to conduct code reviews. Whether you want to review code by entering it directly, selecting specific criteria, or uploading files with optional guidelines, this backend has you covered.

Table of Contents

  1. Routes
  2. Getting Started
  3. Usage
  4. Response Format

Routes

api/v1/upload

You can provide one or multiple files for code review, select criteria, and upload an optional guideline file. The response will be an array of JSON objects containing criteria and corresponding reviews.

exemple of request:

const criterias = ["Code Structure", "Error Handling", "Performance"];

// Create FormData object to handle file uploads
const formData = new FormData();

// Append files to FormData
files.forEach(file => {
  formData.append("files", new Blob([file.content]), file.filename);
});

// Append criterias to FormData
formData.append("criterias", JSON.stringify(criterias));

// Fetch API POST request
fetch("http://localhost:3000/api/v1/upload", {
  method: "POST",
  body: formData
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));

api/v1/upload/stream

Similar to the previous route, but it provides a single streamed response for a criteria and/or guideline file.

exemple of request:

const formData = new FormData();
formData.append("files", file)
const fetchRepos = async () => {
        try {
          const response = await fetch(
            "http://localhost:3000/api/v1/upload/stream",
            {
              method: "POST",

              body: formData,
            }
          );
          console.log(response);
          if (!response.ok || !response.body) {
            throw response.statusText;
          }
          const reader = response.body.getReader();
          const decoder = new TextDecoder("utf-8");

          const readChunk = () => {
            reader
              .read()
              .then(({ value, done }) => {
                if (done) {
                  console.log("Stream finished");
                  return;
                }

                const chunkString = decoder.decode(value);
                setData((prevMessages) => prevMessages + chunkString);
                readChunk();
              })
              .catch((error) => {
                console.error(error);
              });
          };

          readChunk();
        } catch (error) {
          console.error("Error fetching repos:", error);
        }
      };
      fetchRepos();

api/v1/codeReview

You need to provide the code in the request body, and optionally a guideline file. The response will be an array of JSON objects containing criteria and reviews based on them.

exemple of request:

// Fetch API POST request
const criterias = ["Code Structure", "Error Handling", "Performance"];

fetch("http://example.com/api/v1/codeReview", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({code: requestData, criterias})
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error("Error:", error));

api/v1/codeReview/stream

Same as the previous route, generating a single streamed response for a criteria. The difference is in the response format being a stream.

exemple of request:

const formData = new FormData();
const criterias = ["Code Structure"];
formData.append("file", file);
formData.append("criterias", criterias)
formData.append("code", code)

const fetchCodeReviewStream = async () => {
  try {
    const response = await fetch(
      "http://localhost:3000/api/v1/codeReview/stream",
      {
        method: "POST",
        body: formData,
      }
    );

    console.log(response);

    if (!response.ok || !response.body) {
      throw response.statusText;
    }

    const reader = response.body.getReader();
    const decoder = new TextDecoder("utf-8");

    const readChunk = () => {
      reader
        .read()
        .then(({ value, done }) => {
          if (done) {
            console.log("Stream finished");
            return;
          }

          const chunkString = decoder.decode(value);
          // Handle the streamed data as needed
          console.log(chunkString);
          readChunk();
        })
        .catch((error) => {
          console.error(error);
        });
    };

    readChunk();
  } catch (error) {
    console.error("Error fetching code review:", error);
  }
};

fetchCodeReviewStream();

Getting Started

To get started with the Rev Dev Code Review backend, follow these steps:

  1. Clone the repository.
  2. Install dependencies using npm install.
  3. Run the backend server using npm start.
  4. The server will be running on http://localhost:3000 by default.

Usage

Uploading Code

To upload code for review, use either api/v1/upload or api/v1/upload/stream. Provide your code, select criteria, and optionally upload a guideline file. Check the response for a detailed review based on the specified criteria.

Code Review

For code review without file uploads, use api/v1/codeReview or api/v1/codeReview/stream. Provide your code in the request body and an optional guideline file. Receive a detailed review based on the specified criteria.

Response Format

The response format for both uploading code and code review routes will be an array of JSON objects. Each object contains criteria and corresponding reviews.

[
    {
        "criteria": "Code Structure",
        "review": "Good structure, follows best practices."
    },
    {
        "criteria": "Error Handling",
        "review": "Could improve error handling in specific areas."
    },
]

Built With

Share this project:

Updates