Skip to content

Commit c0e1acd

Browse files
committed
fix: project structure
1 parent 79136a7 commit c0e1acd

38 files changed

Lines changed: 104 additions & 86 deletions

AGENTS.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ Environment variables control defaults:
5353
- `CODE_RAG_DATABASE_TYPE`: "chroma" or "qdrant"
5454
- `CODE_RAG_EMBEDDING_MODEL`: Model name
5555
- `CODE_RAG_CHUNK_SIZE`: Characters per chunk
56-
- See `src/config/config.py` for full list
56+
- See `src/code_rag/config/config.py` for full list
5757

5858
### 5. Entry Points
59-
- **CLI** (`code-rag`): Interactive query session
60-
- **MCP Server** (`code-rag-mcp`): Exposes search to AI assistants (Claude, etc.)
59+
- **CLI** (`code-rag-cli`): Interactive query session
60+
- **MCP Server** (`code-rag` or `code-rag-mcp`): Exposes search to AI assistants (Claude, etc.)
6161
- **Embedding Server** (`code-rag-server`): Shared model server for multiple MCP instances
6262

6363
### 6. Shared Embedding Server
@@ -73,24 +73,27 @@ Configuration (via environment):
7373
- `CODE_RAG_SHARED_SERVER_PORT=8199`
7474

7575
Files:
76-
- `src/embedding_server.py` - FastAPI server
77-
- `src/embeddings/http_embedding.py` - HTTP client for embedding
78-
- `src/reranker/http_reranker.py` - HTTP client for reranking
76+
- `src/code_rag/embedding_server.py` - FastAPI server
77+
- `src/code_rag/embeddings/http_embedding.py` - HTTP client for embedding
78+
- `src/code_rag/reranker/http_reranker.py` - HTTP client for reranking
7979

8080
## Quick Start
8181

8282
```bash
8383
# Install
8484
pip install -e .
8585

86-
# Index current directory and start querying
86+
# Run MCP server (default)
8787
code-rag
8888

89+
# Index and start querying via CLI
90+
code-rag-cli
91+
8992
# Index specific repo with different database
90-
code-rag --path /path/to/repo --database qdrant
93+
code-rag-cli --path /path/to/repo --database qdrant
9194

9295
# Force reindexing
93-
code-rag --reindex
96+
code-rag-cli --reindex
9497
```
9598

9699
## Common Tasks
@@ -108,12 +111,12 @@ code-rag --reindex
108111
→ Extend `SyntaxChunker.LANGUAGE_PACKAGES` with tree-sitter binding
109112

110113
**Add new MCP tools?**
111-
→ Update `list_tools()` and `call_tool()` in `src/mcp_server.py`
114+
→ Update `list_tools()` and `call_tool()` in `src/code_rag/mcp_server.py`
112115

113116
## Where to Learn More
114117

115118
- **Implementation details**: See `IMPLEMENTATION.md`
116-
- **Code**: Start with `src/main.py` (CLI orchestration)
119+
- **Code**: Start with `src/code_rag/main.py` (CLI orchestration)
117120
- **Tests**: `pytest` to run test suite
118121
- **Questions?**: Read the code - it's well-structured and follows the plugin pattern
119122

