Skip to content
fatimarajab12Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

QBrain - AI-Powered SRS Analysis & Test Case Generation Platform

QBrain Logo Version License

An intelligent platform for analyzing SRS documents and automatically extracting features and generating test cases using AI

Features β€’ Tech Stack β€’ Architecture β€’ AI & RAG β€’ Installation β€’ Usage β€’ Documentation

Node.js React TypeScript MongoDB OpenAI


πŸ“‹ Table of Contents

  1. Overview
  2. Features
  3. Tech Stack
  4. Architecture
  5. How RAG System Works
  6. Installation
  7. Usage
  8. Documentation
  9. Performance Metrics
  10. Security
  11. Testing
  12. Contributing
  13. License

🎯 Overview

QBrain is an intelligent platform that leverages RAG (Retrieval Augmented Generation) and AI technologies to analyze SRS (Software Requirements Specification) documents and automatically extract features and generate test cases.

Problem Statement

  • Manual SRS analysis is time-consuming and error-prone
  • Feature extraction from SRS documents is complex and expensive
  • Manual test case creation is slow and inconsistent
  • Tracking coverage and maintaining consistency is challenging

Solution

  • βœ… Automated SRS analysis using AI
  • βœ… Automatic feature extraction with intelligent classification
  • βœ… AI-powered test case generation based on features
  • βœ… Comprehensive coverage analysis and section tracking
  • βœ… Smart chatbot for answering SRS-related questions

✨ Features

πŸ€– AI-Powered Capabilities

  • βœ… Automatic Feature Extraction from SRS using GPT-4o-mini
  • βœ… Comprehensive RAG System with 8 parallel queries for complete coverage
  • βœ… Intelligent Test Case Generation based on feature types (FUNCTIONAL, DATA, REPORT, etc.)
  • βœ… Section Coverage Analysis to ensure completeness
  • βœ… Smart Chatbot for answering SRS-related questions with context-aware responses
  • βœ… Automatic Gherkin Conversion with AI or rule-based fallback
  • βœ… Section Matching for feature-to-SRS section correlation

πŸ“Š Project Management

  • βœ… Multi-Project Support with isolated workspaces
  • βœ… Feature Tracking with metadata, scores, and reasoning
  • βœ… Test Case Management with Gherkin conversion
  • βœ… Bug Tracking and issue management
  • βœ… Performance Metrics and analytics
  • βœ… Section Coverage Visualization

πŸ” Advanced RAG System

  • βœ… Semantic Search using OpenAI embeddings (text-embedding-3-small)
  • βœ… Multi-Query Retrieval (8 specialized queries covering all feature types)
  • βœ… Section-Based Organization of context chunks
  • βœ… Adaptive Prompting based on feature types and high-recall mode
  • βœ… Vector Storage in Supabase with pgvector for fast similarity search

🎨 Modern User Interface

  • βœ… React 18 with TypeScript for type safety
  • βœ… Tailwind CSS + shadcn/ui components for beautiful UI
  • βœ… Fully Responsive design for all devices
  • βœ… Dark Mode support
  • βœ… Real-time Updates with TanStack Query
  • βœ… Modern Animations with Framer Motion

πŸ“„ Document Processing

  • βœ… PDF & TXT Support for SRS documents
  • βœ… Google Document AI integration for high-quality extraction with OCR support
  • βœ… Intelligent Chunking (2000 chars with 300 overlap) for context preservation
  • βœ… Batch Embedding Generation for cost efficiency
  • βœ… Automatic PDF Splitting for large documents (>15 pages)

πŸ› οΈ Tech Stack

Backend

Technology Purpose Version
Node.js Runtime environment >= 18.0.0
Express.js Web framework 5.1.0
MongoDB Primary database (Projects, Features, Test Cases, Bugs) 8.20.1
Mongoose ODM for MongoDB 8.20.1
JWT Authentication & authorization 9.0.2
bcryptjs Password hashing 3.0.3
Multer File upload handling 2.0.2
Brevo/Nodemailer Email service 3.0.1 / 7.0.10

AI & Machine Learning

Technology Purpose
LangChain LLM framework & chain orchestration
OpenAI API GPT-4o-mini (analysis), text-embedding-3-small (embeddings)
Supabase Vector database (PostgreSQL + pgvector extension)
RAG Pattern Retrieval Augmented Generation for context-aware responses

Frontend

Technology Purpose
React 18 UI library
TypeScript Type safety
Vite Build tool & dev server
Tailwind CSS Utility-first CSS framework
shadcn/ui High-quality UI components
React Router Client-side routing
TanStack Query Data fetching & caching
React Hook Form Form state management
Zod Schema validation

Document Processing

Technology Purpose
Google Document AI Advanced PDF text extraction with OCR
pdf-parse PDF parsing fallback
pdf-lib PDF manipulation for splitting
RecursiveCharacterTextSplitter Intelligent text chunking

πŸ—οΈ Architecture

Project Structure

