4.6 KiB
4.6 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is a Chinese-language enterprise SaaS device management platform (地空业务支撑平台——生产管理子系统) built with Next.js App Router. It manages the full lifecycle of geophysical instruments (device registration, BOM configuration, license/authorization management, repair orders, firmware, and scrap records).
Tech Stack
- Frontend: Next.js 16, React 19, TypeScript 6, Tailwind CSS 4
- Database: SQLite via
better-sqlite3(file-based, located atdata/app.db) - Icons: lucide-react
- Forms: react-hook-form + zod
- Secondary backend: FastAPI in
python_backend/for device activation and encrypted license generation
Common Commands
# Install dependencies
npm install
# Start Next.js dev server (http://localhost:3000)
npm run dev
# Build for production
npm run build
# Start production server
npm run start
# Run linting
npm run lint
Python Backend
The FastAPI service in python_backend/ handles device check-in, encrypted license generation, and activation reporting independently from the Next.js app.
cd python_backend
pip install -r requirements.txt
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Architecture
Database Layer (src/lib/db.ts)
- Uses
better-sqlite3with WAL mode and foreign keys enabled. getDb()returns a singletonDatabaseinstance. The DB file is created atdata/app.dbrelative toprocess.cwd().initTables()defines the full schema on first run (tables:devices,device_models,materials,bom_templates,config_files,licenses,repair_orders,scrap_records,firmware,applications,app_platform_versions, etc.).migrateDatabase()handles incremental schema changes (e.g., addingconfig_id,license_file,device_snto thelicensestable, creatinglicense_download_logsandlicense_templates).generateLicenseFile()builds a SHA256-signed JSON license payload.
Data Fetching
- Frontend: Uses a lightweight custom hook
useApi(url, defaultValue)defined insrc/lib/hooks.ts(standardfetch+useState/useEffect). No React Query usage in practice despite being inpackage.json. - Backend API: Implemented as Next.js Route Handlers under
src/app/api/. Each endpoint typically callsseedIfEmpty()(currently a no-op that just ensures the DB is open) and then usesgetDb()to run SQL queries. - API routes generally support
GET(list),POST(create),PUT(update), andDELETE.
Page Structure (App Router)
src/app/layout.tsxprovides the root layout with a sidebar navigation and header.src/app/components/sidebar.tsxdefines the navigation groups: 设备 (Devices), 物料 (Materials), 软件 (Software), 维修 (Repair).- Major routes:
/— Dashboard with statistics overview/devices— Device list with batch filtering and pagination/devices/[sn]— Device detail / BOM view/registration— Register new device/models— Device model management/models/bom— BOM template management/materials/*— Material (board/component) inventory and categories/app-versions— Mobile app release management/repair— Repair work orders/scrap— Scrap/disposal records/licenses— License/authorization configuration and JSON file generation/config-files— Device technical parameter configs/firmware— Firmware version management
Styling
- Tailwind CSS v4 is imported in
src/styles/index.css(@import 'tailwindcss'). - Additional custom styles in
src/styles/theme.cssandsrc/styles/fonts.css. - Many components also use inline
styleprops for specific colors (primary brand color is#4a7c59).
Path Aliases
@/*maps to./src/*intsconfig.json.
Key Development Notes
- No test suite is configured. There are no test runners or test files in the repo.
- No pre-commit hooks or CI configuration were found.
- Database schema changes: When modifying the schema, update
initTables()for new tables andmigrateDatabase()for alterations to existing tables, since the app uses a single SQLite file that persists across restarts. - License file generation: The
licensesAPI automatically generates a signed JSON license onPOST/PUTby callinggenerateLicenseFile()fromsrc/lib/db.ts. - Python backend is separate: The Next.js app does not depend on the FastAPI backend for normal operation. The Python service is specifically for field-device activation flows and encrypted license distribution to mobile apps.