PUBLISH.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ twine upload dist/*
4747

4848
## 7. Versioning
4949
To publish a new version later:
50-
1. Update the version in `pyproject.toml` and `src/__init__.py`.
50+
1. Update the version in `pyproject.toml` and `src/code_rag/__init__.py`.
5151
2. Delete the old `dist/` folder.
5252
3. Repeat steps 3, 4, and 6.

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,25 @@ source .venv/bin/activate
1414
# Install
1515
pip install -e .
1616

17-
# Index and search your codebase
17+
# Start the MCP server (default)
1818
code-rag
1919

20-
# That's it. Start asking questions about your code.
20+
# Or use the interactive CLI search
21+
code-rag-cli
2122
```
2223

23-
## Example
24+
## Example (CLI)
2425

2526
```
26-
$ code-rag --path /home/user/myproject
27+
$ code-rag-cli --path /home/user/myproject
2728
2829
Processing codebase... Found 247 files
2930
Indexed 1,234 chunks in 12s
3031
3132
Query: authentication logic
3233
3334
Result 1 | Similarity: 0.85
34-
File: src/auth/authenticator.py (lines 45-78)
35+
File: src/code_rag/auth/authenticator.py (lines 45-78)
3536
3637
class Authenticator:
3738
"""Handle user authentication and session management."""
@@ -134,7 +135,7 @@ Once configured, Claude can automatically search your codebase:
134135
You: "Find the database connection logic"
135136
136137
Claude: [Automatically searches and finds the code]
137-
"I found the database connection logic in src/db/connection.py..."
138+
"I found the database connection logic in src/code_rag/db/connection.py..."
138139
```
139140

140141
See [docs/mcp.md](docs/mcp.md) for detailed setup and troubleshooting.
@@ -143,19 +144,19 @@ See [docs/mcp.md](docs/mcp.md) for detailed setup and troubleshooting.
143144

144145
```bash
145146
# Different codebase
146-
code-rag --path /path/to/repo
147+
code-rag-cli --path /path/to/repo
147148

148149
# Force reindex
149-
code-rag --reindex
150+
code-rag-cli --reindex
150151

151152
# More results
152-
code-rag --results 10
153+
code-rag-cli --results 10
153154

154155
# Different embedding model (better for code)
155-
code-rag --model text-embedding-3-small # need to set OPENAI_API_KEY env
156+
code-rag-cli --model text-embedding-3-small # need to set OPENAI_API_KEY env
156157

157158
# Use Qdrant instead of ChromaDB
158-
code-rag --database qdrant
159+
code-rag-cli --database qdrant
159160
```
160161

161162
## Configuration
@@ -225,7 +226,7 @@ Pluggable architecture - swap databases, embedding models, or add new ones.
225226
Use programmatically:
226227

227228
```python
228-
from src.api import CodeRAGAPI
229+
from code_rag.api import CodeRAGAPI
229230

230231
api = CodeRAGAPI(database_type="chroma", embedding_model="all-MiniLM-L6-v2")
231232
api.initialize_collection("myproject")

docs/IMPLEMENTATION.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This document contains detailed implementation notes, patterns, and design decis
4141
Each chunk includes:
4242
```python
4343
{
44-
"file_path": "src/example.py",
44+
"file_path": "src/code_rag/example.py",
4545
"chunk_index": 0, # Position in file (0-indexed)
4646
"total_chunks": 5, # Total chunks from this file
4747
"content": "chunk text..." # The actual code chunk
@@ -227,7 +227,7 @@ Embedding models:
227227

228228
### Environment Variables
229229

230-
Located in `src/config/config.py`. All have fallback defaults:
230+
Located in `src/code_rag/config/config.py`. All have fallback defaults:
231231

232232
| Variable | Default | Description |
233233
|----------|---------|-------------|
@@ -403,7 +403,7 @@ elif args.database == "qdrant":
403403
pytest
404404

405405
# With coverage
406-
pytest --cov=src
406+
pytest --cov=code_rag
407407

408408
# Specific module
409409
pytest tests/test_file_processor.py
@@ -419,13 +419,13 @@ pytest tests/test_file_processor.py
419419

420420
```bash
421421
# Format code
422-
black src/
422+
black src/code_rag/
423423

424424
# Lint
425-
flake8 src/
425+
flake8 src/code_rag/
426426

427427
# Type checking (if configured)
428-
mypy src/
428+
mypy src/code_rag/
429429
```
430430

431431
---

docs/mcp.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,21 @@ The **final design** intentionally exposes **one tool only**:
1616
From the project root:
1717

1818
```bash
19-
cd /ub/home/qduc/src/code-rag
19+
cd /ub/home/qduc/src/code_rag/code-rag
2020
pip install -e .
2121
```
2222

2323
This installs:
2424

25-
- `code-rag` (CLI)
26-
- `code-rag-mcp` (MCP server entry point)
25+
- `code-rag` (MCP server - default)
26+
- `code-rag-cli` (CLI search tool)
27+
- `code-rag-mcp` (MCP server alias)
2728
- All required dependencies, including `mcp>=0.9.0`
2829

2930
Verify that the MCP server is on your PATH:
3031

3132
```bash
32-
which code-rag-mcp
33+
which code-rag
3334
```
3435

3536
---
@@ -42,16 +43,16 @@ The MCP server uses stdio transport.
4243

4344
```bash
4445
claude mcp add code-rag \
45-
--type stdio \
46-
-- code-rag-mcp
46+
--transport stdio \
47+
-- code-rag
4748
```
4849

4950
If necessary, you can register it with an explicit path:
5051

5152
```bash
5253
claude mcp add code-rag \
5354
--type stdio \
54-
-- /ub/home/qduc/src/code-rag/.venv/bin/code-rag-mcp
55+
-- /ub/home/qduc/src/code_rag/code-rag/.venv/bin/code-rag-mcp
5556
```
5657

5758
### Manual configuration (JSON)
@@ -182,8 +183,8 @@ model, regardless of this variable.
182183
2. Claude calls:
183184
- `search_codebase(codebase_path="/home/user/myapp", query="user authentication implementation")`
184185
3. Claude returns locations such as:
185-
- `src/auth/authenticator.py` (main authentication logic)
186-
- `src/middleware/auth.py` (authentication middleware)
186+
- `src/code_rag/auth/authenticator.py` (main authentication logic)
187+
- `src/code_rag/middleware/auth.py` (authentication middleware)
187188
4. If the user wants more context, Claude uses its own file-reading capability to show full files.
188189

189190
---
@@ -192,8 +193,8 @@ model, regardless of this variable.
192193

193194
### API and MCP layering
194195

195-
- `CodeRAGAPI` (`src/api.py`) provides a clean, reusable façade over the core Code-RAG pipeline (initialize collection, index, search, get chunks, stats, close).
196-
- `src/mcp_server.py` hosts the MCP server and exposes that API as tools for Claude over stdio.
196+
- `CodeRAGAPI` (`src/code_rag/api.py`) provides a clean, reusable façade over the core Code-RAG pipeline (initialize collection, index, search, get chunks, stats, close).
197+
- `src/code_rag/mcp_server.py` hosts the MCP server and exposes that API as tools for Claude over stdio.
197198
- The same API can later back other interfaces (e.g., HTTP, gRPC) without changing core logic.
198199

199200
### Single-tool, auto-indexing design (final)

pyproject.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
6-
name = "code-rag"
7-
version = "0.1.0"
6+
name = "code-rag-mcp"
7+
version = "0.1.2"
88
description = "MCP server for efficient code search"
99
readme = "README.md"
1010
requires-python = ">=3.10, <3.14"
@@ -60,7 +60,8 @@ dev = [
6060
]
6161

6262
[project.scripts]
63-
code-rag = "code_rag.main:main"
63+
code-rag = "code_rag.mcp_server:main"
64+
code-rag-cli = "code_rag.main:main"
6465
code-rag-mcp = "code_rag.mcp_server:main"
6566
code-rag-server = "code_rag.embedding_server:main"
6667

@@ -69,10 +70,18 @@ Homepage = "https://github.com/qduc/code-rag"
6970
Issues = "https://github.com/qduc/code-rag/issues"
7071

7172
[tool.setuptools]
72-
packages = ["code_rag"]
73+
packages = [
74+
"code_rag",
75+
"code_rag.config",
76+
"code_rag.database",
77+
"code_rag.embeddings",
78+
"code_rag.index",
79+
"code_rag.processor",
80+
"code_rag.reranker",
81+
]
7382

7483
[tool.setuptools.package-dir]
75-
code_rag = "src"
84+
"" = "src"
7685

7786
[tool.black]
7887
line-length = 88

src/__main__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/code_rag/__main__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Allow running the package as a module: python -m code_rag"""
2+
3+
from .mcp_server import main
4+
5+
if __name__ == "__main__":
6+
main()

src/api.py renamed to src/code_rag/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def search(
520520
collection_name: Name of the collection to search (uses active collection if None)
521521
expand_context: If True, fetch adjacent chunks to provide more context
522522
file_types: Optional list of file extensions to filter by (e.g. ['.py', '.md'])
523-
include_paths: Optional list of path substrings to include (e.g. ['src/', 'tests/'])
523+
include_paths: Optional list of path substrings to include (e.g. ['src/code_rag/', 'tests/'])
524524
525525
Returns:
526526
List of search results, each containing:

0 commit comments

Comments
 (0)