QBrain/
β”œβ”€β”€ backend/                           # Backend Server (Node.js/Express)
β”‚   β”œβ”€β”€ ai/                            # AI & RAG Services
β”‚   β”‚   β”œβ”€β”€ chatbot/                   # Chatbot functionality
β”‚   β”‚   β”‚   β”œβ”€β”€ index.js               # Main chatbot export
β”‚   β”‚   β”‚   β”œβ”€β”€ prompts.js             # Chatbot prompts
β”‚   β”‚   β”‚   β”œβ”€β”€ query.js               # Chatbot query handler
β”‚   β”‚   β”‚   └── utils.js               # Chatbot utilities
β”‚   β”‚   β”œβ”€β”€ config/                    # Configuration
β”‚   β”‚   β”‚   β”œβ”€β”€ llmClient.js           # LLM client factory
β”‚   β”‚   β”‚   β”œβ”€β”€ models.config.js       # Model configurations
β”‚   β”‚   β”‚   └── constants.js           # 8 comprehensive SRS queries
β”‚   β”‚   β”œβ”€β”€ ingestion/                 # Document processing
β”‚   β”‚   β”‚   β”œβ”€β”€ documentParser.js      # PDF/TXT parsing 
β”‚   β”‚   β”‚   └── embeddings.js          # Embedding generation (OpenAI)
β”‚   β”‚   β”œβ”€β”€ retrieval/                 # Context retrieval
β”‚   β”‚   β”‚   β”œβ”€β”€ retrievalCore.js       # RAG context retrieval
β”‚   β”‚   β”‚   β”œβ”€β”€ retrievalStrategies.js # Retrieval strategies
β”‚   β”‚   β”‚   └── sectionsCore.js        # Section grouping & analysis
β”‚   β”‚   β”œβ”€β”€ reasoning/                 # AI reasoning & analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ featureExtraction.js   # Feature extraction logic
β”‚   β”‚   β”‚   β”œβ”€β”€ testCaseGeneration.js  # Test case generation
β”‚   β”‚   β”‚   β”œβ”€β”€ gherkinConversion.js   # Gherkin format conversion
β”‚   β”‚   β”‚   β”œβ”€β”€ sectionMatching.js     # Section matching logic
β”‚   β”‚   β”‚   β”œβ”€β”€ jsonUtils.js           # JSON parsing utilities
β”‚   β”‚   β”‚   └── prompts/               # Prompt templates
β”‚   β”‚   β”‚       └── index.js           # Prompt exports
β”‚   β”‚   └── rag/                       # Unified entry point
β”‚   β”‚       β”œβ”€β”€ index.js               # Export all functions
β”‚   β”‚       └── query.js               # RAG query handler (Chatbot)
β”‚   β”œβ”€β”€ config/                        # Configuration files
β”‚   β”‚   β”œβ”€β”€ database.js                # MongoDB connection
β”‚   β”‚   └── nodemailer.config.js       # Email service configuration
β”‚   β”œβ”€β”€ controllers/                   # Route controllers
β”‚   β”‚   β”œβ”€β”€ admin.controller.js        # Admin operations
β”‚   β”‚   β”œβ”€β”€ aiController.js            # AI feature extraction & test generation
β”‚   β”‚   β”œβ”€β”€ auth.controller.js         # Authentication (login, signup, reset)
β”‚   β”‚   β”œβ”€β”€ bugsController.js          # Bug CRUD operations
β”‚   β”‚   β”œβ”€β”€ chatbotController.js       # Chatbot endpoints
β”‚   β”‚   β”œβ”€β”€ featuresController.js      # Feature CRUD operations
β”‚   β”‚   β”œβ”€β”€ projectsController.js      # Project CRUD operations
β”‚   β”‚   └── testCasesController.js     # Test case CRUD operations
β”‚   β”œβ”€β”€ models/                        # MongoDB schemas
β”‚   β”‚   β”œβ”€β”€ ApiRequestMetric.js        # API usage metrics
β”‚   β”‚   β”œβ”€β”€ Bug.js                     # Bug model
β”‚   β”‚   β”œβ”€β”€ DailyActiveUser.js         # Daily active users tracking
β”‚   β”‚   β”œβ”€β”€ Feature.js                 # Feature model
β”‚   β”‚   β”œβ”€β”€ PerformanceMetric.js       # Performance metrics
β”‚   β”‚   β”œβ”€β”€ Project.js                 # Project model
β”‚   β”‚   β”œβ”€β”€ TestCase.js                # Test case model
β”‚   β”‚   └── User.js                    # User model
β”‚   β”œβ”€β”€ routes/                        # API route definitions
β”‚   β”‚   β”œβ”€β”€ admin.routes.js            # Admin routes
β”‚   β”‚   β”œβ”€β”€ ai.routes.js               # AI routes (feature extraction, test generation)
β”‚   β”‚   β”œβ”€β”€ auth.routes.js             # Authentication routes
β”‚   β”‚   β”œβ”€β”€ bugs.routes.js             # Bug routes
β”‚   β”‚   β”œβ”€β”€ chatbot.routes.js          # Chatbot routes
β”‚   β”‚   β”œβ”€β”€ features.routes.js         # Feature routes
β”‚   β”‚   β”œβ”€β”€ projects.routes.js         # Project routes
β”‚   β”‚   └── testCases.routes.js        # Test case routes
β”‚   β”œβ”€β”€ services/                      # Business logic layer
β”‚   β”‚   β”œβ”€β”€ bugService.js              # Bug business logic
β”‚   β”‚   β”œβ”€β”€ documentProcessingValidator.js # Document validation
β”‚   β”‚   β”œβ”€β”€ featureService.js          # Feature business logic
β”‚   β”‚   β”œβ”€β”€ performanceMetricsService.js # Performance tracking
β”‚   β”‚   β”œβ”€β”€ projectService.js          # Project business logic
β”‚   β”‚   └── testCaseService.js         # Test case business logic
β”‚   β”œβ”€β”€ middleware/                    # Express middleware
β”‚   β”‚   β”œβ”€β”€ auth.middleware.js         # JWT authentication
β”‚   β”‚   β”œβ”€β”€ errorHandler.middleware.js # Error handling
β”‚   β”‚   └── usageMetrics.middleware.js # Usage tracking
β”‚   β”œβ”€β”€ utils/                         # Helper utilities
β”‚   β”‚   β”œβ”€β”€ AppError.js                # Custom error class
β”‚   β”‚   β”œβ”€β”€ emailService.js            # Email sending utilities
β”‚   β”‚   β”œβ”€β”€ emailTemplates.js          # Email templates
β”‚   β”‚   └── textProcessing.js          # Text processing helpers
β”‚   β”œβ”€β”€ vector/                        # Vector store integration
β”‚   β”‚   └── vectorStore.js             # Supabase vector store wrapper
β”‚   β”œβ”€β”€ test/                          # Test files
β”‚   β”‚   β”œβ”€β”€ data/                      # Test data
β”‚   β”‚   └── unit/                      # Unit tests
β”‚   β”‚       β”œβ”€β”€ fixtures/              # Test fixtures
β”‚   β”‚       β”‚   β”œβ”€β”€ chunks.js
β”‚   β”‚       β”‚   β”œβ”€β”€ factories.js
β”‚   β”‚       β”‚   β”œβ”€β”€ index.js
β”‚   β”‚       β”‚   β”œβ”€β”€ llm.js
β”‚   β”‚       β”‚   └── testCase.js
β”‚   β”‚       β”œβ”€β”€ helpers/               # Test helpers
β”‚   β”‚       β”‚   └── console.js
β”‚   β”‚       β”œβ”€β”€ reasoning/             # Reasoning tests
β”‚   β”‚       β”‚   β”œβ”€β”€ featureExtraction.test.js
β”‚   β”‚       β”‚   β”œβ”€β”€ gherkinConversion.test.js
β”‚   β”‚       β”‚   └── testCaseGeneration.test.js
β”‚   β”‚       β”œβ”€β”€ retrieval/             # Retrieval tests
β”‚   β”‚       β”‚   β”œβ”€β”€ retrievalCore.test.js
β”‚   β”‚       β”‚   └── sectionsCore.test.js
β”‚   β”‚       └── utils/                 # Utils tests
β”‚   β”‚           β”œβ”€β”€ jsonUtils.test.js
β”‚   β”‚           └── textProcessing.test.js
β”‚   β”œβ”€β”€ scripts/                       # Utility scripts
β”‚   β”‚   └── promote-admin.js           # Admin promotion script
β”‚   β”œβ”€β”€ uploads/                       # Uploaded files directory
β”‚   β”œβ”€β”€ logs/                          # Application logs
β”‚   β”œβ”€β”€ server.js                      # Express server entry point
β”‚   β”œβ”€β”€ package.json                   # Backend dependencies
β”‚   └── jest.config.mjs                # Jest configuration
β”‚
β”œβ”€β”€ frontend/                          # React Frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/                # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ ui/                    # shadcn/ui components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ accordion.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ alert-dialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ alert.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ avatar.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ badge.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ button.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ card.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ checkbox.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ collapsible.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ dialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ dropdown-menu.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ form.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ input.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ label.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ loading-button.tsx      # Custom loading button
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ loading-spinner.tsx     # Custom loading spinner
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ page-loading.tsx        # Page loading component
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ progress.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ scroll-area.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ select.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ separator.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ skeleton.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ table.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ tabs.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ textarea.tsx
β”‚   β”‚   β”‚   β”‚   └── ... (more shadcn/ui components)
β”‚   β”‚   β”‚   β”œβ”€β”€ custom/                 # Custom components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DotGrid.tsx        # Background grid component
β”‚   β”‚   β”‚   β”‚   └── Orb.tsx            # Orb animation component
β”‚   β”‚   β”‚   β”œβ”€β”€ ProjectChatBot/        # Chatbot component
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatButton.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatHeader.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatInput.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatWindow.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   └── MessageList.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useChatApi.ts
β”‚   β”‚   β”‚   β”‚   β”‚   └── useChatMessages.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ constants.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ index.tsx
β”‚   β”‚   β”‚   β”‚   └── types.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ shared/                # Shared components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PrefetchLink.tsx
β”‚   β”‚   β”‚   β”‚   └── SuspenseFallback.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminRoute.tsx         # Admin route protection
β”‚   β”‚   β”‚   β”œβ”€β”€ AppSidebar.tsx         # Main sidebar navigation
β”‚   β”‚   β”‚   β”œβ”€β”€ ErrorBoundary.tsx      # Error boundary component
β”‚   β”‚   β”‚   β”œβ”€β”€ ErrorBoundaryNavigation.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Logo.tsx               # Application logo
β”‚   β”‚   β”‚   └── icons/                 # Icon components
β”‚   β”‚   β”œβ”€β”€ pages/                     # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ admin-dashboard/       # Admin dashboard
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AdminHeader.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ DeleteUserDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoadingState.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ OverviewTab.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ StatsCards.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ SystemHealthTab.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ UserFilters.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ UserManagementTab.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   └── UserTable.tsx
β”‚   β”‚   β”‚   β”‚   └── hooks/
β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ useAdminData.ts
β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ useUserActions.ts
β”‚   β”‚   β”‚   β”‚       β”œβ”€β”€ useUserFilters.ts
β”‚   β”‚   β”‚   β”‚       └── useUserSelection.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminDashboard.tsx     # Admin dashboard page
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/                  # Authentication pages
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AuthLayout.tsx     # Auth layout wrapper
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ForgotPassword.tsx # Password reset request
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Login.tsx          # Login page
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ResetPassword.tsx  # Password reset
β”‚   β”‚   β”‚   β”‚   └── Signup.tsx         # Registration page
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthPage.tsx           # Auth page wrapper
β”‚   β”‚   β”‚   β”œβ”€β”€ bug-details/           # Bug details page
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugAttachments.tsx      # Bug file attachments
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugBadges.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugBasicInfo.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugDeleteDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugEnvironment.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugExpectedActual.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugHeader.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugLabels.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugPeople.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugResolution.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugStepsToReproduce.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugTimeline.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ErrorState.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   └── LoadingState.tsx
β”‚   β”‚   β”œβ”€β”€ BugDetails.tsx             # Bug details page
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatPage.tsx           # Chat page
β”‚   β”‚   β”‚   β”œβ”€β”€ dashboard/             # Dashboard components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CreateProjectDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EmptyState.tsx
β”‚   β”‚   β”‚   β”‚   └── ProjectCard.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx          # Main dashboard page
β”‚   β”‚   β”‚   β”œβ”€β”€ feature-details/       # Feature details page
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureAcceptanceCriteria.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureHeader.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureHeaderBack.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureInfoCard.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeaturePrioritySelector.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureTabs.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureTechnicalDetails.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoadingState.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ TestCasesContent.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   └── TestCasesToolbar.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useFeatureBugs.ts
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useFeatureData.ts
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useFeatureDetailsState.ts
β”‚   β”‚   β”‚   β”‚   β”‚   └── useTestCaseFilters.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AITestCaseGenerationDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugsTab.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CreateTestCaseDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EditTestCaseDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ StatsGrid.tsx
β”‚   β”‚   β”‚   β”‚   └── TestCaseCard.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureDetails.tsx     # Feature details page
β”‚   β”‚   β”‚   β”œβ”€β”€ Index.tsx              # Landing page
β”‚   β”‚   β”‚   β”œβ”€β”€ NotFound.tsx           # 404 page
β”‚   β”‚   β”‚   β”œβ”€β”€ profile/               # Profile page components
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AccountInfoCard.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PersonalInfoTab.tsx
β”‚   β”‚   β”‚   β”‚   └── UserAvatarCard.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Profile.tsx            # User profile page
β”‚   β”‚   β”‚   β”œβ”€β”€ project-details/       # Project details page
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeaturesContent.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeaturesToolbar.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoadingState.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ProjectHeader.tsx
β”‚   β”‚   β”‚   β”‚   β”‚   └── ProjectTabs.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useBugHandlers.ts
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useFeatureFilters.ts
β”‚   β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ useFeatureFiltersState.ts
β”‚   β”‚   β”‚   β”‚   β”‚   └── useProjectData.ts
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ AIGenerationDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ BugTab.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CreateBugDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ CreateFeatureDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EditBugDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EditFeatureDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ EmptyState.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeatureCard.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ FeaturesTable.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ShareProjectDialog.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ StatusDropdown.tsx
β”‚   β”‚   β”‚   β”‚   └── TestCasesPage.tsx
β”‚   β”‚   β”‚   └── ProjectDetails.tsx     # Project details page
β”‚   β”‚   β”œβ”€β”€ services/                  # API service layer
β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts                 # Base API configuration & interceptors
β”‚   β”‚   β”‚   β”œβ”€β”€ api.test.ts            # API tests
β”‚   β”‚   β”‚   β”œβ”€β”€ admin.service.ts       # Admin API calls
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.service.ts        # Authentication API calls
β”‚   β”‚   β”‚   β”œβ”€β”€ bug.service.ts         # Bug API calls
β”‚   β”‚   β”‚   β”œβ”€β”€ feature.service.ts     # Feature API calls
β”‚   β”‚   β”‚   β”œβ”€β”€ project.service.ts     # Project API calls
β”‚   β”‚   β”‚   β”œβ”€β”€ test-case.service.ts   # Test case API calls
β”‚   β”‚   β”‚   └── user.service.ts        # User API calls
β”‚   β”‚   β”œβ”€β”€ hooks/                     # Custom React hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ use-auth.ts            # Authentication hook
β”‚   β”‚   β”‚   β”œβ”€β”€ use-mobile.tsx         # Mobile detection hook
β”‚   β”‚   β”‚   β”œβ”€β”€ use-toast.ts           # Toast notifications hook
β”‚   β”‚   β”‚   β”œβ”€β”€ useBug.ts              # Single bug hook
β”‚   β”‚   β”‚   β”œβ”€β”€ useBugs.ts             # Bugs management hook
β”‚   β”‚   β”‚   β”œβ”€β”€ useFeatures.ts         # Features management hook
β”‚   β”‚   β”‚   β”œβ”€β”€ useNavigation.ts       # Navigation utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ useProjects.ts         # Projects management hook
β”‚   β”‚   β”‚   β”œβ”€β”€ useProjectTestCases.ts # Project-level test cases hook
β”‚   β”‚   β”‚   β”œβ”€β”€ useTestCases.ts        # Test cases management hook
β”‚   β”‚   β”‚   └── useUserProfile.ts      # User profile hook
β”‚   β”‚   β”œβ”€β”€ types/                     # TypeScript type definitions
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.ts                # Authentication types
β”‚   β”‚   β”‚   β”œβ”€β”€ bug.ts                 # Bug types
β”‚   β”‚   β”‚   β”œβ”€β”€ feature.ts             # Feature types
β”‚   β”‚   β”‚   β”œβ”€β”€ project.ts             # Project types
β”‚   β”‚   β”‚   β”œβ”€β”€ test-case.ts           # Test case types
β”‚   β”‚   β”‚   └── user.ts                # User types
β”‚   β”‚   β”œβ”€β”€ utils/                     # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ admin-helpers.ts       # Admin utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ array-helpers.ts       # Array manipulation
β”‚   β”‚   β”‚   β”œβ”€β”€ auth-helpers.ts        # Auth utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ bug-helpers.tsx        # Bug utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ feature-helpers.ts     # Feature utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ logger.ts              # Logging utilities
β”‚   β”‚   β”‚   β”œβ”€β”€ navigation.ts          # Navigation helpers
β”‚   β”‚   β”‚   β”œβ”€β”€ test-case-helpers.ts   # Test case utilities
β”‚   β”‚   β”‚   └── user-helpers.ts        # User utilities
β”‚   β”‚   β”œβ”€β”€ config/                    # Configuration files
β”‚   β”‚   β”‚   └── routes.tsx             # Route definitions
β”‚   β”‚   β”œβ”€β”€ layouts/                   # Layout components
β”‚   β”‚   β”‚   └── AppLayout.tsx          # Main application layout
β”‚   β”‚   β”œβ”€β”€ lib/                       # Library utilities
β”‚   β”‚   β”‚   └── utils.ts               # General utility functions (cn, etc.)
β”‚   β”‚   β”œβ”€β”€ App.tsx                    # Root App component
β”‚   β”‚   β”œβ”€β”€ main.tsx                   # Application entry point
β”‚   β”‚   β”œβ”€β”€ index.css                  # Global styles
β”‚   β”‚   └── vite-env.d.ts             # Vite type definitions
β”‚   β”œβ”€β”€ public/                        # Static assets
β”‚   β”œβ”€β”€ package.json                   # Frontend dependencies
β”‚   └── vite.config.ts                 # Vite configuration
β”‚
└── supabase_vector_migration.sql      # Supabase vector database schema

