Commit 286ad585 authored by yuguo's avatar yuguo

fix

parent 1189e884
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
Internet Hospital (互联网医院) — a full-stack telemedicine platform with a Go backend (`server/`) and Next.js frontend (`web/`).
## Commands
### Backend (run from `server/`)
```bash
make run # go run cmd/api/main.go
make build # binary → build/internet-hospital-api
make test # go test -v ./...
make deps # go mod download && go mod tidy
```
Single test: `cd server && go test -v -run TestName ./path/to/package/...`
### Frontend (run from `web/`)
```bash
npm run dev # next dev --turbopack --hostname 0.0.0.0
npm run build # production build
npm run lint # next lint
```
### Docker
```bash
docker-compose up # postgres (5432) + redis (6379) + api (8080)
```
## Architecture
### Backend (`server/`)
- **Entry**: `cmd/api/main.go` — Gin server, GORM auto-migrate on startup, seeds admin/doctors/tools
- **Framework**: Gin (HTTP), GORM (PostgreSQL), go-redis (Redis), gorilla/websocket
- **Config**: Viper reads `configs/config.yaml` (copy from `config.example.yaml`)
- **Module**: `internet-hospital`, Go 1.22
**Key packages:**
| Package | Purpose |
|---------|---------|
| `internal/model/` | All GORM models (40+), auto-migrated at startup |
| `internal/agent/` | Agent platform integration — tool init, service, handlers, seed data |
| `internal/service/` | Domain services: `admin/`, `user/`, `doctor/`, `consult/`, `preconsult/`, `chronic/`, `health/`, `payment/`, `doctorportal/` |
| `pkg/agent/` | ReAct agent engine, tool registry, executor (cache/timeout/retry), memory manager |
| `pkg/agent/tools/` | 19+ builtin tools + dynamic HTTP/CRUD/Expression tool factories |
| `pkg/ai/` | AI client (DeepSeek/OpenAI-compatible), auto-falls back to MockChat when no API key |
| `pkg/workflow/` | Workflow engine with 11 node types, expr-lang for code/condition nodes |
| `pkg/middleware/` | CORS, JWT auth, TraceID |
| `pkg/response/` | Unified response: `{code: 0, message, data, trace_id}` |
**Circular import prevention**: `pkg/agent/tools/` cannot import `internal/agent/`. Instead, function variables (`AgentCallFn`, `WorkflowTriggerFn`, `SkillExecuteFn`) are injected via `WireCallbacks()` at startup.
**Routes**: All under `/api/v1`. JWT via `middleware.JWTAuth()`, role checks via `middleware.RequireRole()`.
### Frontend (`web/`)
- **Framework**: Next.js 15 (App Router, Turbopack), React 19, TypeScript 5.9
- **Styling**: Tailwind CSS v4 (CSS-based config, no tailwind.config.js) + Ant Design v5
- **State**: Zustand v5 (client state, `userStore` persisted to localStorage) + TanStack Query v5 (server state)
**Key directories:**
| Directory | Purpose |
|-----------|---------|
| `src/app/(auth)/` | Login, Register pages |
| `src/app/(main)/admin/` | Admin panel (agents, tools, workflows, pharmacy, etc.) |
| `src/app/(main)/patient/` | Patient portal (consult, prescriptions, chronic care) |
| `src/app/(main)/doctor/` | Doctor portal (workbench, consult, tasks) |
| `src/api/` | API modules — `request.ts` (Axios with JWT), `sse.ts` (SSE streaming) |
| `src/components/GlobalAIFloat/` | Floating AI assistant with SSE streaming, embedded views |
| `src/store/` | Zustand stores |
| `src/hooks/` | Custom hooks (auth, AI chat, WebSocket, etc.) |
### Tailwind v4 + Ant Design v5 CSS Layer Setup
This is critical and easy to break:
1. `globals.css` declares `@layer antd;` FIRST, before `@import "tailwindcss"`
2. `providers.tsx` wraps Ant Design with `<StyleProvider layer>` so antd CSS goes into `@layer antd`
3. Result: Tailwind utilities override antd styles without `!important`
4. Layer priority (low→high): `antd``theme``base``components``utilities`
## Coding Conventions
### Backend
- Package `internalagent` for `internal/agent/` (avoid name collision)
- `expr-lang/expr` imported as `exprlib` to avoid naming conflicts
- Hot-reloadable: agents, HTTP tools, CRUD tools, expr tools (admin API, no restart needed)
- `ai.GetClient()` returns nil when AI is disabled — all callers must nil-check
- `SystemLog` model uses `Action`/`Resource`/`Detail` fields (not Level/Message/Module)
### Frontend
- `"use client"` directive required on all interactive components
- Import alias: `@/``src/`
- Use `const { message } = App.useApp()` for Ant Design feedback (not static `message.success()`)
- API responses: access `res.data` directly (request.ts already extracts `response.data`)
- Tailwind important modifier uses suffix `!` (e.g., `h-10!`) — avoid unless necessary
- `next.config.ts` has `ignoreBuildErrors: true` — TS errors won't fail builds
## Configuration
### Backend (`server/configs/config.yaml`)
- `ai.api_key: ""` → MockChat fallback mode (hardcoded test responses)
- Set a real DeepSeek/OpenAI key for real AI functionality
### Frontend
- `NEXT_PUBLIC_API_BASE_URL` — API base URL (default `http://localhost:8080`)
- `BACKEND_URL` — server-side rewrite target in next.config.ts
## Test Accounts (Seeded on Startup)
- Doctors: `13800000001-3` / `123456` (require `status = 'approved'` in DB)
- Admin: created by `user.InitAdminUser()` on first run
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment