Files
NovalRedot/CLAUDE.md

3.4 KiB
Raw Blame History

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Language

使用中文作为自然语言对话和注释等语言类工作。

Project Overview

Noval 是一个本地Web形式的小说创作应用集成AI Agent辅助创作。用户运行Python后端 + 浏览器前端。

Development Commands

Backend

cd backend
# 首次安装
py -3 -m venv .venv && .venv/Scripts/pip install -r requirements.txt
# 启动Windows上用 py -3不要用 python3
.venv/Scripts/uvicorn app.main:app --port 8000
# API文档
http://localhost:8000/docs

Frontend

cd frontend
npm install
npm run dev          # 开发服务器 http://localhost:5173
npm run build        # 生产构建
npm run type-check   # TypeScript类型检查

前端Vite代理 /apihttp://127.0.0.1:8000,开发时需同时运行后端。

Architecture

backend/app/
├── main.py              # FastAPI入口CORSlifespan初始化DB
├── database.py          # SQLite (backend/data/noval.db)SQLModel engine
├── models.py            # ORM: Novel, Outline, AIConfig, ChatMessage
├── schemas.py           # Pydantic请求/响应模型
├── routers/             # REST API路由
│   ├── novels.py        # /api/novels — 小说CRUD
│   ├── outlines.py      # /api/novels/{id}/outlines — 大纲CRUD+排序
│   ├── ai_config.py     # /api/ai/config — AI服务配置
│   └── chat.py          # /api/chat/stream — SSE流式对话
└── services/
    └── ai_provider.py   # AI抽象层OpenAI兼容 + Anthropic原生httpx直调无SDK

frontend/src/
├── api/                 # Axios封装 + 各资源APInovels, outlines, chat
├── types/               # TypeScript接口定义
├── composables/         # Vue组合式函数useChatAgent, useToast
├── components/
│   ├── ui/              # 基础组件BaseButton, BaseInput, BaseModal等
│   ├── novel/           # 小说卡片、网格、空状态
│   ├── outline/         # 卷轴时间线、节点卡片、表单
│   └── chat/            # 聊天面板、消息气泡、AI配置弹窗
├── views/               # 页面视图
└── style/               # CSS变量、重置、排版、动画

Key Patterns

  • 后端FastAPI + SQLModel + SQLite同步Session路由按资源分文件
  • 前端Vue 3 Composition API + TypeScript纯手写UI组件无组件库
  • AI集成不用SDKhttpx直调OpenAI/Anthropic HTTP APISSE流式输出
  • 聊天状态useChatAgent() 使用模块级ref实现全局共享
  • 流式处理:后端 StreamingResponse → 前端 fetch + ReadableStream 解析SSE

Design System — "墨韵书斋"

CSS变量定义在 frontend/src/style/variables.css

  • 墨色系(--ink-)、纸色系(--paper-)、朱砂红(--vermilion)、竹青(--bamboo)
  • 字体Noto Serif SC标题、Crimson Pro正文

API Structure

前缀 说明
/api/novels 小说CRUDPATCH部分更新
/api/novels/{id}/outlines 大纲CRUD + PUT /reorder 排序
/api/ai/config AI配置读写 + POST /test 测试连接
/api/chat/stream SSE流式对话返回content/usage/done事件
/api/chat/messages 历史消息查询和清空