System Architecture Layers

The QBrain system is built on 4 core layers that work together to provide intelligent SRS analysis:

1. Ingestion Layer (backend/ai/ingestion/)

  • Purpose: Process and prepare documents for AI analysis
  • Components:
    • documentParser.js: Extract text from PDF/TXT files (Google Document AI or pdf-parse)
    • embeddings.js: Convert text chunks to vector embeddings (OpenAI text-embedding-3-small)
  • Output: Vector embeddings stored in Supabase

2. Retrieval Layer (backend/ai/retrieval/)

  • Purpose: Find relevant context from SRS documents
  • Components:
    • retrievalCore.js: Execute 8 parallel semantic searches
    • sectionsCore.js: Group chunks by SRS sections, analyze coverage
    • retrievalStrategies.js: Advanced retrieval strategies
  • Output: Ranked, weighted context chunks organized by sections

3. Reasoning Layer (backend/ai/reasoning/)

  • Purpose: AI-powered analysis and generation
  • Components:
    • featureExtraction.js: Extract features from SRS using RAG
    • testCaseGeneration.js: Generate test cases for features
    • gherkinConversion.js: Convert test cases to Gherkin format
    • sectionMatching.js: Match features to SRS sections
    • jsonUtils.js: Parse and validate LLM JSON responses
  • Output: Structured features and test cases with metadata

