Skip to content

tonywangs/code-canary

Repository files navigation

🐦 Dependency Canary

AI-powered dependency vulnerability analysis and supply chain security platform. Analyzes your project's entire dependency graph (SBOM) to flag vulnerabilities, supply-chain risks, and generate minimal patch plans.

Won 1st Place Overall + 2nd Place Modal Prize at the AI Agent & Infra Hackathon (by Lux Capital, Modal, Cognition, AWS, and Ramp)

Demo video link: https://youtu.be/eLHv1lriGms
Devpost link: https://devpost.com/software/code-canary

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   Modal/Mock    β”‚
β”‚  (Next.js)      │───▢│  API Routes     │───▢│   Services      β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Upload Form   β”‚    β”‚ β€’ /api/scan     β”‚    β”‚ β€’ SBOM Extract  β”‚
β”‚ β€’ Results View  β”‚    β”‚ β€’ /api/enrich   β”‚    β”‚ β€’ Vuln Enrich   β”‚
β”‚ β€’ Dep Graph     β”‚    β”‚ β€’ /api/ask      β”‚    β”‚ β€’ Multi-lang    β”‚
β”‚ β€’ Q&A Panel     β”‚    β”‚ β€’ /api/report   β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   AI Agent      β”‚
                       β”‚                 β”‚
                       β”‚ β€’ RAG Pipeline  β”‚
                       β”‚ β€’ Vector Store  β”‚
                       β”‚ β€’ LLM Reasoning β”‚
                       β”‚ β€’ Patch Plans   β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Monorepo Structure

dependency-canary/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ web/                 # Next.js frontend (port 3000)
β”‚   └── api/                 # API backend (port 3001)
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ shared/              # TypeScript types & API clients
β”‚   └── agent/               # RAG agent & vector processing
└── README.md

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • pnpm 8+
  • Optional: OpenAI API key for production embeddings

Installation

# Clone the repository
git clone <your-repo-url>
cd dependency-canary

# Install all dependencies
pnpm install

# Build shared packages
pnpm -r build

Development Setup

# Seed the system with mock data
pnpm seed:mock

# Start both frontend and API in development mode
pnpm dev

# Or start individually:
pnpm --filter @dependency-canary/web dev     # Frontend: http://localhost:3000
pnpm --filter @dependency-canary/api dev     # API: http://localhost:3001

Environment Variables

Create .env.local files in both apps/web and apps/api:

# Optional: Real Modal endpoints
MODAL_BASE_URL=https://your-modal-deployment.com

# Optional: OpenAI for embeddings (defaults to mock)
OPENAI_API_KEY=sk-...

# Optional: Vector store configuration
VECTOR_STORE_TYPE=memory|sqlite|pinecone
SQLITE_DB_PATH=./vector-store.db
PINECONE_API_KEY=...
PINECONE_INDEX=...

Default Behavior (No Env Vars):

  • Uses mock Modal client with realistic test data
  • Uses mock embedder with deterministic vectors
  • Uses in-memory vector store

🎯 Usage Workflow

1. Upload Project

Navigate to http://localhost:3000 and either:

  • Enter a GitHub repository URL
  • Upload a ZIP file URL
  • Specify a container image

2. Scan & Analysis

The system will:

  • Generate SBOM (Software Bill of Materials)
  • Enrich with CVE data from NVD, OSV, GHSA
  • Analyze supply chain risks
  • Index into vector database

3. Interactive Analysis

  • KPI Dashboard: View vulnerability counts, risk scores
  • Dependency Graph: Interactive visualization with severity color-coding
  • AI Q&A: Ask natural language questions about vulnerabilities
  • Remediation Plans: Get prioritized upgrade recommendations

4. Generate Reports

Download comprehensive PDF or Markdown reports with:

  • Executive summary
  • Detailed vulnerability analysis
  • Remediation roadmap
  • Package inventory

πŸ€– Sample Questions for AI Agent

Try asking these questions in the Q&A panel:

  • "What single upgrade removes the most critical CVEs?"
  • "Which packages pose the highest supply chain risk?"
  • "What are the most dangerous vulnerabilities in my direct dependencies?"
  • "How can I reduce my attack surface with minimal changes?"
  • "What abandoned packages should I replace first?"
  • "Which vulnerabilities have public exploits available?"

πŸ§ͺ Testing

# Run all tests
pnpm test

# Run smoke tests specifically
pnpm --filter @dependency-canary/agent test

# Test with verbose output
pnpm test -- --reporter=verbose

Smoke Test Coverage

  • βœ… Mock SBOM generation with realistic vulnerabilities
  • βœ… Vector store operations and filtering
  • βœ… Agent Q&A functionality with remediation plans
  • βœ… End-to-end workflow validation
  • βœ… Embedding consistency and document processing

