> ## 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.

# Basic Scan Example

> Simple examples of using KafkaCode for privacy scanning

## Quick Start Example

The simplest way to use KafkaCode:

```bash theme={null}
# Install globally
npm install -g kafkacode

# Scan your project
kafkacode scan ./src
```

## Example 1: First Scan

Let's scan a simple project:

```bash theme={null}
# Project structure
my-app/
├── src/
│   ├── config.js
│   ├── auth.js
│   └── utils/
│       └── validator.js
└── package.json
```

**Run the scan:**

```bash theme={null}
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`:

```javascript theme={null}
// ❌ 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:

```bash theme={null}
AWS_KEY=AKIAIOSFODNN7EXAMPLE
DB_PASSWORD=mypassword123
ADMIN_EMAIL=admin@company.com
```

Update `src/config.js`:

```javascript theme={null}
// ✅ 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:**

```bash theme={null}
kafkacode scan ./src
```

**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:

```bash theme={null}
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

```json theme={null}
{
  "scripts": {
    "scan": "kafkacode scan ./src",
    "prescan": "echo '🔍 Running privacy scan...'",
    "test": "npm run scan && jest"
  }
}
```

**Usage:**

```bash theme={null}
npm run scan
```

### Pre-commit Hook

Create `.git/hooks/pre-commit`:

```bash theme={null}
#!/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:

```bash theme={null}
chmod +x .git/hooks/pre-commit
```

## Example 5: Using npx

No installation required:

```bash theme={null}
# Scan without installing
npx kafkacode scan ./src

# Scan with verbose mode
npx kafkacode scan ./src --verbose
```

## Common Scenarios

### Scenario 1: New Project Setup

```bash theme={null}
# 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

```bash theme={null}
#!/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

```bash theme={null}
# 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

<CardGroup cols={2}>
  <Card title="GitHub Actions" icon="github" href="/examples/github-actions">
    Automate with GitHub Actions
  </Card>

  <Card title="GitLab CI" icon="gitlab" href="/examples/gitlab-ci">
    Integrate with GitLab CI
  </Card>

  <Card title="Pre-commit Hook" icon="git" href="/examples/pre-commit-hook">
    Set up pre-commit scanning
  </Card>

  <Card title="CLI Options" icon="terminal" href="/usage/cli-options">
    Explore all options
  </Card>
</CardGroup>