4. Config Layer (backend/ai/config/)

  • Purpose: Centralized AI configuration
  • Components:
    • llmClient.js: LLM client factory (OpenAI, etc.)
    • models.config.js: Model configurations (GPT-4o-mini, embeddings)
    • constants.js: 8 comprehensive SRS queries with weights
  • Output: Configured AI clients ready for use

πŸ€– How RAG System Works

πŸ“š Overview

QBrain uses RAG (Retrieval Augmented Generation) - a sophisticated AI architecture that combines vector search with LLM reasoning to provide accurate, context-aware responses based on your project's SRS documents.

Instead of relying solely on LLM knowledge, the system retrieves relevant information from your project's SRS documents, augments the prompt with this context, and generates responses using LLM based on the retrieved context.

πŸ”„ Basic RAG Workflow

User Query/Request
    ↓
1. Query Expansion (expand related terms)
   β”‚   Add synonyms and related terms for better retrieval
    ↓
2. Generate Query Embedding (text-embedding-3-small)
   β”‚   Convert query text to 1536-dimensional vector
    ↓
3. Vector Similarity Search (Supabase + pgvector)
   β”‚   Semantic search in vector database
   β”‚   Using cosine similarity to find similar chunks
    ↓
4. Retrieve Top K Relevant Chunks
   β”‚   Get the most relevant text chunks from SRS
    ↓
