File size: 7,234 Bytes
b8ea7be
 
 
 
 
 
 
 
 
 
 
5cd89db
f2f397e
 
 
 
 
 
 
5cd89db
f2f397e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cd89db
f2f397e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cd89db
 
f2f397e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5cd89db
f2f397e
 
5cd89db
f2f397e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
---
title: RepoAnalyzer
emoji: ⚡
colorFrom: yellow
colorTo: purple
sdk: docker
pinned: false
short_description: analyze repo and provide documentation about repo
---


# RepoAnalyzer 🧙‍♂️

> AI-powered code documentation and search agent — paste a GitHub URL, get professional docs in seconds.

---

## What It Does

RepoAnalyzer takes any public GitHub repository, reads every Python file, and automatically generates clean human-readable documentation using AI. It also lets developers search the codebase in plain English — no more digging through files manually.

**Core features:**
- Generates documentation for every file in a repo with one click
- Answers natural language questions about the codebase
- Semantic search powered by FAISS vector embeddings
- Download individual file docs or all docs as a ZIP
- Auto-generates README.md and .gitignore for any project

---

## Tech Stack

| Layer | Technology |
|-------|------------|
| Backend | Python 3.10+, FastAPI, Uvicorn |
| LLM | OpenRouter API (qwen/qwen3-coder:free) |
| Embeddings | sentence-transformers (all-MiniLM-L6-v2) |
| Vector Search | FAISS (faiss-cpu) |
| Code Parsing | Python AST (built-in) |
| GitHub Access | GitHub REST API v3 |
| Frontend | React 18, Vite, Tailwind CSS |
| File Handling | JSZip (client-side ZIP generation) |

**Total cost to run: $0** — all free tier services, no credit card required.

---

## Project Structure

```
RepoAnalyzer/
├── backend/
│   ├── main.py              # FastAPI app, all API endpoints
│   ├── doc_generator.py     # OpenRouter API calls, doc generation logic
│   ├── parser.py            # AST-based Python code parser
│   ├── vector_store.py      # FAISS index creation and semantic search
│   ├── github_client.py     # GitHub API, repo file fetching
│   └── requirements.txt     # Python dependencies
├── frontend/
│   └── src/
│       ├── App.jsx          # Main React component, full UI
│       └── components/      # UI sub-components
├── faiss_indexes/           # Auto-generated, gitignored
├── .env                     # Your API keys, gitignored
├── .env.example             # Template for environment variables
├── .gitignore
└── README.md
```

---

## Prerequisites

Make sure these are installed on your machine before starting:

- [Python 3.10+](https://www.python.org/downloads/)
- [Node.js 18+](https://nodejs.org/)
- [Git](https://git-scm.com/)

---

## Installation

### 1. Clone the repository

```bash
git clone https://github.com/yourusername/repoanalyzer.git
cd repoanalyzer
```

### 2. Get your API keys

**OpenRouter API key** (free, no credit card):
1. Go to [openrouter.ai](https://openrouter.ai)
2. Sign up → Profile → Keys → Create Key
3. Copy the key (starts with `sk-or-...`)

**GitHub Personal Access Token** (free):
1. Go to GitHub → Settings → Developer settings
2. Personal access tokens → Tokens (classic) → Generate new token
3. Check only the `repo` scope → Generate → Copy the token (starts with `ghp_...`)

### 3. Set up environment variables

```bash
cp .env.example .env
```

Open `.env` and fill in your keys:

```env
OPENROUTER_API_KEY=sk-or-your-key-here
GITHUB_TOKEN=ghp_your-token-here
LLM_MODEL=qwen/qwen3-coder:free
```

### 4. Install backend dependencies

```bash
cd backend
pip install "numpy<2"
pip install -r requirements.txt
```

> **Windows note:** If `faiss-cpu` fails to install, run `pip install faiss-cpu --prefer-binary` instead.

### 5. Install frontend dependencies

```bash
cd ../frontend
npm install
```

---

## Running the App

You need two terminals open simultaneously.

**Terminal 1 — Backend:**
```bash
cd backend
uvicorn main:app --reload
```
Backend runs at `http://127.0.0.1:8000`

**Terminal 2 — Frontend:**
```bash
cd frontend
npm run dev
```
Frontend runs at `http://localhost:5173`

Open `http://localhost:5173` in your browser.

---

## How to Use

1. Paste any public GitHub repository URL into the input field
   - Example: `https://github.com/tiangolo/fastapi`
2. Click **Generate Docs** and wait 10–30 seconds
3. Documentation appears for every Python file in the repo
4. Click any file card to expand and read its docs
5. Use the **Copy** or **Download .md** button on each card
6. Click **Download All as ZIP** to get everything at once
7. Type a question in the search bar to query the codebase
   - Example: *"How do I handle authentication?"*
8. Click **Generate README** to create a README for that repo
9. Click **Generate .gitignore** for a project-specific gitignore

---

## API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/generate-docs` | Generate docs for a GitHub repo |
| POST | `/ask` | Ask a natural language question |
| POST | `/generate-readme` | Generate a README.md for the repo |
| POST | `/generate-gitignore` | Generate a .gitignore for the repo |

**Example request:**
```bash
curl -X POST http://localhost:8000/generate-docs \
  -H "Content-Type: application/json" \
  -d '{"repo_url": "https://github.com/tiangolo/fastapi"}'
```

---

## Environment Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `OPENROUTER_API_KEY` | Your OpenRouter API key | Yes |
| `GITHUB_TOKEN` | GitHub personal access token | Yes |
| `LLM_MODEL` | Model to use (default: `qwen/qwen3-coder:free`) | No |

---

## Known Limitations

- **Free tier rate limits:** OpenRouter free tier allows 50 requests/day and 20 requests/minute. RepoAnalyzer batches all files into one request to stay within this limit.
- **Python only:** The AST parser currently supports Python files only. JavaScript and other languages are planned for a future update.
- **Public repos only:** Private repositories require additional GitHub token scopes.
- **Context window:** Very large repos (100+ files) may exceed the model's context window. RepoAnalyzer will document as many files as fit.

---

## Troubleshooting

**`uvicorn main:app --reload` gives NumPy error:**
```bash
pip install "numpy<2" --force-reinstall
```

**Search returns 0 results:**
Generate docs first before searching — the search index is built during doc generation.

**Rate limit error but OpenRouter shows 0 requests:**
Your `.env` file is not being loaded. Make sure `load_dotenv()` is called at the top of `doc_generator.py` and your `.env` file is in the `backend/` folder.

**`npm run dev` fails:**
Make sure you ran `npm install` inside the `frontend/` folder first.

---

## Roadmap

- [ ] JavaScript / TypeScript support
- [ ] Private repository support
- [ ] GitHub Action for auto-updating docs on push
- [ ] Change detection — only re-document modified files
- [ ] Architecture diagram generation
- [ ] Multi-language support (Java, Go, Rust)

---

## License

MIT License — free to use, modify, and distribute.

---

## Acknowledgements

- [OpenRouter](https://openrouter.ai) for free LLM access
- [FAISS](https://github.com/facebookresearch/faiss) by Meta for vector search
- [sentence-transformers](https://www.sbert.net/) for local embeddings
- [FastAPI](https://fastapi.tiangolo.com/) for the backend framework