πŸ“Š Mock Data Details

The mock service provides a realistic test dataset with:

  • 8 packages across npm, PyPI ecosystems
  • 5 vulnerabilities (1 Critical, 2 High, 2 Medium)
  • 3 services (web, api, worker)
  • Supply chain risks (prototype pollution, SSRF, ReDoS)

Key test packages:

πŸ”§ Development

Adding New Vector Stores

// packages/agent/src/vector-stores/custom-store.ts
import { VectorStore, VectorDocument, VectorSearchResult } from '@dependency-canary/shared';

export class CustomVectorStore implements VectorStore {
  async addDocuments(documents: VectorDocument[]): Promise<void> {
    // Implementation
  }
  
  async search(query: VectorStoreQuery): Promise<VectorSearchResult[]> {
    // Implementation
  }
  
  async clear(): Promise<void> {
    // Implementation
  }
}

Adding New Embedders

// packages/agent/src/embedders/custom-embedder.ts
import { Embedder } from '@dependency-canary/shared';

export class CustomEmbedder implements Embedder {
  async embed(text: string): Promise<number[]> {
    // Implementation
  }
  
  async embedBatch(texts: string[]): Promise<number[][]> {
    // Implementation
  }
}

πŸ”— API Contracts

Modal Integration Points

// Scan endpoint
POST /api/scan
Body: { projectRef: string, refType: "git"|"zip"|"image", ref: string }
Response: { jobId: string }

// Enrich endpoint  
GET /api/enrich?jobId=<jobId>
Response: EnrichedSBOM (see types/sbom.ts)

Internal API Routes

// Ask the AI agent
POST /api/ask
Body: { projectId: string, question: string }
Response: AgentAnswer (see types/api.ts)

// Generate reports
GET /api/report?projectId=<id>&format=pdf|markdown
Response: PDF blob or Markdown text

πŸ“ˆ Performance Notes

  • Vector Store: In-memory store for dev, SQLite/Pinecone for production
  • Embeddings: ~1500 dimensions, cached per document
  • Agent Reasoning: Context-aware RAG with metadata filtering
  • Report Generation: Server-side PDF rendering with Puppeteer

πŸ”’ Security Considerations

  • Never logs or commits API keys
  • Sanitizes user inputs in search queries
  • Validates SBOM schemas before processing
  • Uses read-only vector operations in agent reasoning

🚒 Production Deployment

Environment Setup

# Production build
pnpm build

# Set production environment variables
export MODAL_BASE_URL=https://your-modal-deployment.com
export OPENAI_API_KEY=sk-...
export VECTOR_STORE_TYPE=sqlite
export SQLITE_DB_PATH=/data/vector-store.db

# Start production servers
pnpm --filter @dependency-canary/web start
pnpm --filter @dependency-canary/api start

Docker Deployment

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN corepack enable pnpm && pnpm install --frozen-lockfile
RUN pnpm build
CMD ["pnpm", "dev"]

🀝 Integration with Real Modal Services

When your teammate's Modal services are ready:

  1. Set MODAL_BASE_URL environment variable
  2. The system automatically switches from mock to real client
  3. No code changes needed - interface is identical

The Modal services should implement:

  • POST /scan β†’ { jobId }
  • GET /enrich?jobId=... β†’ EnrichedSBOM

πŸ“‹ Todo / Future Enhancements

  • WebSocket support for real-time scan progress
  • GitHub Actions integration for CI/CD scanning
  • SARIF output format support
  • Multi-project comparison views
  • Slack/Teams notifications for critical findings
  • Custom risk scoring models
  • Integration with dependency management tools

πŸ› Troubleshooting

Common Issues

"No SBOM available" error:

  • Ensure you've run pnpm seed:mock
  • Check that both web and API servers are running

Vector store errors:

  • Clear data: rm -rf *.db and re-run seed script
  • Check filesystem permissions for SQLite

PDF generation fails:

  • Install system dependencies: apt-get install -y chromium-browser
  • For Docker: use puppeteer/puppeteer:latest base image

Empty dependency graph:

  • Verify service filter selection
  • Check browser console for JavaScript errors

πŸŽ‰ Demo Walkthrough

  1. Start: pnpm dev (both apps running)
  2. Seed: pnpm seed:mock (populate with test data)
  3. Upload: Visit localhost:3000, paste https://github.com/mock/repo
  4. Scan: Click "Start Security Scan" (uses mock data)
  5. Explore: View KPIs, interact with dependency graph
  6. Ask: "What single upgrade removes the most critical CVEs?"
  7. Report: Download PDF with full analysis
  8. Test: Run pnpm test to validate all components

Built with ❀️ for supply chain security. Questions? Check the code or run the smoke tests!

About

dependency vulnerability detection

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors