Skip to content

Commit 0218d06

Browse files
Merge pull request #2 from KasarLabs/core/db-migration
core(db) : Migration from mongodb to postgresql
2 parents f6337f0 + 2e517bd commit 0218d06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1002
-529
lines changed

.cursor/rules/imports.mdc

Lines changed: 81 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,93 +8,121 @@ globs: *.ts,*.tsx,*.js,*.jsx
88

99
### Backend and Agent Libraries
1010
- `express`: Web server framework.
11-
- Used in: `packages/backend/src/app.ts`
12-
- Import: `import express from 'express';`
11+
- Used in: `packages/backend/src/routes/cairocoder.ts`
12+
- Import: `import express, { Router } from 'express';`
1313
- `cors`: CORS middleware for Express.
14-
- Used in: `packages/backend/src/app.ts`
14+
- Used in: `packages/backend/src/server.ts`
1515
- Import: `import cors from 'cors';`
1616
- `mongodb`: MongoDB client for database operations.
17-
- Used in: `packages/agents/src/db/`
17+
- Used in: `packages/agents/src/db/vectorStore.ts`
1818
- Import: `import { MongoClient } from 'mongodb';`
19+
- `@langchain/core`: LangChain core libraries.
20+
- Used in: `packages/agents/src/core/agentFactory.ts`
21+
- Import: `import { BaseMessage } from '@langchain/core/messages';`
22+
- Import: `import { Embeddings } from '@langchain/core/embeddings';`
23+
- Import: `import { Document } from '@langchain/core/documents';`
1924
- `anthropic`: Anthropic Claude API client.
20-
- Used in: `packages/agents/src/lib/`
25+
- Used in: `packages/agents/src/models/`
2126
- Import: `import Anthropic from '@anthropic-ai/sdk';`
2227
- `openai`: OpenAI API client.
23-
- Used in: `packages/agents/src/lib/`
28+
- Used in: `packages/agents/src/models/`
2429
- Import: `import OpenAI from 'openai';`
2530
- `@google/generative-ai`: Google AI API client.
26-
- Used in: `packages/agents/src/lib/`
31+
- Used in: `packages/agents/src/models/`
2732
- Import: `import { GoogleGenerativeAI } from '@google/generative-ai';`
33+
- `uuid`: For generating unique identifiers.
34+
- Used in: `packages/backend/src/routes/cairocoder.ts`
35+
- Import: `import { v4 as uuidv4 } from 'uuid';`
36+
- `toml`: For parsing TOML configuration files.
37+
- Used in: `packages/agents/src/config/settings.ts`
38+
- Import: `import toml from '@iarna/toml';`
2839

29-
### Frontend Libraries
30-
- `react`: UI library.
31-
- Used in: `packages/ui/components/`
32-
- Import: `import React from 'react';`
33-
- `next`: React framework.
34-
- Used in: `packages/ui/app/`
35-
- Import: `import { useRouter } from 'next/router';`
36-
- `tailwindcss`: CSS framework.
37-
- Used in: `packages/ui/components/`
38-
- Applied via class names.
40+
### Data Ingestion Libraries
41+
- `axios`: HTTP client for downloading documentation.
42+
- Used in: `packages/ingester/src/ingesters/MarkdownIngester.ts`
43+
- Import: `import axios from 'axios';`
44+
- `adm-zip`: For handling ZIP archives.
45+
- Used in: `packages/ingester/src/ingesters/MarkdownIngester.ts`
46+
- Import: `import AdmZip from 'adm-zip';`
47+
- `fs/promises`: Node.js file system promises API.
48+
- Used in: `packages/ingester/src/ingesters/MarkdownIngester.ts`
49+
- Import: `import * as fs from 'fs/promises';`
3950

4051
## Internal Modules
4152

