AI-powered code knowledge management system
Store, search, analyze, and improve your code with semantic search and AI assistance
Features • Benefits • Screenshots • Getting Started • Usage Examples • API • Contributing • License
CodeVault is a comprehensive platform for developers to store, organize, and analyze code snippets across various programming languages. Powered by AI, it offers intelligent code explanations, security scanning, performance analysis, and smart search capabilities, making it the ultimate developer's knowledge base.
- 🧠 AI Code Assistant - Get intelligent explanations, optimizations, and guidance with the integrated AI chat
- 📚 Code Repository - Store, categorize, and search code snippets across multiple programming languages
- 🔍 Semantic Search - Advanced vector-based search finds semantically similar code beyond simple text matching
- 🔒 Security Scanner - Detect potential security vulnerabilities with detailed recommendations
- 📊 Code Analysis Tools - Analyze complexity, quality, and optimization opportunities
- 🔄 Code Comparison - Compare different code approaches side-by-side
- 📝 Conversation History - Keep track of your AI chat interactions for future reference
- Save time by quickly finding and reusing code snippets
- Learn faster with AI-powered explanations of complex code
- Improve productivity by building a personal knowledge base of working code
- Avoid reinventing the wheel by leveraging your existing code solutions
- Identify security issues before they reach production
- Optimize performance with AI-powered suggestions
- Improve code quality through complexity and structure analysis
- Compare different approaches to understand tradeoffs
- Modern web interface works across devices
- REST API for integration with your development tools
- Docker support for easy deployment
- Open-source and extensible architecture
- Docker and Docker Compose
- .NET 8.0 SDK (for development)
- PostgreSQL with pgvector extension
- OpenAI API key or Ollama (for local AI models)
- Clone the repository:
git clone https://github.com/George-Sakellariou/codevault.git
cd codevault- Set your OpenAI API key:
# Create a .env file
echo "OPENAI_API_KEY=your_api_key_here" > .env- Start the application:
docker-compose up -d- Access CodeVault at
http://localhost:8080
- Clone the repository:
git clone https://github.com/George-Sakellariou/codevault.git
cd codevault- Install PostgreSQL with pgvector extension:
# Ubuntu/Debian
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo apt install postgresql-server-dev-$(pg_config --version | awk '{print $2}' | cut -d. -f1)
git clone https://github.com/pgvector/pgvector.git
cd pgvector
make
sudo make install
cd ..- Create database and user:
sudo -u postgres psql
postgres=# CREATE USER codevault-user WITH PASSWORD 'securepass123!';
postgres=# CREATE DATABASE code_vault;
postgres=# GRANT ALL PRIVILEGES ON DATABASE code_vault TO codevault-user;
postgres=# \c code_vault
code_vault=# CREATE EXTENSION vector;
code_vault=# \q- Configure API keys:
# Edit appsettings.json or use user secrets
dotnet user-secrets init
dotnet user-secrets set "OpenAI:ApiKey" "your_api_key_here"- Run database migrations:
dotnet ef database update- Start the application:
dotnet run-
Navigate to
Code Snippets>Add New Snippet -
Fill in the details:
- Title: "Async/Await Error Handling Pattern"
- Language: JavaScript
- Content:
async function fetchData() { try { const response = await fetch('https://api.example.com/data'); if (!response.ok) { throw new Error(`HTTP error: ${response.status}`); } const data = await response.json(); return data; } catch (error) { console.error('Fetch error:', error); throw error; // Re-throw for caller handling } } // Usage with error handling async function loadData() { try { const result = await fetchData(); processData(result); } catch (error) { displayError(error); } }
- Description: "A robust pattern for handling errors in async/await functions, including proper error propagation and HTTP status checking."
- Tags: async, error-handling, javascript, fetch-api
-
Click
Save Code Snippet
- Find the code snippet you want to scan
- Note its ID (visible in the URL or details page)
- Navigate to
Tools>Security Scanner - Enter the snippet ID and click
Scan for Vulnerabilities - Review the results, which might include:
- Hardcoded credentials
- Insecure API calls
- Potential XSS vulnerabilities
- SQL injection risks
Example vulnerable code to test (NodeJS):
function authenticateUser(req, res) {
const username = req.body.username;
const password = req.body.password;
// VULNERABLE: Hardcoded credentials
if (username === "admin" && password === "admin123") {
return res.json({ token: "secret-jwt-token" });
}
// VULNERABLE: SQL Injection
const query = `SELECT * FROM users WHERE username = '${username}' AND password = '${password}'`;
db.query(query, (err, result) => {
if (err) throw err;
if (result.length > 0) {
// VULNERABLE: Insecure token generation
const token = Math.random().toString(36).substring(2);
res.json({ token: token });
} else {
res.status(401).json({ error: "Invalid credentials" });
}
});
}- Find or add a code snippet
- Navigate to
Tools>Code Analysis - Enter the snippet ID and click
Analyze - Review complexity metrics and optimization suggestions
Example code to analyze (Python):
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def calculate_fibonacci_sequence(length):
result = []
for i in range(length):
result.append(fibonacci(i))
return result
# Generate a sequence
sequence = calculate_fibonacci_sequence(30)
print(sequence)The analysis will suggest replacing recursive Fibonacci with dynamic programming for better performance.
- Navigate to the
Chattab - Ask a code-related question:
- "Can you explain how promises work in JavaScript?"
- "What's the difference between ArrayList and LinkedList in Java?"
- "How can I optimize this SQL query? SELECT * FROM orders WHERE customer_id IN (SELECT id FROM customers WHERE region = 'Europe')"
- "What are the security risks in this code?" (paste code snippet)
The AI will provide an answer, often referencing relevant code from your repository.
- Navigate to
Tools>Code Comparison - Enter the IDs of two code snippets to compare
- Review the detailed comparison highlighting:
- Structural differences
- Complexity variations
- Performance implications
- Common patterns
CodeVault uses advanced embeddings to enable semantic search:
// Example from CodeVault's search service
public async Task<List<CodeSnippet>> SearchWithVectorAsync(string query, int limit = 5)
{
// Generate embeddings for the search query
var queryEmbeddings = await _vectorService.GetEmbeddingsAsync(query);
// Perform cosine similarity search in the vector database
// This finds semantically similar code, not just text matches
var results = await _vectorDatabase.SearchSimilarAsync(queryEmbeddings, limit);
return results;
}This allows you to find code based on concepts, not just keywords.
Track performance metrics for your code snippets:
// Add time complexity metric
await _analysisService.AddPerformanceMetricAsync(
snippetId: 42,
metricName: "Time Complexity",
metricValue: "O(n log n)",
environment: "Node.js 18.x",
notes: "Measured with array size of 10,000 elements"
);
// Add memory usage metric
await _analysisService.AddPerformanceMetricAsync(
snippetId: 42,
metricName: "Memory Usage",
metricValue: "12.5",
numericValue: 12.5,
unit: "MB",
environment: "Node.js 18.x"
);CodeVault provides a REST API for integration with your development tools.
All API endpoints require authentication using API keys.
# Example API request with authentication
curl -X GET https://your-codevault-instance.com/api/code/search?query=async%20function \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_api_key_here"GET /api/code/search?query={query}&language={language}
GET /api/code/{id}
POST /api/code
Request body:
{
"title": "Async Error Handling",
"content": "async function fetchData() {...}",
"language": "JavaScript",
"description": "Error handling pattern for async functions",
"tags": ["async", "error-handling", "javascript"]
}PUT /api/code/{id}
DELETE /api/code/{id}
POST /api/analysis/complexity
Request body:
{
"snippetId": 42
}POST /api/analysis/optimization
POST /api/analysis/security
POST /api/analysis/compare
Request body:
{
"snippetId1": 42,
"snippetId2": 43
}POST /api/analysis/metrics
Request body:
{
"snippetId": 42,
"metricName": "Time Complexity",
"metricValue": "O(n)",
"unit": "",
"environment": "Node.js 18.x",
"notes": "Measured with array of 10,000 elements"
}POST /api/chat/message
Request body:
{
"content": "Explain how promises work in JavaScript",
"conversationId": 0
}GET /api/chat/conversations
DELETE /api/chat/conversations/{id}
CodeVault supports multiple programming languages out of the box, but you can extend it with new ones:
- Add language definition in
GetLanguageClass()methods - Add language-specific security checks in
SecurityAnalysisService.cs - Add syntax highlighting support in the frontend
CodeVault works with OpenAI by default, but you can integrate other models:
- Implement the
IOpenAiServiceinterface for your AI provider - Configure the service in
Program.cs
Example integration with a local Ollama model:
public class OllamaService : IOpenAiService
{
private readonly HttpClient _httpClient;
private readonly string _baseUrl;
private readonly string _model;
public OllamaService(IConfiguration configuration)
{
_httpClient = new HttpClient();
_baseUrl = configuration["Ollama:BaseUrl"] ?? "http://localhost:11434/api";
_model = configuration["Ollama:CompletionModel"] ?? "llama3";
}
public async Task<string> GetCompletionAsync(string prompt)
{
var requestData = new
{
model = _model,
prompt = prompt
};
var content = new StringContent(
JsonSerializer.Serialize(requestData),
Encoding.UTF8,
"application/json");
var response = await _httpClient.PostAsync($"{_baseUrl}/generate", content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var responseObject = JsonSerializer.Deserialize<JsonElement>(responseBody);
return responseObject.GetProperty("response").GetString() ?? "";
}
}- Database Connection
Error: Host=localhost;Port=5432;Database=code_vault;Username=codevault-user;Password=securepass123!
Solution: Check that PostgreSQL is running and credentials are correct:
# Test connection
psql -h localhost -U codevault-user -d code_vault- Vector Extension
Error: ERROR: function vector_cosine_similarity(numeric[], numeric[]) does not exist
Solution: Verify pgvector is installed correctly:
# In PostgreSQL
\c code_vault
CREATE EXTENSION IF NOT EXISTS vector;
\dx- OpenAI API Key
Error: OpenAI API key is not configured
Solution: Check your API key is set in appsettings.json, environment variables, or user secrets.
- Fork and clone the repository
- Install dependencies
- Set up the development database
- Run the application in development mode
# Run in development mode
dotnet watch runThis project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.