5. Weight & Rank Chunks (by category, priority, relevance)
   β”‚   Apply category weights and prioritize important chunks
    ↓
6. Build Context from Retrieved Chunks
   β”‚   Combine chunks into coherent context string
    ↓
7. Create Adaptive Prompt (context + instructions)
   β”‚   Build prompt with context and task instructions
    ↓
8. Send to LLM (GPT-4o-mini with dynamic temperature)
   β”‚   Generate response using AI model
    ↓
9. Generate & Return Response
   β”‚   Return final answer to user

πŸ” Detailed RAG Architecture

1️⃣ Document Ingestion Layer

πŸ“„ SRS Document Upload
    ↓
πŸ“– Text Extraction
   - Google Document AI (OCR support)
   - OR pdf-parse (fallback)
    ↓
βœ‚οΈ Intelligent Chunking
   - Size: 2000 characters
   - Overlap: 300 characters (preserve context)
   - Method: RecursiveCharacterTextSplitter
    ↓
πŸ”’ Embedding Generation
   - Model: text-embedding-3-small
   - Dimensions: 1536
   - Normalization: Yes (better similarity)
   - Batch processing for efficiency
    ↓
πŸ’Ύ Vector Storage (Supabase + pgvector)
   - Table: project_vectors
   - Index: IVFFlat (fast similarity search)
   - Metadata: projectId, sectionId, etc.

Key Files:

  • backend/ai/ingestion/documentParser.js - PDF/TXT parsing
  • backend/ai/ingestion/embeddings.js - Embedding generation
  • backend/vector/vectorStore.js - Vector database operations

2️⃣ Comprehensive Retrieval System

The Magic of 8 Parallel Queries:

Instead of a single search query, QBrain uses 8 specialized parallel queries that target different semantic areas of the SRS document to ensure comprehensive coverage and maximum feature discovery:

COMPREHENSIVE_SRS_QUERIES = [
  {
    query: "functional requirement feature shall must system behavior use case",
    category: "FUNCTIONAL",
    weight: 1.0  // Highest priority
  },
  {
    query: "workflow process step procedure lifecycle state transition",
    category: "WORKFLOW",
    weight: 0.9
  },
  {
    query: "interface user interface UI API integration",
    category: "INTERFACE",
    weight: 0.8
  },
  {
    query: "quality performance security usability reliability",
    category: "QUALITY",
    weight: 0.8
  },
  {
    query: "constraint assumption dependency limitation restriction rule",
    category: "CONSTRAINT",
    weight: 0.5  // Lower priority
  },
  {
    query: "data dictionary field table column attribute",
    category: "DATA",
    weight: 0.7
  },
  {
    query: "report document format output statement",
    category: "REPORT",
    weight: 0.5
  },
  {
    query: "notification alert message communication email SMS",
    category: "NOTIFICATION",
    weight: 0.85
  }
]

Retrieval Process:

1. Execute 8 Queries in PARALLEL (Promise.all)
   β”‚   All queries run simultaneously for maximum efficiency
    ↓
2. For Each Query:
   - Expand query terms (add synonyms)
   - Convert to embedding vector
   - Search vector store (cosine similarity)
   - Retrieve top K chunks (default: 5-7 per query)
   - Enrich with category & weight metadata
    ↓
3. Merge All Results (8 queries Γ— 5 chunks = 40 chunks)
   β”‚   Combine all retrieved chunks from all queries
    ↓
4. Deduplication
   - Hash by first 100 characters
   - Remove duplicate chunks
   - Keep highest relevance version
    ↓
5. Category-Based Weighting
   - FUNCTIONAL: weight 1.0 (highest priority)
   - WORKFLOW: weight 0.9
   - NOTIFICATION: weight 0.85
   - INTERFACE/QUALITY: weight 0.8
   - DATA: weight 0.7
   - CONSTRAINT/REPORT: weight 0.5 (lower priority)
    ↓
6. Sort by Adjusted Relevance
   adjustedRelevance = baseRelevance Γ— categoryWeight
    ↓
7. Group by SRS Sections
   - Extract section numbers (e.g., "3.2.1")
   - Group chunks by section
   - Track section coverage

Why 8 Queries?

  • Better Coverage: Single query might miss important information
  • Semantic Diversity: Each query targets different aspect
  • Weighted Results: Priority-based ranking (FUNCTIONAL > CONSTRAINT)
  • Section Awareness: Maintains document structure

