abdulsamad183/GitSight-autonomous-se-platform
GitHub: abdulsamad183/GitSight-autonomous-se-platform
GitSight 是一个融合 Tree-sitter 静态解析、pgvector 向量检索与 LLM 的自主软件工程平台,用于对 GitHub 仓库进行代码理解、搜索、文档生成和 PR 审查。
Stars: 0 | Forks: 0
# GitSight
GitSight 是一个用于感知代码仓库的软件工程开源平台。粘贴公开的 GitHub URL 即可分析代码结构,搜索已索引的 symbol,探索依赖图,与基于你的代码库的 LLM 进行聊天,生成文档以及审查 pull request。
**状态:** v0.1.0
## 核心功能
- **代码仓库分析** — 克隆 GitHub 仓库,使用 Tree-sitter 解析源文件,提取 symbol 和依赖,并通过分阶段进度跟踪分析任务。
- **代码索引** — 对源文件进行分块,并将 384 维 embedding 存储在带有 pgvector 的 PostgreSQL 中,以实现语义检索。
- **混合搜索** — 支持对已索引代码块进行关键词、语义和混合搜索模式。
- **依赖图** — 文件和导入的交互式结构图 (React Flow)。
- **代码仓库聊天** — 基于 RAG 从已索引块中检索并与 LLM 聊天,辅以工具辅助的上下文收集。
- **文档生成** — 根据分析过的代码,由 AI 生成代码仓库文档。
- **Pull request 审查** — 借助 diff 和 graph 上下文,由 LLM 驱动的 PR 审查。
- **身份验证** — 通过 HTTP-only JWT cookie 进行注册、登录和 session 管理。
## 技术栈
| 层级 | 技术 |
|-------|------------|
| Frontend | Next.js, React, TypeScript, Tailwind CSS, shadcn/ui, TanStack Query, React Flow |
| Backend | FastAPI, Python 3.11, SQLAlchemy 2.x, Alembic, Pydantic v2, asyncpg |
| Database | 带 pgvector 的 PostgreSQL(生产环境使用 Supabase) |
| Parsing | Tree-sitter (Python, JavaScript, TypeScript, Go, C, C++) |
| AI / LLM | Groq API |
| Embeddings | fastembed(本地开发)或 Google Gemini Embedding API(生产环境) |
| Deployment | Vercel (Frontend), Render (Backend), Supabase (Database) |
## 架构概述
```
┌─────────────────┐ HTTP ┌─────────────────┐ asyncpg ┌─────────────────┐
│ Next.js (Web) │ ────────────► │ FastAPI (API) │ ─────────────► │ PostgreSQL │
│ Vercel │ │ Render │ │ (pgvector) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │
│ /api/* rewrites (production) │ Groq API, Google Embeddings API,
└──────────────────────────────────┘ GitHub API, Git clone
```
**请求流程:** Browser → Next.js (Vercel) → FastAPI endpoint → 服务层 → 仓库层 → PostgreSQL。
**分析 pipeline:** Clone repo → 扫描文件 → Tree-sitter 解析 → 提取 symbol/依赖 → 代码分块 → 生成 embedding → 存储至 `chunk_embeddings` → 启用搜索、聊天和 PR 审查。
更多详情,请参阅 [docs/architecture.md](docs/architecture.md)。
## 前置条件
- [uv](https://docs.astral.sh/uv/) (Python 包管理器)
- Node.js 20+
- 带有 [pgvector](https://github.com/pgvector/pgvector) 扩展的 PostgreSQL 16+(Supabase 已提供此扩展)
- API key:
- [Groq](https://console.groq.com/) — 聊天、文档和 PR 审查必需
- [GitHub](https://github.com/settings/tokens) — 建议使用,以提高 GitHub API 的 rate limit
- [Google AI](https://aistudio.google.com/apikey) — 生产环境中当 `EMBEDDING_PROVIDER=google` 时必需
- Docker(可选,用于容器化的本地开发)
## 本地设置
### 1. Clone 代码仓库
```
git clone https://github.com/abdulsamad183/GitSight-autonomous-se-platform.git
cd GitSight-autonomous-se-platform
```
### 2. 配置环境变量
```
cp backend/.env.example backend/.env
cp frontend/.env.local.example frontend/.env.local
```
使用你自己的值编辑这两个文件。请参阅下方的[环境变量](#environment-variables)部分。
### 3. 数据库
创建一个启用 pgvector 的 PostgreSQL 数据库,然后在 `backend/.env` 中设置 `DATABASE_URL`:
```
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/gitsight
```
运行数据库迁移:
```
cd backend
uv sync --extra dev
uv run alembic upgrade head
```
### 4. 安装依赖
**Backend:**
```
cd backend
uv sync --extra dev
```
**Frontend:**
```
cd frontend
npm install
```
### 5. Docker(可选)
在代码仓库根目录下运行:
```
docker compose up --build
```
这将使用你的 `.env` 文件,在端口 8000 启动 Backend,并在端口 3000 启动 Frontend。
## 环境变量
环境变量模板位于:
- **Backend:** [`backend/.env.example`](backend/.env.example)
- **Frontend:** [`frontend/.env.local.example`](frontend/.env.local.example)
### Backend(本地开发必需)
| 变量 | 描述 |
|----------|-------------|
| `DATABASE_URL` | 异步 PostgreSQL URL (`postgresql+asyncpg://...`) |
| `SECRET_KEY` | JWT 签名密钥(在生产环境中请使用至少 32 个字符的随机字符串) |
| `GROQ_API_KEY` | 用于 LLM 功能的 Groq API key |
### Backend(推荐)
| 变量 | 描述 |
|----------|-------------|
| `GITHUB_TOKEN` | 用于仓库克隆和 PR 同步的 GitHub 个人访问 token |
### Frontend
| 变量 | 描述 |
|----------|-------------|
| `NEXT_PUBLIC_API_URL` | Backend API 的基础 URL(例如 `http://localhost:8000`) |
| `NEXT_PUBLIC_API_PROXY` | 在 Vercel 上设置为 `true`,以便将 `/api/*` 代理到 backend |
有关可选的调优变量(搜索权重、embedding 设置、LLM 模型、索引限制),请参阅 `.env.example` 文件。
## 运行应用程序
### Backend
```
cd backend
uv run uvicorn app.main:app --reload
```
API:`http://localhost:8000`
健康检查:`GET /health` 和 `GET /health/ready`
### Frontend
```
cd frontend
npm run dev
```
App:`http://localhost:3000`
### 开发命令
**Backend:**
```
cd backend
uv run pytest
uv run black app tests
uv run isort app tests
uv run flake8 app tests
```
**Frontend:**
```
cd frontend
npm run lint
npm test
npm run build
```
## 部署概述
GitSight 旨在作为三个服务运行:
| 服务 | 平台 | 说明 |
|---------|----------|-------|
| Frontend | [Vercel](https://vercel.com) | 根目录:`frontend` |
| Backend API | [Render](https://render.com) | Docker Web 服务;请参阅 `infrastructure/render.yaml` |
| Database | [Supabase](https://supabase.com) | 带 pgvector 的 PostgreSQL;使用连接池(端口 6543) |
**生产环境请求路径:** 浏览器在 Vercel 上调用同源的 `/api/*`。Next.js 通过重写将这些请求代理到 Render 上的 backend。Auth cookie 会签发在 Vercel 域名上。
### 部署清单
1. **Supabase** — 创建一个项目并复制异步连接池的 `DATABASE_URL`。如果尚未启用 pgvector,请将其启用。
2. **Render** — 使用 `infrastructure/render.yaml` 部署 backend,或者连接代码仓库并将 `backend/` 设为根目录。设置 `ENV=production`、`DATABASE_URL`、`SECRET_KEY`、`GROQ_API_KEY`、`GITHUB_TOKEN`、`CORS_ORIGINS`、`EMBEDDING_PROVIDER=google` 和 `GOOGLE_API_KEY`。数据库迁移通过 Render blueprint 中的 pre-deploy 命令运行。
3. **Vercel** — 部署 `frontend/`,将 `NEXT_PUBLIC_API_URL` 指向你的 Render backend URL,并设置 `NEXT_PUBLIC_API_PROXY=true`。
4. **验证** — 确认 `GET /health/ready` 返回 200,然后注册、登录并分析一个公开的 GitHub 仓库。
**Render 的 CORS 示例:**
```
CORS_ORIGINS=["https://your-app.vercel.app","https://your-service.onrender.com"]
```
## 项目结构
```
GitSight-autonomous-se-platform/
├── backend/ # FastAPI API (uv-managed)
│ ├── app/
│ │ ├── api/ # HTTP route handlers
│ │ ├── core/ # Config, database, security
│ │ ├── models/ # SQLAlchemy ORM models
│ │ ├── repositories/ # Data access layer
│ │ ├── schemas/ # Pydantic request/response models
│ │ └── services/ # Business logic (analysis, indexing, AI, search)
│ ├── alembic/ # Database migrations
│ ├── tests/
│ └── .env.example
├── frontend/ # Next.js web application
│ ├── src/
│ │ ├── app/ # App Router pages
│ │ ├── components/ # UI components
│ │ ├── hooks/ # React hooks
│ │ ├── services/ # API client functions
│ │ └── types/ # TypeScript types
│ └── .env.local.example
├── docs/ # Architecture documentation
├── infrastructure/ # Deployment configs (Render blueprint)
├── .github/workflows/ # CI workflows
├── docker-compose.yml # Local development with Docker
├── CONTRIBUTING.md
├── LICENSE
└── README.md
```
## 路线图
### 已完成
- [x] 用户身份验证(注册、登录、JWT cookie)
- [x] 代码仓库接入和多分支分析
- [x] Tree-sitter AST 解析与 symbol 提取
- [x] 代码分块和 pgvector embedding
- [x] 关键词、语义和混合搜索
- [x] 感知代码仓库的 AI 聊天(基于 RAG)
- [x] 文档生成
- [x] Pull request 审查自动化
- [x] 依赖结构图可视化
### 计划中
- [ ] 私有仓库支持(GitHub OAuth / PAT)
- [ ] 自动 Bug 检测
- [ ] 工程审计和代码质量报告
- [ ] 增量重新索引改进
- [ ] 在 Tree-sitter 解析器中支持更多语言
## 贡献
欢迎贡献。请阅读 [CONTRIBUTING.md](CONTRIBUTING.md) 了解开发工作流、代码规范和 pull request 指南。
## 许可证
本项目基于 MIT 许可证授权。详情请参阅 [LICENSE](LICENSE)。
标签:RAG, 仓库分析, 代码智能, 代码检索, 测试用例, 请求拦截, 软件开发, 逆向工具