4253
### Agent Modules
43-
- `pipeline`: RAG pipeline components.
44-
- Used in: `packages/agents/src/core/ragAgentFactory.ts`
45-
- Import: `import { QueryProcessor, DocumentRetriever, CodeGenerator } from './pipeline';`
54+
- `core/pipeline`: RAG pipeline components.
55+
- Used in: `packages/agents/src/core/agentFactory.ts`
56+
- Import: `import { RagPipeline } from './pipeline/ragPipeline';`
4657
- `config`: Configuration management.
47-
- Used in: `packages/agents/src/`
48-
- Import: `import { config } from './config';`
58+
- Used in: `packages/agents/src/core/agentFactory.ts`
59+
- Import: `import { getAgentConfig } from '../config/agent';`
4960
- `db`: Database interaction.
50-
- Used in: `packages/agents/src/core/`
51-
- Import: `import { VectorStore } from './db/vectorStore';`
52-
- `models`: LLM and embedding models interfaces.
53-
- Used in: `packages/agents/src/core/`
54-
- Import: `import { LLMProviderFactory } from './models/llmProviderFactory';`
55-
- Import: `import { EmbeddingProviderFactory } from './models/embeddingProviderFactory';`
61+
- Used in: `packages/agents/src/core/agentFactory.ts`
62+
- Import: `import { VectorStore } from '../db/vectorStore';`
63+
- `types`: Type definitions.
64+
- Used in: `packages/agents/src/core/agentFactory.ts`
65+
- Import: `import { LLMConfig } from '../types';`
66+
- `utils`: Utility functions.
67+
- Used in: `packages/backend/src/app.ts`
68+
- Import: `import { logger } from '@cairo-coder/agents/utils/index';`
5669

5770
### Backend Modules
58-
- `routes`: API routes.
59-
- Used in: `packages/backend/src/app.ts`
60-
- Import: `import { generateRoutes } from './routes/generate';`
61-
- Import: `import { modelsRoutes } from './routes/models';`
62-
- `handlers`: Request handlers.
63-
- Used in: `packages/backend/src/routes/`
64-
- Import: `import { generateHandler } from '../handlers/generateHandler';`
71+
- `routes`: API route definitions.
72+
- Used in: `packages/backend/src/server.ts`
73+
- Import: `import routes from '../routes';`
74+
- `config`: Server configuration.
75+
- Used in: `packages/backend/src/server.ts`
76+
- Import: `import { initializeLLMConfig } from './config/llm';`
77+
- Import: `import { getPort } from '@cairo-coder/agents/config/settings';`
78+
- `cairocoder`: Main endpoint handler.
79+
- Used in: `packages/backend/src/routes/index.ts`
80+
- Import: `import cairocoderRouter from './cairocoder';`
6581

6682
### Ingester Modules
67-
- `baseIngester`: Abstract base class for all ingesters.
68-
- Used in: `packages/ingester/src/ingesters/`
83+
- `BaseIngester`: Abstract base class for all ingesters.
84+
- Used in: `packages/ingester/src/ingesters/MarkdownIngester.ts`
6985
- Import: `import { BaseIngester } from '../BaseIngester';`
70-
- `ingesterFactory`: Factory for creating ingesters.
71-
- Used in: `packages/ingester/src/scripts/`
72-
- Import: `import { IngesterFactory } from '../IngesterFactory';`
73-
- `utils`: Utility functions.
74-
- Used in: `packages/ingester/src/`
75-
- Import: `import { downloadFile, extractArchive } from './utils/fileUtils';`
76-
- Import: `import { processContent, splitMarkdown } from './utils/contentUtils';`
86+
- `IngesterFactory`: Factory for creating ingesters.
87+
- Used in: `packages/ingester/src/chat/completionsEmbeddings.ts`
88+
- Import: `import { IngesterFactory } from './IngesterFactory';`
89+
- `utils`: Utility functions for ingestion.
90+
- Used in: `packages/ingester/src/ingesters/MarkdownIngester.ts`
91+
- Import: `import { processDocFiles } from '../utils/fileUtils';`
92+
- Import: `import { isInsideCodeBlock, calculateHash } from '../utils/contentUtils';`
7793

