BugTrace-AI - Developer Documentation

Version: 0.1.1 Beta

1. Project Architecture & Build Process

This project is a modern single-page application (SPA) built with React, TypeScript, and Vite. This stack provides a fast, modern development experience and a highly optimized production build.

Local Development (Vite)

During local development (using npm run dev), the application is served by the Vite development server. Vite leverages the browser's native ES Modules (ESM) support to serve source files on demand. This provides:

Production Build (Docker)

For production, the application is bundled and optimized using Vite's build process (npm run build). The Dockerfile.txt orchestrates this using a robust multi-stage build:

  1. Stage 1 ('builder'): A Node.js environment is used to install all dependencies (npm install) and run the production build script (npm run build). This transpiles all TypeScript, bundles the application into highly optimized static JavaScript and CSS files, and places them in a /dist directory.
  2. Stage 2 (Nginx): A lightweight Nginx web server image is used. Only the optimized /dist directory from Stage 1 is copied into the server's public directory.

This multi-stage approach results in a small, secure, and performant final Docker image that contains only the static files needed to run the application, with no source code or build tools included.

2. State Management

The application employs a pragmatic, tiered approach to state management without external libraries like Redux.

3. AI Services & Prompt Engineering

The services/ directory contains the most critical pieces of application logic. It is the sole interface between the frontend UI and the generative AI models, abstracting all API complexity away from the React components.

The Service Layer (Service.ts)

This file acts as a facade for all AI interactions. No React component should ever call fetch directly. Instead, they call a function from Service.ts (e.g., analyzeUrl, forgePayloads). This centralizes logic and makes the application easier to maintain and debug.

Prompt Engineering (services/prompts/)

The effectiveness of the entire application hinges on high-quality prompt engineering. All prompts are modularized and stored in the prompts directory. This separation of concerns allows for easy tuning of the AI's behavior without altering the core application logic.

Reliability Through Recursion

Generative AI can be non-deterministic. To improve reliability, key analysis functions (like DAST and SAST) use a recursive, multi-attempt strategy. The UI asks for an "Analysis Depth" (e.g., 3), and the service layer then calls the AI 3 times, each with a slightly different prompt variation. The results are then passed to a final "consolidation" prompt, where the AI is asked to merge and de-duplicate the findings into a single, high-quality report. This significantly reduces false negatives and improves consistency.

API Resilience (utils/apiManager.ts)

To ensure the application is robust and doesn't abuse the API, a centralized manager handles all requests. It implements:

4. Core Feature Deep Dive

Each tool's effectiveness relies on its unique prompt engineering methodology.

5. Styling Philosophy

The application uses a hybrid approach for a consistent and maintainable "hacker" aesthetic.

6. Deployment & Setup

The application is designed for easy deployment using Docker. This method correctly runs the Vite build process and configures an Nginx web server to serve the resulting static files.

Instructions:

  1. Make the Script Executable: In your terminal, run:
    chmod +x dockerizer.sh.txt (and rename it to dockerizer.sh).
  2. Run the Script: Now, execute the script to build and run the container:
    ./dockerizer.sh

The script will build the Docker image and launch the container. You can then access the application at http://localhost:6869.

7. Open Source Contributions

This project is open-source and contributions are welcome. To ensure a smooth and secure development process, please be aware of the following files:

LICENSE

The project is licensed under the MIT License. This is a permissive license that allows for broad use, modification, and distribution, both in open-source and proprietary projects, provided the original copyright and license notice are included.

8. Detailed File Structure

A brief overview of the key files and directories in the project.

9. Development Workflow

To make a change, simply edit the relevant .tsx or .ts file. The Vite development server (started with npm run dev) will automatically update the browser with your changes, often without a full page reload, thanks to Hot Module Replacement (HMR).