This file offers comprehensive guidance for Claude Code (claude.ai/code) when working with the BookWith project codebase.
Last updated: 2025-06-29
Project Version: v0.1.0
Supported Claude Code: claude.ai/code
This project is an AI-powered next-generation browser-based ePub reader called "BookWith".
Differentiators from conventional e-book readers:
- Interactive reading with an AI assistant that understands the book's content
- Multi-tier memory system: short-, mid-, and long-term memory for context retention
- Semantic search: discover related information via vector search
- Integrated annotation: seamless integration of highlights, notes, and AI conversations
- Reading continuity: a continuous reading experience across sessions
Target users:
- Academic researchers (deep understanding of papers and technical books)
- Avid readers (enhanced enjoyment of novels and general-interest books)
- Learners (efficient study with textbooks and reference books)
- Business professionals (grasp key points of business books and reports)
Turbo + pnpm Workspaces
packages:
- 'apps/*' # applications
- 'packages/*' # shared libraries
Directory Structure
- apps/api/: FastAPI backend (Python 3.13+)
- Dependency management with Poetry
- DDD layered architecture
- Automatic OpenAPI generation
- apps/reader/: Next.js frontend (TypeScript/React)
- App Router + Turbopack
- Automatic type generation (OpenAPI → TypeScript)
- State management with Valtio
- packages/: Shared libraries (planned)
- Shared type definitions
- Utility functions
- Common components
DDD (Domain-Driven Design) layered architecture:
- Domain Layer (
src/domain/): Entities, value objects, repository interfaces - UseCase Layer (
src/usecase/): Application-specific business logic - Infrastructure Layer (
src/infrastructure/): Integration with external tech (DB, DI, memory) - Presentation Layer (
src/presentation/): FastAPI routes & schemas
# 1. Install dependencies (repo root)
pnpm i
# 2. Set environment variables
cd apps/api
cp src/config/.env.example src/config/.env
# Edit .env (set API keys, etc.)
# 3. Start Docker services (Weaviate + GCS emulator)
make docker.up
# 4. Launch API in dev mode
make configure # poetry install --no-root
make run # FastAPI on port 8000
# 5. Launch frontend in another terminal
cd apps/reader
pnpm dev # Next.js on port 7127
# Or launch everything at once (repo root)
pnpm dev # turbo run dev --parallel# Build all
pnpm build # turbo run build
# Lint all
pnpm lint # turbo run lint
# API lint & type-check
cd apps/api
make lint # mypy + pre-commit
# Frontend type-check
cd apps/reader
pnpm ts:check # tsc --noEmitcd apps/api
# Start dev server
make run
# Lint & type-check
make lint
# Run via Docker
make docker.up
# Generate OpenAPI schema (for frontend)
cd ../reader
pnpm openapi:ts- FastAPI – web framework
- SQLAlchemy – ORM (PostgreSQL)
- Pydantic – data validation
- Weaviate – vector DB (memory)
- LangChain – LLM integration
- OpenAI API – GPT-4 for chat & summarization
- Next.js 15 – React framework
- TypeScript – type safety
- Tailwind CSS – styling
- SWR – data fetching
- Epub.js – ePub rendering
- Valtio & Jotai – state management
A distinctive feature is long-term memory in LLM interactions.
- Short-term memory – recent conversation buffer
- Mid-term memory – automatic conversation summaries
- Long-term memory – vector search for relevant info
- User profile – extraction & use of personal info
src/infrastructure/memory/– memory functionalitysrc/usecase/message/– message processing logicsrc/config/app_config.py– memory-related settings
- Book – book entity (ID, title, description, status)
- Chat – chat entity (user + book)
- Message – individual message within a chat
- Annotation – highlights & notes
For each entity:
- Interface defined in domain layer
- PostgreSQL implementation in infrastructure layer
- Entity identity by ID
- Value objects immutable with
@dataclass(frozen=True) - Business logic in domain layer
- Maintain dependency direction (upper → lower)
- Backend: mandatory MyPy checks
- Frontend: TypeScript strict mode
- API schema: automatic OpenAPI generation
apps/api/src/config/.env*– env varsAppConfigclass – Pydantic settings- Memory-related thresholds & limits also here
Docker Compose
services:
weaviate: # vector DB
- Ports: 8080 (HTTP), 50051 (gRPC)
- Persistence: weaviate_data volume
- No-auth (dev)
gcloud-storage-emulator: # GCS emulator
- Port: 4443
- Storage: ./gcs
Frontend Build
# apps/reader/Dockerfile (multi-stage build)
stage 1: Builder – turbo prune
stage 2: Installer – install deps + build
stage 3: Runner – production run (non-root)Docker Commands
# Start dev services
cd apps/api && make docker.up
# Build frontend
docker build -f apps/reader/Dockerfile -t bookwith-reader .
# Entire stack (future)
docker-compose up # root docker-compose.ymlOthers
PORT=8000– API portLANGSMITH_TRACING=true– enable tracing
- FastAPI
- Next.js 15
- Weaviate
- LangChain
- ePub.js
- Turbo (Monorepo)
- Valtio (State Management)
- SWR (Data Fetching)
- Tailwind CSS
- shadcn/ui
Common API client (apps/reader/src/lib/apiHandler/apiClient.ts):
// Basic usage
import { apiClient } from '@/lib/apiHandler/apiClient'
// GET request
const books = await apiClient<Book[]>('/books')
// POST request (JSON)
const newBook = await apiClient<Book>('/books', {
method: 'POST',
body: { title: 'Sample Book', description: 'Description' },
})
// With query params
const messages = await apiClient<Message[]>('/messages', {
params: { chat_id: 123, limit: 50 },
})Features
- Automatically attaches USER_ID (
TEST_USER_ID) - Auto-parses JSON responses
- Error handling (logs + throws)
- Supports standard response format
{success: boolean, data: T}
- Python 3.13 – latest typing features
- FastAPI – auto OpenAPI, high performance, streaming
- Next.js 15 – App Router, Turbopack, RSC
- Weaviate – open source, multi-tenant, semantic search
- Valtio – proxy-based state management for React
- Type safety across all layers
- DDD / Clean Architecture for maintainability & extensibility
- User experience as a comfortable ePub reader
- AI integration as a natural part of reading
- Traditional chatbots handle single Q&A
- BookWith enables continuous conversation with reading context
- Integrates book content + past conversations + annotations search
- Learns the user's reading style
- Backend: Black + MyPy + pre-commit
- Frontend: Prettier + ESLint + TypeScript strict
- Commits: Conventional Commits recommended
- Docs: auto-generated + manual additions
This notebook covers how to get started with the Weaviate vector store in LangChain, using the langchain-weaviate package. https://python.langchain.com/docs/integrations/vectorstores/weaviate/
https://weaviate.io/developers/weaviate
- Components under @apps/reader/src/components/ui should never be edited as they use components from shadcn/ui.