7894
## Common Import Patterns
7995

8096
### For Backend API Routes
8197
```typescript
82-
import express from 'express';
83-
import { generateHandler } from '../handlers/generateHandler';
84-
import { config } from '../config';
98+
import express, { Router } from 'express';
99+
import { AIMessage, HumanMessage, SystemMessage, BaseMessage } from '@langchain/core/messages';
100+
import { v4 as uuidv4 } from 'uuid';
101+
import {
102+
getVectorDbConfig,
103+
logger,
104+
RagAgentFactory,
105+
LLMConfig,
106+
VectorStore,
107+
} from '@cairo-coder/agents';
85108
```
86109

87110
### For Agent Core
88111
```typescript
89-
import { VectorStore } from './db/vectorStore';
90-
import { LLMProviderFactory } from './models/llmProviderFactory';
91-
import { EmbeddingProviderFactory } from './models/embeddingProviderFactory';
112+
import { BaseMessage } from '@langchain/core/messages';
113+
import { Embeddings } from '@langchain/core/embeddings';
114+
import { getAgentConfig } from '../config/agent';
115+
import { RagPipeline } from './pipeline/ragPipeline';
116+
import { VectorStore } from '../db/vectorStore';
117+
import { LLMConfig } from '../types';
92118
```
93119

94120
### For Ingesters
95121
```typescript
122+
import * as fs from 'fs/promises';
123+
import * as path from 'path';
124+
import { Document } from '@langchain/core/documents';
125+
import { BookChunk, DocumentSource } from '@cairo-coder/agents/types/index';
96126
import { BaseIngester } from '../BaseIngester';
97-
import { BookPageDto, ParsedSection, BookChunk } from '../types';
98-
import { Document } from 'langchain/document';
99-
import { VectorStore } from '../../agents/src/db/vectorStore';
127+
import { BookConfig, BookPageDto, ParsedSection } from '../utils/types';
100128
```

.cursor/rules/navigation.mdc

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,105 @@
1-
---
2-
description:
3-
globs:
4-
---
5-
# Navigation Rules for Starknet Agent Codebase
1+
# Navigation Rules for Cairo Coder Codebase
62

73
## Project Structure Overview
84

9-
The Starknet Agent codebase is organized as a monorepo with multiple packages:
5+
The Cairo Coder codebase is organized as a monorepo with multiple packages:
106

11-
- `packages/agents`: Contains the core agent logic for RAG-based search and response generation
12-
- `packages/backend`: Express-based server handling WebSocket connections and API endpoints
13-
- `packages/ui`: Next.js frontend application
14-
- `packages/ingester`: Tools for ingesting and processing data for the vector database
7+
- `packages/agents`: Contains the core agent logic for RAG-based Cairo code generation
8+
- `packages/backend`: Express-based server handling API endpoints for code generation
9+
- `packages/ingester`: Tools for ingesting and processing Cairo documentation for the vector database
1510
- `packages/typescript-config`: Shared TypeScript configuration
1611

1712
## Key Directories and Files
1813

1914
### Agent Logic
20-
- `packages/agents/src/pipeline`: Contains the RAG pipeline implementation
15+
- `packages/agents/src/core/pipeline`: Contains the RAG pipeline implementation
16+
- `ragPipeline.ts`: Orchestrates the entire RAG process
17+
- `queryProcessor.ts`: Processes and reformulates user queries
18+
- `documentRetriever.ts`: Retrieves relevant documents from vector database
19+
- `answerGenerator.ts`: Generates Cairo code based on retrieved documents
2120
- `packages/agents/src/core`: Core agent functionality
22-
- `packages/agents/src/config`: Configuration handling
21+
- `agentFactory.ts`: Factory for creating RAG agents
2322
- `packages/agents/src/db`: Database interaction logic
23+
- `packages/agents/src/config`: Configuration handling
2424
- `packages/agents/src/utils`: Utility functions
25-
- `packages/agents/src/lib`: Shared libraries
26-
- `packages/agents/src/ragAgentFactory.ts`: Factory for creating RAG agents
27-
- `packages/agents/src/suggestionGeneratorAgent.ts`: Agent for generating search suggestions
25+
- `packages/agents/src/types`: TypeScript type definitions
2826

