Files
2026-04-21 23:02:15 +08:00

107 lines
3.8 KiB
Markdown

# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
**FastAdmin 1.6.x** admin panel built on **ThinkPHP 5.x** (forked from gitee.com/fastadminnet/framework.git). The project is a Macau lottery (澳门六合彩) data tracking application named "amlhc".
- PHP >= 7.4.0, Apache-2.0 license
- Database: MySQL with `fa_` table prefix, utf8mb4 charset
- Frontend: RequireJS + Bootstrap 3.4 + AdminLTE skin
## Key Directories
| Path | Purpose |
|---|---|
| `application/admin/` | Admin backend — controllers, models, views, validates, lang |
| `application/index/` | Public-facing frontend |
| `application/api/` | REST API endpoints |
| `application/common/` | Shared base controllers, models, libraries, global helpers |
| `application/extra/` | Extra config: site.php, upload.php, queue.php, addons.php |
| `public/` | Web root — entry point `index.php`, static assets in `assets/` |
| `addons/` | Plugin directory (currently `command` addon installed) |
| `sql/` | SQL migration/DDL files |
| `thinkphp/` | Vendored ThinkPHP 5.x framework |
## Config Loading Chain
All files under `application/` are merged by ThinkPHP:
1. `config.php` — main config (debug, modules, URL, template, session, cookie, FastAdmin settings)
2. `database.php` — DB connection (reads from `.env`)
3. `extra/*.php` — site, upload, queue, addons config
4. `route.php` — URL routing (currently empty)
Environment variables are loaded from `.env` via `think\Env`.
## Admin Module Architecture
All admin controllers extend `app\common\controller\Backend`, which provides:
- RBAC auth via `app\admin\library\Auth` (salt double-MD5, session + cookie)
- CRUD base operations (index/add/edit/del/multi) via `app\admin\library\traits\Backend`
- Search/filtering, SelectPage, import/export
- Layout templating via `application/admin/view/layout/default.html`
**Standard controller pattern:** Each admin controller maps to a model + view directory + validate + lang file:
```
controller/X.php → model/X.php → view/x/ → validate/X.php → lang/zh-cn/x.php
```
## Custom Domain Code (Lottery)
| File | Purpose |
|---|---|
| `application/admin/controller/History.php` | Lottery history admin |
| `application/admin/model/History.php` | `fa_history` model |
| `application/admin/controller/Num.php` | `fa_num` color mapping API (`getColorMap`) |
| `application/admin/model/Num.php` | `fa_num` model |
| `application/index/controller/Index.php` | Scrapes lottery data from external API |
## Frontend Build System
**Grunt** (`Gruntfile.js`) is the build tool:
- `grunt deploy` — copy npm packages to `public/assets/libs/`
- `grunt backend:js` / `grunt frontend:js` — RequireJS optimizer for JS
- `grunt backend:css` / `grunt frontend:css` — Less → CSS compilation
JS uses RequireJS with separate entry points: `require-backend.js` and `require-frontend.js`.
## Common Development Commands
### Install dependencies
```bash
composer install
npm install
grunt deploy # copy npm deps to public/assets/libs/
grunt # build all JS/CSS
```
### Run dev server
```bash
php -S 127.0.0.1:8000 -t public public/router.php
```
### Generate CRUD scaffolding (built-in)
```bash
php think crud --table=fa_xxx --controller=xxx --model=xxx
```
### Generate menu for admin controller
```bash
php think menu --controller=xxx/xxx
```
### Run tests
```bash
php think unit
```
## Important Notes
- Admin entry is `public/index.php` (the admin module is accessed via URL routing, not a separate `admin.php`)
- All database queries use ThinkPHP's query builder (`Db::name('table')`) or models
- Language files use key-value pairs; keys are English labels (e.g., `'Num1' => '号码1'`)
- The `.env` file contains actual credentials — never commit it
- Runtime cache lives in `runtime/` — clear it when config changes don't take effect