Documentation Index
Fetch the complete documentation index at: https://docs.kafkalabs.com/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start Example
The simplest way to use KafkaCode:
# Install globally
npm install -g kafkacode
# Scan your project
kafkacode scan ./src
Example 1: First Scan
Let’s scan a simple project:
# Project structure
my-app/
├── src/
│ ├── config.js
│ ├── auth.js
│ └── utils/
│ └── validator.js
└── package.json
Run the scan:
cd my-app
kafkacode scan ./src
Output:
🎯 PRIVACY SCAN REPORT
═══════════════════════════════════════════════════════════
📊 SCAN SUMMARY
📁 Directory: ./src
⏰ Timestamp: 2025-01-15 10:30:45
📄 Files Scanned: 3
🔍 Total Issues: 2
🏆 Privacy Grade: 🟡 B-
═══════════════════════════════════════════════════════════
🔴 CRITICAL (1)
────────────────────────────────────────────────────────────
📄 src/config.js:5
AWS Access Key detected
const AWS_KEY = "AKIAIOSFODNN7EXAMPLE"
💡 Recommendation: Move to environment variables
🟡 MEDIUM (1)
────────────────────────────────────────────────────────────
📄 src/utils/validator.js:12
Email address found in code
const adminEmail = "admin@company.com"
💡 Recommendation: Use configuration file
═══════════════════════════════════════════════════════════
Example 2: Fixing Issues
Before (Grade: B-)
src/config.js:
// ❌ Hardcoded credentials
const AWS_KEY = "AKIAIOSFODNN7EXAMPLE";
const DB_PASSWORD = "mypassword123";
const adminEmail = "admin@company.com";
module.exports = {
AWS_KEY,
DB_PASSWORD,
adminEmail
};
After (Grade: A+)
Create .env file:
AWS_KEY=AKIAIOSFODNN7EXAMPLE
DB_PASSWORD=mypassword123
ADMIN_EMAIL=admin@company.com
Update src/config.js:
// ✅ Using environment variables
require('dotenv').config();
module.exports = {
AWS_KEY: process.env.AWS_KEY,
DB_PASSWORD: process.env.DB_PASSWORD,
adminEmail: process.env.ADMIN_EMAIL
};
Rescan:
New Output:
📊 SCAN SUMMARY
📄 Files Scanned: 3
🔍 Total Issues: 0
🏆 Privacy Grade: 🟢 A+
✅ No privacy issues detected!
Example 3: Verbose Mode
For detailed progress information:
kafkacode scan ./src --verbose
Output:
🚀 Starting KafkaCode privacy scan...
📁 Discovering source code files...
Found 3 files to analyze
🔍 Performing privacy analysis...
Analyzing: src/config.js
Analyzing: src/auth.js
Analyzing: src/utils/validator.js
✅ Analysis complete
🎯 PRIVACY SCAN REPORT
[... report details ...]
Example 4: CI/CD Integration
package.json Script
{
"scripts": {
"scan": "kafkacode scan ./src",
"prescan": "echo '🔍 Running privacy scan...'",
"test": "npm run scan && jest"
}
}
Usage:
Pre-commit Hook
Create .git/hooks/pre-commit:
#!/bin/bash
echo "🔍 Running KafkaCode privacy scan..."
kafkacode scan ./src
if [ $? -ne 0 ]; then
echo "❌ Privacy issues detected. Commit aborted."
exit 1
fi
echo "✅ Privacy scan passed"
exit 0
Make it executable:
chmod +x .git/hooks/pre-commit
Example 5: Using npx
No installation required:
# Scan without installing
npx kafkacode scan ./src
# Scan with verbose mode
npx kafkacode scan ./src --verbose
Common Scenarios
Scenario 1: New Project Setup
# 1. Create project
mkdir my-project && cd my-project
npm init -y
# 2. Create source files
mkdir src
echo "const apiKey = 'test-key';" > src/config.js
# 3. Scan
npx kafkacode scan ./src
# 4. Fix issues and add to CI
npm install --save-dev kafkacode
# Add to package.json scripts
Scenario 2: Before Deployment
#!/bin/bash
echo "Pre-deployment privacy check..."
kafkacode scan ./src
if [ $? -eq 0 ]; then
echo "✅ Privacy check passed. Deploying..."
npm run deploy
else
echo "❌ Privacy issues found. Deployment aborted."
exit 1
fi
Scenario 3: Scan Specific Files
# Create temp directory with files to scan
mkdir -p /tmp/scan
cp src/config.js src/auth.js /tmp/scan/
# Scan only these files
kafkacode scan /tmp/scan
Next Steps
GitHub Actions
Automate with GitHub Actions
GitLab CI
Integrate with GitLab CI
Pre-commit Hook
Set up pre-commit scanning
CLI Options
Explore all options