2927
### Backend
30-
- `packages/backend/src/websocket`: WebSocket server implementation
31-
- `packages/backend/src/routes`: API route definitions
28+
- `packages/backend/src/api`: API routes and handlers
29+
- `cairocoder.ts`: Main handler for the Cairo code generation endpoint
30+
- `routes.ts`: API route definitions
31+
- `config.ts`: API configuration
3232
- `packages/backend/src/app.ts`: Express application setup
3333
- `packages/backend/src/server.ts`: Server initialization
3434
- `packages/backend/src/config`: Server configuration
35-
- `packages/backend/src/utils`: Utility functions
3635

37-
### Frontend
38-
- `packages/ui/app`: Next.js app directory with page components
39-
- `packages/ui/components`: Reusable UI components
40-
- `packages/ui/lib`: Frontend utilities and helpers
41-
- `packages/ui/public`: Static assets
42-
43-
### Data Ingestion
44-
- `packages/ingester/scripts`: Scripts for data ingestion and embedding generation
36+
### Ingestion System
37+
- `packages/ingester/src/`: Source code for the ingester package
38+
- `BaseIngester.ts`: Abstract base class for all ingesters
39+
- `IngesterFactory.ts`: Factory for creating ingesters based on source
40+
- `generateEmbeddings.ts`: Main script for generating embeddings
41+
- `ingesters/`: Source-specific ingester implementations
42+
- `CairoBookIngester.ts`: Ingester for Cairo Book
43+
- `CairoByExampleIngester.ts`: Ingester for Cairo By Example
44+
- `StarknetDocsIngester.ts`: Ingester for Starknet Docs (may be used for Cairo docs)
45+
- `StarknetFoundryIngester.ts`: Ingester for Starknet Foundry
46+
- `OpenZeppelinDocsIngester.ts`: Ingester for OpenZeppelin Docs
47+
- `MarkdownIngester.ts`: Base ingester for Markdown format docs
48+
- `AsciiDocIngester.ts`: Base ingester for AsciiDoc format docs
49+
- `utils/`: Utility functions for ingestion
50+
- `shared.ts`: Shared types and interfaces
4551

4652
## Navigation Patterns
4753

4854
1. **Following the RAG Pipeline Flow**:
49-
- Start at `packages/agents/src/ragAgentFactory.ts`
50-
- Explore the pipeline components in `packages/agents/src/pipeline`
51-
- Understand how results are sent back via `packages/backend/src/websocket`
55+
- Start at `packages/agents/src/core/agentFactory.ts`
56+
- Explore the pipeline components in `packages/agents/src/core/pipeline/`
57+
- See how code generation happens in `packages/agents/src/core/pipeline/answerGenerator.ts`
5258

5359
2. **Understanding API Endpoints**:
5460
- Start at `packages/backend/src/app.ts`
55-
- Follow through to `packages/backend/src/routes`
56-
- See how they connect to agent functionality
57-
58-
3. **Exploring the UI Flow**:
59-
- Start at `packages/ui/app/page.tsx` (main entry point)
60-
- Look at the chat interface components
61-
- Understand how the UI connects to the backend via WebSockets
61+
- Follow through to `packages/backend/src/api/routes.ts`
62+
- Examine the main handler in `packages/backend/src/api/cairocoder.ts`
6263

63-
4. **Configuration Flow**:
64-
- Check `packages/agents/config.toml` for agent configuration
65-
- See how configuration is loaded in `packages/agents/src/config.ts`
64+
3. **Configuration Flow**:
65+
- Look for configuration files in the root directory
66+
- Check `packages/agents/src/config/` for agent configuration
67+
- See how configuration is loaded in backend via `packages/backend/src/config/`
6668

6769
## Common Navigation Tasks
6870

