Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.env
.agent
app/data/app.db
70 changes: 16 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,70 +50,32 @@ docker-compose up -d

## 💻 本地开发

### 前置要求

- Python 3.13
- Node.js 24
- npm

### 环境配置

创建 `api/.env` 文件配置环境变量:

```env
# 数据库配置
DATABASE_URL=sqlite+aiosqlite:///./data/app.db
# DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/dbname

# JWT 配置
SECRET_KEY=your-secret-key-here
ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7
ALGORITHM=HS256
```sh
# 启动(带日志)
docker compose -f docker-compose.dev.yml up
```

### 后端设置
更多命令

```bash
cd api
```sh
# 后台启动
docker compose -f docker-compose.dev.yml up -d

# 创建虚拟环境
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# 查看日志
docker compose -f docker-compose.dev.yml logs -f

# 安装依赖
pip install uv
uv sync

# 运行数据库迁移
alembic upgrade head
# 停止
docker compose -f docker-compose.dev.yml down

# 启动开发服务器
python main.py
# 重新构建(如果修改了依赖)
docker compose -f docker-compose.dev.yml up --build
```

后端将在 http://localhost:8000 运行

### 前端设置

```bash
cd web

# 安装依赖
npm install

# 启动开发服务器
npm run dev
```

前端将在 http://localhost:5173 运行

## 📖 API 文档
前端开发服务器:http://localhost:5173

启动后端服务后,访问以下地址查看自动生成的 API 文档:
后端 API:http://localhost:8000

- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API 文档:http://localhost:8000/docs

## 📚 数据库迁移

Expand Down
10 changes: 10 additions & 0 deletions api/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles

Expand All @@ -29,6 +30,15 @@ async def lifespan(app: FastAPI):

app = FastAPI(lifespan=lifespan)

# 配置 CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.include_router(auth.router)
app.include_router(users.router)
app.include_router(workspaces.router)
Expand Down
52 changes: 52 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
services:
# 后端服务
backend:
image: python:3.13-slim
container_name: archivenote-backend-dev
working_dir: /app
ports:
- "8000:8000"
volumes:
- ./api:/app
- ./app/data:/app/data
environment:
- SECRET_KEY=dev-secret-key-change-in-production
# - DATABASE_URL=sqlite+aiosqlite:///./data/app.db
- DATABASE_URL=postgresql+asyncpg://postgres:postgres@postgres:5432/archivenote
command: >
bash -c "pip install uv &&
uv sync &&
uv run python -m alembic upgrade head &&
uv run python -m uvicorn app.app:app --host 0.0.0.0 --port 8000 --reload"
restart: unless-stopped

# 前端服务
frontend:
image: node:24-alpine
container_name: archivenote-frontend-dev
working_dir: /app
ports:
- "5173:5173"
volumes:
- ./web:/app
- /app/node_modules
environment:
- VITE_API_BASE_URL=http://localhost:8000/api
command: sh -c "npm install && npm run dev -- --host"
restart: unless-stopped

postgres:
image: postgres:17
container_name: archivenote-postgres
restart: always
ports:
- 5432:5432
environment:
POSTGRES_DB: archivenote
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: ['CMD', 'pg_isready', '-U', 'postgres', '-d', 'archivenote']
interval: 5s
timeout: 10s
retries: 5