Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI/CD Pipeline

on:
push:
branches: [ main, dev, 7-feat-add-workflow-ci ]
pull_request:
branches: [ main, dev, 7-feat-add-workflow-ci ]

jobs:
test-and-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

# Install and test client
- name: Install client dependencies
working-directory: ./client
run: |
npm install
npm run build

- name: Run client tests
working-directory: ./client
run: |
npm test -- --passWithNoTests --no-watch

- name: Run client linting
working-directory: ./client
run: |
rm -rf build/
npm run lint -- --quiet || echo "Linting issues found, but continuing build"

# Install and test server
- name: Install server dependencies
working-directory: ./server
run: npm install

# Build server (if needed)
- name: Build server
working-directory: ./server
run: npm run build || echo "No build script found, skipping"

deploy:
needs: test-and-build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
278 changes: 248 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,275 @@
# CoreTrace Web Interface
# CoreTrace Web Application

A web-based interface for the CoreTrace tool that uses WebAssembly for core functionality.
A full-stack web application for analyzing C/C++ code using various static and dynamic analysis tools. The application provides a modern web interface for uploading code, configuring analysis options, and viewing security findings.

## Prerequisites
## Features

- [Node.js](https://nodejs.org/) (v16 or higher)
- **Code Analysis**: Analyze C/C++ code using multiple tools (flawfinder, cppcheck, etc.)
- **Sandboxed Execution**: Secure code analysis in isolated environments
- **Modern UI**: React-based interface with Monaco Editor for code editing
- **Real-time Results**: View analysis results with syntax highlighting
- **Tool Selection**: Choose which analysis tools to use
- **Example Code**: Pre-built examples for testing and learning

## Getting Started
## Architecture

These instructions will help you set up the project locally for development and testing purposes.
### Backend (Node.js/Express)
- **Server**: Express.js REST API
- **Analysis Engine**: Custom analyzer with tool integration
- **Sandboxing**: Multiple isolation methods (Firejail, QEMU, Bubblewrap)
- **Job Management**: Asynchronous analysis job handling
- **Logging**: Structured logging with Winston

### Frontend (React)
- **UI Framework**: React with Tailwind CSS
- **Code Editor**: Monaco Editor with syntax highlighting
- **State Management**: React Context for application state
- **API Integration**: Axios for backend communication

## Quick Start

### Prerequisites

- Node.js 16+
- npm or yarn
- Linux environment (for sandboxing tools)
- Firejail (recommended) or QEMU

### Installation

1. Clone the repository:
1. **Clone the repository**
```bash
git clone <repository-url>
cd coretrace-web
```

2. **Install backend dependencies**
```bash
cd server
npm install
```

3. **Install frontend dependencies**
```bash
cd ../client
npm install
```

4. **Start the development servers**
```bash
# Terminal 1 - Backend
cd server
npm run dev

# Terminal 2 - Frontend
cd client
npm start
```

5. **Access the application**
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000

## Documentation

### API Documentation

Comprehensive API documentation is available in [`server/API_DOCUMENTATION.md`](server/API_DOCUMENTATION.md).

**Key Endpoints:**
- `POST /api/analyze` - Analyze code files
- `GET /api/tools` - Get available analysis tools
- `GET /api/examples` - Get example code snippets

### Code Documentation

#### Backend Documentation

The backend code is documented using JSDoc. Generate documentation by running:

```bash
git clone <repository-url>
cd ctrace-web
cd server
npm run docs
```

2. Install dependencies for the client:
```bash
cd client
npm install
Then open `server/docs/index.html` in your browser.

**Documented Modules:**
- **Services**: Analyzer, JobManager, Logger, Sandbox, SARIF Parser
- **Routes**: Analysis, Examples, Tools endpoints
- **Controllers**: Request handling and validation
- **Configuration**: Environment and sandbox settings

#### Frontend Documentation

Frontend components are documented with JSDoc comments:

**Key Components:**
- `App.jsx` - Main application component
- `AnalysisContext.jsx` - State management context
- `ApiService` - Backend communication
- Editor components for code editing and results display

### Architecture Documentation

#### Backend Architecture

```
server/
├── services/ # Business logic
│ ├── analyzer.js # Main analysis orchestrator
│ ├── jobManager.js # Job lifecycle management
│ ├── sandbox.js # Execution isolation
│ ├── logger.js # Logging service
│ └── sarifParser.js # Result parsing
├── routes/ # API endpoints
├── controllers/ # Request handlers
├── middlewares/ # Express middleware
└── config/ # Configuration
```

3. Install dependencies for the server:
```bash
cd server
npm install
#### Frontend Architecture

```
client/src/
├── components/ # React components
│ └── Editor/ # Code editor components
├── context/ # React context
├── services/ # API services
└── App.jsx # Main component
```

### Running the Development Server
## Configuration

### Backend Configuration

Edit `server/config/index.js` to customize:

- **Sandbox Settings**: Memory limits, timeouts, isolation methods
- **File Limits**: Maximum file sizes and counts
- **Job Management**: Cleanup delays and retention periods
- **Logging**: Log levels and formats

### Environment Variables

**Backend:**
- `PORT` - Server port (default: 5000)
- `NODE_ENV` - Environment mode
- `QEMU_BINARY` - QEMU binary path
- `QEMU_LIB_ROOT` - QEMU library root

**Frontend:**
- `REACT_APP_API_URL` - Backend API URL

## Development

### Backend Development

Start the development server with:
```bash
cd server
npm run dev
npm run dev # Start with nodemon
npm run docs # Generate documentation
npm test # Run tests
```

### Running the Client
In a separate terminal, start the client:
### Frontend Development

```bash
cd client
npm run start
npm start # Start development server
npm test # Run tests
npm run build # Build for production
```

## Project Structure
### Adding New Analysis Tools

1. **Backend Integration**
- Add tool binary to `server/bin/`
- Update `services/analyzer.js` to include new tool
- Add tool configuration to `config/index.js`

2. **Frontend Integration**
- Update tool selection UI in `components/Editor/`
- Add tool-specific result display logic

### Documentation Standards

#### JSDoc Comments

Use standard JSDoc format for all functions and classes:

```javascript
/**
* @function functionName
* @description Brief description of what the function does
* @param {string} paramName - Description of parameter
* @returns {Promise<Object>} Description of return value
* @throws {Error} Description of when error is thrown
*/
```

#### API Documentation

- Update `server/API_DOCUMENTATION.md` for new endpoints
- Include request/response examples
- Document error scenarios

## Deployment

### Docker Deployment

```bash
# Build and run with Docker Compose
docker-compose up --build
```

### Production Considerations

- **Security**: Implement authentication and rate limiting
- **Monitoring**: Add application monitoring and logging
- **Scaling**: Consider job queue systems for high load
- **Backup**: Implement data backup strategies

## Troubleshooting

### Common Issues

1. **Sandbox Failures**
- Ensure Firejail is installed: `sudo apt install firejail`
- Check file permissions in sandbox directories
- Verify resource limits in configuration

2. **Analysis Tool Errors**
- Verify tool binaries are executable
- Check tool dependencies are installed
- Review tool-specific error logs

3. **API Connection Issues**
- Verify backend server is running
- Check CORS configuration
- Ensure correct API URL in frontend

### Logs

- **Backend**: Check `server/combined.log` and `server/error.log`
- **Frontend**: Browser developer console
- **Sandbox**: Check system logs for sandbox-related errors

## Contributing

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Update documentation
5. Submit a pull request

## License

- `client/` - Contains the React frontend application.
- `server/` - Contains the Node.js backend server.
[Add your license information here]

## Technologies Used
## Support

- React
- WebAssembly
- Tailwind CSS
For issues and questions:
- Create an issue in the repository
- Check the documentation
- Review the troubleshooting section
6 changes: 6 additions & 0 deletions client/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
build/
dist/
coverage/
postcss.config.js
tailwind.config.js
Loading