69-
- **To understand the RAG process**: Follow the pipeline components in `packages/agents/src/pipeline`
70-
- **To see how user queries are processed**: Start at the WebSocket handlers in `packages/backend/src/websocket`
71-
- **To explore the UI components**: Look at the components in `packages/ui/components`
72-
- **To understand data ingestion**: Check the scripts in `packages/ingester/scripts`
73-
74-
## Ingester Package
75-
- `packages/ingester/src/`: Source code for the ingester package
76-
- `BaseIngester.ts`: Abstract base class for all ingesters
77-
- `IngesterFactory.ts`: Factory for creating ingesters based on source
78-
- `ingesters/`: Source-specific ingester implementations
79-
- `CairoBookIngester.ts`: Ingester for Cairo Book
80-
- `StarknetDocsIngester.ts`: Ingester for Starknet Docs
81-
- `StarknetFoundryIngester.ts`: Ingester for Starknet Foundry
82-
- `CairoByExampleIngester.ts`: Ingester for Cairo By Example
83-
- `OpenZeppelinDocsIngester.ts`: Ingester for OpenZeppelin Docs
84-
- `utils/`: Utility functions
85-
- `fileUtils.ts`: File operations
86-
- `contentUtils.ts`: Content processing
87-
- `vectorStoreUtils.ts`: Vector store operations
88-
- `types.ts`: Common types and interfaces
89-
- `scripts/`: Scripts for running ingestion
90-
- `generateEmbeddings.ts`: Main script for generating embeddings
71+
- **To understand the RAG process**: Follow the pipeline components in `packages/agents/src/core/pipeline/`
72+
- **To see how user queries are processed**: Start at the API handlers in `packages/backend/src/api/cairocoder.ts`
73+
- **To understand data ingestion**: Check the ingester implementations in `packages/ingester/src/ingesters/`
74+
- **To modify embeddings generation**: Look at `packages/ingester/src/chat/completionsEmbeddings.ts`
9175

9276
## Key Files for Common Tasks
9377

9478
### Adding a New Documentation Source
9579
1. Create a new ingester in `packages/ingester/src/ingesters/`
9680
2. Update `IngesterFactory.ts` to include the new source
97-
3. Update the `DocumentSource` type in `packages/agents/src/types.ts`
81+
3. Update the document source types in `packages/agents/src/types/`
9882

9983
### Modifying the RAG Pipeline
100-
1. Update the relevant component in `packages/agents/src/pipeline/`
101-
2. Adjust the configuration in `packages/agents/config.toml` if needed
84+
1. Update the relevant component in `packages/agents/src/core/pipeline/`
85+
2. Adjust the pipeline configuration in `packages/agents/src/core/agentFactory.ts` if needed
10286

103-
### Updating the UI
104-
1. Modify the relevant component in `packages/ui/components/`
105-
2. Update styles in `packages/ui/styles/` if needed
87+
### Adding or Modifying API Endpoints
88+
1. Update route definitions in `packages/backend/src/api/routes.ts`
89+
2. Implement handlers in `packages/backend/src/api/cairocoder.ts` or add new handlers
10690

10791
### Running Ingestion
108-
1. Use the script at `packages/ingester/src/scripts/generateEmbeddings.ts`
109-
2. Or run `pnpm run generate-embeddings` from the project root
92+
1. Use the script at `packages/ingester/src/chat/completionsEmbeddings.ts`
93+
2. Or run `pnpm generate-embeddings` from the project root
94+
95+
## Key Endpoints
96+
97+
- `/chat/completions`: Main endpoint for Cairo code generation
98+
- Accepts POST requests with messages array in OpenAI format
99+
- Returns generated Cairo code
100+
101+
## Docker and Deployment Files
102+
103+
- `docker-compose.yml`: Main Docker Compose configuration
104+
- `backend.dockerfile`: Dockerfile for the backend service
105+
- `ingest.dockerfile`: Dockerfile for running ingestion tasks

0 commit comments

Comments
 (0)