Key Files:

  • backend/ai/retrieval/retrievalCore.js - Core retrieval logic
  • backend/ai/config/constants.js - 8 query definitions
  • backend/ai/retrieval/sectionsCore.js - Section grouping

3️⃣ Feature Extraction Workflow

1. Upload SRS Document
   β”‚   User uploads PDF or TXT file
    ↓
2. Process Document (Ingestion Layer)
   β”‚   Extract text, chunk, and generate embeddings
    ↓
3. Comprehensive Retrieval (8 parallel queries)
   β”‚   Execute 8 specialized queries simultaneously
   - Gets 40+ chunks (5 per query)
   - Deduplicates to ~25-30 unique chunks
    ↓
4. Group Chunks by SRS Sections
   β”‚   Organize chunks by document structure
   - Extract section numbers: "3.2.1", "4.5.2", etc.
   - Create section-based context
    ↓
5. Build Context String
   β”‚   Format chunks into structured context
   Format:
   [Section 3.2.1]
   chunk text...
   
   [Section 4.5.2]
   chunk text...
   
   [Other Content]
   ungrouped chunks...
    ↓
6. Create Adaptive Prompt (High-Recall Mode)
   β”‚   Build prompt optimized for comprehensive extraction
   - Instructions for comprehensive extraction
   - JSON output format
   - Feature type classification
   - Acceptance criteria generation
    ↓
7. Call LLM (GPT-4o-mini, temperature: 0.3)
   β”‚   Generate features using AI
   - Low temperature for consistent extraction
   - JSON mode for structured output
    ↓
8. Parse JSON Response
   β”‚   Extract and validate feature data
   - Extract features array
   - Validate structure
    ↓
9. Enhance Features
   β”‚   Add metadata and scores to features
   - Match chunks to features (keyword matching)
   - Calculate relevance scores
   - Extract matched sections
   - Generate reasoning text
   - Calculate ranking scores
    ↓
10. Clean & Deduplicate
    β”‚   Remove duplicates and filter low-quality features
    - Remove duplicates (normalize names)
    - Filter low-quality features
    - Aggregate data fields into data models
    - Remove infrastructure-only features
    ↓
11. Section Coverage Analysis
    β”‚   Analyze which SRS sections were covered
    - Calculate coverage percentage
    - Identify missing sections
    - Generate recommendations
    ↓
12. Save to MongoDB
    β”‚   Persist features to database

Key Files:

  • backend/ai/reasoning/featureExtraction.js - Main extraction logic
  • backend/ai/reasoning/prompts/index.js - Prompt templates

4️⃣ Test Case Generation Workflow

1. Select Feature
   β”‚   User selects a feature to generate tests for
    ↓
2. Context Retrieval Strategy
   β”‚   Choose optimal retrieval method based on feature
   
   IF feature has matchedSections:
      β†’ Retrieve from specific sections (section-aware)
   ELSE IF useComprehensiveRetrieval:
      β†’ Use 8-query comprehensive retrieval
   ELSE:
      β†’ Query by feature description
    ↓
3. Feature-Type-Specific Prompt
   β”‚   Create prompt optimized for feature type
   
   FUNCTIONAL β†’ Focus on use cases, user actions
   DATA β†’ Focus on data validation, CRUD operations
   WORKFLOW β†’ Focus on state transitions, steps
   QUALITY β†’ Focus on performance, security tests
   NOTIFICATION β†’ Focus on delivery, content verification
    ↓
4. Build Context String
   β”‚   Combine retrieved chunks into context
   - Include section references
   - Combine all retrieved chunks
    ↓
5. Call LLM (GPT-4o-mini, temperature: 0.3, JSON mode)
   β”‚   Generate comprehensive test cases
   - Generate happy path scenarios
   - Generate negative test cases
   - Generate edge cases
   - Assign priorities (P0, P1, P2, P3)
    ↓
6. Parse & Validate Test Cases
   β”‚   Extract and validate test case structure
    ↓
7. Enhance Test Cases
   β”‚   Add metadata and enrich test cases
   - Link to feature
   - Add section references
   - Calculate relevance scores
    ↓
8. Generate Gherkin Format (AI or rule-based)
   β”‚   Convert to BDD format
   - Given-When-Then structure
   - Feature, Scenario, Steps
    ↓
9. Save to MongoDB
   β”‚   Persist test cases to database
    ↓
10. Store in Vector Store (for chatbot)
    β”‚   Store embeddings for future retrieval
    - Embed test case content
    - Add metadata (featureId, priority, etc.)

Key Files:

  • backend/ai/reasoning/testCaseGeneration.js - Test case generation
  • backend/ai/reasoning/gherkinConversion.js - Gherkin conversion

5️⃣ Chatbot RAG Workflow

1. User Question
   β”‚   User asks a question about the SRS
    ↓
2. Conversation History (Optional)
   β”‚   Use previous conversation for context
   - Last 10 messages
   - Maintains context across questions
    ↓
3. Query Expansion & Variations
   β”‚   Enhance query for better retrieval
   - Expand query with synonyms
   - Create 3 query variations
   - Add category detection
    ↓
4. Multi-Query Retrieval
   β”‚   Retrieve from multiple query variations
   - Execute all 3 variations
   - Retrieve nResults Γ— 2 chunks (for deduplication)
   - Deduplicate by text hash
    ↓
5. Category-Based Weighting
   β”‚   Apply weights based on question category
   - Detect question category
   - Apply category weight
   - Boost priority-based chunks (High > Medium > Low)
   - Boost critical test cases
    ↓
6. Sort & Filter
   β”‚   Rank and select best chunks
   - Sort by adjusted relevance
   - Prioritize critical tests
   - Take top nResults chunks
    ↓
7. Build Context with Metadata
   β”‚   Format context with rich metadata
   Format:
   [Section: 3.2.1 | Feature: Login | Priority: High]
   chunk content...
   
   [Section: 4.5.2 | Test Case: Verify Password]
   test case content...
    ↓
8. Dynamic Temperature Selection
   β”‚   Adjust creativity based on question type
   - Precise questions β†’ 0.6 (more accurate)
   - Explanatory questions β†’ 0.8 (more natural)
   - Default β†’ 0.8 (balanced, friendly)
    ↓
9. Build Prompt with History
   β”‚   Create comprehensive prompt
   - System prompt (SRS context rules)
   - User prompt (question + history + context)
    ↓
10. Call LLM (GPT-4o-mini)
    β”‚   Generate conversational response
    - Generate natural, conversational response
    - Cite section numbers
    - Reference specific features/test cases
    ↓
11. Return Response
    β”‚   Return answer to user

Key Features:

  • βœ… Context-Aware: Uses project-specific SRS content
  • βœ… History Support: Maintains conversation context
  • βœ… Section Citations: References specific SRS sections
  • βœ… Category Detection: Optimizes retrieval by question type
  • βœ… Weighted Results: Prioritizes important information

Key Files:

  • backend/ai/chatbot/query.js - Chatbot RAG logic
  • backend/ai/rag/query.js - Simple RAG query handler

🎯 Key Components Explained

Vector Store (Supabase + pgvector)

// Similarity Search Process
1. Query Text β†’ Embedding Vector (1536 dimensions)
2. Cosine Similarity Search in PostgreSQL
3. Filter by projectId (project isolation)
4. Return top K most similar chunks

Why Supabase + pgvector?

  • βœ… Fast similarity search (IVFFlat index)
  • βœ… PostgreSQL reliability
  • βœ… Project-scoped filtering
  • βœ… Metadata support (JSONB)

Embedding Model (text-embedding-3-small)

  • Dimensions: 1536
  • Cost: $0.02 per 1M tokens (very cheap!)
  • Quality: Excellent for semantic search
  • Normalization: Yes (improves cosine similarity)

LLM Model (GPT-4o-mini)

  • For Reasoning: temperature 0.3 (consistent, accurate)
  • For Chatbot: temperature 0.6-0.8 (natural, friendly)
  • Cost: $0.15 per 1M input tokens
  • JSON Mode: Enabled for structured outputs

πŸ“Š Performance Optimizations

  1. Parallel Queries: 8 queries executed simultaneously
  2. Batch Embeddings: Generate embeddings in batches
  3. Caching: Vector store caches embeddings
  4. Deduplication: Prevents duplicate chunks
  5. Weighted Ranking: Prioritizes important information
  6. Section Grouping: Organized context structure

πŸ” Project Isolation

Each project has isolated vector storage:

  • All chunks tagged with projectId
  • Similarity search filtered by projectId
  • No cross-project data leakage
  • Secure multi-tenant architecture

Test Case Generation Workflow

1. Select Feature
   ↓
2. Retrieve Context:
   - From matched sections (if available)
   - OR comprehensive retrieval
   - OR feature description-based search
   ↓
3. Build Feature-Type-Specific Prompt
   ↓
4. Call LLM (GPT-4o-mini, JSON mode)
   ↓
5. Generate Test Cases
   ↓
6. Enhance & Validate
   ↓
7. Save to MongoDB
   ↓
8. Generate Gherkin (AI or rule-based)
   ↓
9. Store in Vector Store (for chatbot)

Key AI Components

1. Embeddings (ai/ingestion/embeddings.js)

  • Model: text-embedding-3-small (1536 dimensions)
  • Cost: $0.02 per 1M tokens
  • Features:
    • Text cleaning before embedding
    • Vector normalization for better cosine similarity
    • Batch processing support
    • Retry mechanism with exponential backoff

2. Comprehensive Retrieval (ai/retrieval/retrievalCore.js)

  • 8 Parallel Queries covering all feature types
  • Query Expansion for better recall
  • Deduplication based on text content
  • Section Grouping for organized context

3. Feature Extraction (ai/reasoning/featureExtraction.js)

  • Retrieves comprehensive context (8 categories)
  • Organizes context by sections
  • Creates adaptive prompts (high-recall mode)
  • Enhances features with metadata and scores
  • Analyzes section coverage

4. Test Case Generation (ai/reasoning/testCaseGeneration.js)

  • Feature-type-specific prompts
  • Section-aware context retrieval
  • JSON mode for structured output
  • Automatic Gherkin conversion

5. Vector Store (vector/vectorStore.js)

  • Supabase + pgvector for fast similarity search
  • Stores embeddings with metadata
  • Project-scoped filtering
  • Automatic embedding generation for new documents

LangChain Integration

LangChain provides:

  • ChatOpenAI: LLM management and invocation
  • OpenAIEmbeddings: Embedding generation
  • PromptTemplate: Prompt management and formatting
  • RetrievalChain: RAG chain orchestration
  • SupabaseVectorStore: Vector store integration
  • RecursiveCharacterTextSplitter: Intelligent text chunking

πŸš€ Installation

Prerequisites

  • Node.js >= 18.0.0
  • npm >= 9.0.0
  • MongoDB (local or Atlas cloud)
  • Supabase account (for vector storage)
  • OpenAI API key
  • Google Cloud account (optional, for Document AI)

1. Clone Repository

git clone https://github.com/yourusername/QBrain.git
cd QBrain

2. Backend Setup

cd backend
npm install

# Copy environment template
cp .env.example .env

# Edit .env file with your actual API keys:
# - OPENAI_API_KEY (required)
# - SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY (required)
# - MONGO_URI (required)
# - JWT_SECRET (required)
# - GCP credentials (optional, for Document AI)
# - Email service credentials (optional)

Quick Setup: If you want to use shared API keys (for development/testing only):

  1. Open backend/.env.example
  2. Replace placeholder values with actual API keys
  3. Copy to .env: cp .env.example .env
  4. Adjust any settings as needed

⚠️ Security Note: For production, use separate API keys per environment and never commit .env files.

3. Frontend Setup

cd frontend
npm install

# Copy environment template
cp .env.example .env

# Edit .env if needed (default usually works):
# VITE_API_BASE_URL=http://localhost:5000/api

4. Database Setup

MongoDB

# Start MongoDB locally (if using local instance)
mongod

# Or use MongoDB Atlas cloud service
# Update MONGO_URI in .env with your Atlas connection string

Supabase Vector Store

  1. Create a new Supabase project at supabase.com

  2. Enable pgvector extension:

CREATE EXTENSION IF NOT EXISTS vector;
  1. Run the migration script (supabase_vector_migration.sql):
-- Create project_vectors table
CREATE TABLE IF NOT EXISTS project_vectors (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  content TEXT NOT NULL,
  embedding vector(1536),
  metadata JSONB,
  project_id TEXT,
  created_at TIMESTAMP DEFAULT NOW()
);

-- Create index for vector similarity search
CREATE INDEX ON project_vectors USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100);

-- Create function for similarity search
CREATE OR REPLACE FUNCTION match_project_vectors(
  query_embedding vector(1536),
  match_threshold float DEFAULT 0.7,
  match_count int DEFAULT 10,
  filter_project_id TEXT DEFAULT NULL
)
RETURNS TABLE (
  id UUID,
  content TEXT,
  metadata JSONB,
  similarity float,
  project_id TEXT
)
LANGUAGE plpgsql
AS $$
BEGIN
  RETURN QUERY
  SELECT
    project_vectors.id,
    project_vectors.content,
    project_vectors.metadata,
    1 - (project_vectors.embedding <=> query_embedding) as similarity,
    project_vectors.project_id
  FROM project_vectors
  WHERE (filter_project_id IS NULL OR project_vectors.project_id = filter_project_id)
    AND 1 - (project_vectors.embedding <=> query_embedding) > match_threshold
  ORDER BY project_vectors.embedding <=> query_embedding
  LIMIT match_count;
END;
$$;

5. Run Application

Development Mode

# Terminal 1: Backend
cd backend
npm run dev

# Terminal 2: Frontend
cd frontend
npm run dev

Production Mode

# Build frontend
cd frontend
npm run build

# Start backend (with PM2 or similar)
cd backend
npm start

The application will be available at:


πŸ“– Usage

1. Create Account

  1. Navigate to sign-up page
  2. Enter name, email, and password
  3. Verify email address (check inbox)
  4. Log in with credentials

2. Create Project

  1. Click "Create Project" button
  2. Enter project name and description
  3. (Optional) Upload SRS document (PDF or TXT)
  4. Project is created and ready

3. Upload & Process SRS

  1. Navigate to project details
  2. Click "Upload SRS" if not uploaded during creation
  3. Select PDF or TXT file
  4. Wait for processing (automatic chunking and embedding)
  5. Status updates to "Processed" when complete

4. Extract Features

  1. Click "Generate Features (AI)" button
  2. Wait for AI processing (30-60 seconds)
  3. Review extracted features with:
    • Feature types (FUNCTIONAL, DATA, REPORT, etc.)
    • Priority levels
    • Matched SRS sections
    • Confidence scores
    • Section coverage analysis

5. Generate Test Cases

  1. Select a feature
  2. Click "Generate Test Cases (AI)" button
  3. Review AI-generated test cases:
    • Happy path scenarios
    • Negative test cases
    • Edge cases
    • Priority assignments
  4. Test cases are automatically saved with Gherkin format

6. Use Chatbot

  1. Navigate to project chatbot
  2. Ask questions about the SRS
  3. Get accurate answers based on document context
  4. Answers reference specific SRS sections

7. Manage Bugs

  1. Navigate to Bugs tab in project
  2. Create bugs linked to features
  3. Track bug status and assignments
  4. View bug analytics

πŸ“– Documentation

Comprehensive Documentation

For detailed explanations of the AI system, see:

  • AI_SYSTEM_EXPLANATION.md - Complete AI system documentation (Arabic)

    • Full workflow explanations
    • Component details
    • Technical deep dives
    • Best practices
  • AI_QUICK_GUIDE.md - Quick reference guide (Arabic)

    • Key concepts
    • Quick workflows
    • Important notes
    • Cost information

πŸ“Š Performance Metrics

Processing Times

  • SRS Processing: 30-60 seconds (depending on document size)
  • Feature Extraction: 30-60 seconds per SRS (with 8 parallel queries)
  • Test Case Generation: 10-20 seconds per feature
  • Gherkin Conversion: 2-5 seconds per test case

Accuracy & Coverage

  • Section Coverage: 75-85% average coverage
  • Feature Extraction Accuracy: High (validated by section matching)
  • Test Case Quality: Comprehensive (happy path + negative + edge cases)

Cost Estimates (OpenAI API)

  • Embeddings (text-embedding-3-small): $0.02 per 1M tokens
  • GPT-4o-mini: $0.15 per 1M input tokens
  • Average Cost per SRS: $0.10 - $0.50 (depending on size)
  • Cost per Feature Extraction: ~$0.05 - $0.15
  • Cost per Test Case Generation: ~$0.01 - $0.03

πŸ”’ Security

Authentication & Authorization

  • βœ… JWT-based authentication
  • βœ… HTTP-only cookies for token storage
  • βœ… Password hashing with bcrypt (12 rounds)
  • βœ… Email verification required
  • βœ… Password reset with secure tokens

Data Security

  • βœ… Input validation with Zod schemas
  • βœ… SQL injection prevention (MongoDB)
  • βœ… XSS protection
  • βœ… CORS configuration
  • βœ… Environment variable protection

API Security

  • βœ… Rate limiting (recommended in production)
  • βœ… Request size limits (500MB for file uploads)
  • βœ… File type validation (PDF/TXT only)
  • βœ… Row Level Security (RLS) on Supabase

Best Practices

  • βœ… Never commit .env files
  • βœ… Use strong JWT secrets
  • βœ… Rotate API keys regularly
  • βœ… Monitor API usage
  • βœ… Implement logging and monitoring

πŸ§ͺ Testing

Backend Tests

cd backend
npm test

Frontend Tests

cd frontend
npm test

Manual Testing Checklist

  • User authentication (sign up, sign in, email verification)
  • Project creation and management
  • SRS upload and processing
  • Feature extraction
  • Test case generation
  • Gherkin conversion
  • Chatbot queries
  • Bug tracking

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation as needed
  • Follow existing code style
  • Add JSDoc comments for complex functions

Code Style

  • Use ESLint and Prettier
  • Follow existing naming conventions
  • Keep functions focused and small
  • Add error handling
  • Include input validation

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Authors

  • Fatima Rajab - Initial work and development

πŸ™ Acknowledgments


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages