Code Origin Ratio Matrix - Track and analyze how much AI-generated code survives in your codebase over time.
COR-Matrix helps development teams understand the real-world impact of AI-generated code by tracking what percentage of originally AI-generated code remains unchanged versus modified or removed during development.
The Problem: Teams using AI coding assistants don't know if the generated code is actually useful long-term or gets rewritten immediately.
The Solution: COR-Matrix captures signatures of AI-generated code as it's written, then analyzes your codebase later to show retention rates and code evolution patterns.
# Set up environment variables
cp .env.example .env
# Edit .env file with your actual values
# Start the API server with Docker
docker-compose up -d# Install dependencies
bun install
# Set up environment variables
cp .env.example .env
# Edit .env file with your actual values
# Run database migrations
bun run db:push
# Start the API server
bun run dev:apiThe API will be available at http://localhost:3000 with documentation at http://localhost:3000/docs.
Install the client SDK in your project:
npm install @presidio-dev/cor-matrixIntegrate tracking into your development workflow:
import { CorMatrix } from "@presidio-dev/cor-matrix";
const corMatrix = new CorMatrix({
appName: "my-app",
baseURL: "http://localhost:3000",
token: "your-workspace-token",
workspaceId: "your-workspace-id",
});
// Track AI-generated code as you write it
corMatrix.addCodeOriginRecord({
code: "console.log('Hello from AI');",
path: "src/index.ts",
language: "typescript",
generatedBy: "copilot",
});Analyze your codebase to see AI code retention:
npx @presidio-dev/cor-matrix report \
--workspace-id your-workspace-id \
--project-path /path/to/your/project \
--api-url http://localhost:3000 \
--api-token your-workspace-tokenExample output:
COR-Matrix Report
────────────────────────────────────────────────────────────────
Codebase Path: /path/to/your/project
Report Time: June 1, 2025 at 6:00 PM
Total Lines: 961 (100%)
AI-Written Lines: 40 of 961 (4.16%)
────────────────────────────────────────────────────────────────
# Database operations
bun run db:generate # Generate migrations
bun run db:push # Apply migrations
bun run db:studio # Open database GUI
# Development
bun run dev:api # Start API server with hot reload
bun run build:client # Build client SDK
bun run build:api # Build API Docker imageThe project primarily uses Bun as the JavaScript runtime. To set up Bun:
# Install Bun
curl -fsSL https://bun.sh/install | bash
# Verify installation
bun --version # Should display 1.2.15 or newerWhile Bun is the primary development runtime, Node.js is required for some operations:
# Recommended Node.js version
node --version # Should be v18 or newer
# Installing dependencies with Bun
bun installThe project uses SQLite with Drizzle ORM for data persistence:
-
Database Configuration:
- Copy
.env.exampleto.envand configure the database settings - By default, the application uses a SQLite file database
- Copy
-
Running Migrations:
# Apply the latest schema to your database bun run db:push # Generate new migrations when schema changes bun run db:generate # Explore your database with the Drizzle Studio GUI bun run db:studio
-
Database Structure:
- The database schema is defined in TypeScript using Drizzle ORM
- Migrations are stored in the
drizzledirectory
Run integration tests using Vitest:
# Run all integration tests
bun run test:integration
# Run tests in watch mode during development
bun run test:integration:watchFor containerized development:
# Build the API Docker image
bun run build:api
# Run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f- API Server: Elysia.js REST API with SQLite database
- SDK: Node.js library for real-time code tracking
- CLI: Command-line tool for codebase analysis
- Database: Stores code signatures and workspace data
- TypeScript: The entire project is built using TypeScript, providing strong typing, enhanced IDE support, and improved code quality through compile-time error checking.
- Bun: A fast all-in-one JavaScript runtime that serves as the primary runtime environment for the project. Bun is used for running the API server, executing scripts, and managing dependencies.
- Node.js: Used as a complementary runtime environment, particularly for the SDK which is published as an npm package for broader compatibility with Node.js-based projects.
- Elysia.js: A high-performance TypeScript web framework built on Bun that powers the REST API. Elysia.js offers type-safe route definitions, middleware support, and integrated Swagger documentation.
- SQLite: A lightweight, file-based database engine used for local development and embedded deployments.
- Drizzle ORM: A TypeScript-first ORM for SQL databases with a lightweight, relational-focused API. Drizzle handles schema definitions, migrations, and database operations with full type safety.
- Database Migration: The project includes automated schema migrations using
drizzle-kit, with commands for generating and applying migrations (db:generate,db:push).
- Vitest: A Vite-based test runner with a Jest-compatible API that provides fast, modern testing capabilities. Used for integration testing the API endpoints and core functionality.
- Testcontainers: Used in integration tests to create isolated Docker container environments for testing database interactions and API functionality.
- Supertest: HTTP assertion library used for testing API endpoints in integration tests.
- Docker: The project uses Docker for containerization, with multi-platform support (linux/amd64, linux/arm64). The API server is packaged as a containerized application for easy deployment.
- Docker Compose: Provided as the recommended way to run the API server, handling environment configuration and service orchestration.
- GitHub Actions: Comprehensive CI/CD pipeline that:
- Runs integration tests on every push to main and rc branches
- Builds and publishes Docker images to GitHub Container Registry
- Builds and publishes the SDK package to npm
- Handles versioning for both Docker images and npm packages
- Generates build summaries for each workflow run
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
For security concerns, please see our Security Policy.