介紹
Doggy Framework 是一個 AI 原生的企業級低程式碼開發框架,基於 Symfony 7.4 LTS(長期支援至 2029 年)建置。
為什麼選擇 Doggy?
- AI 原生:深度整合 MCP、Agent、多模型(阿里百煉、OpenAI、LM Studio、Ollama 等),內建 LLM 設定系統、全域 AI 助手、AI 視圖增強、程式碼助手、自然語言查詢、視覺辨識等 AI 能力
- 低程式碼引擎:透過 PHP 8 Attribute 搭配
@Ef自訂註解定義業務模型,自動產生資料庫遷移和管理介面 - AI 驅動的視圖設計器:拖曳版面配置 + AI 自然語言操作 + 意圖辨識子 Agent 產生視圖 + 多版本管理
- 企業級安全:WebAuthn 無密碼登入、三員分立、密碼策略、全鏈路稽核日誌
- 即時通訊:基於 Mercure SSE 的即時推播,FrankenPHP 內建 Hub,無需額外服務
- 高效能:FrankenPHP Worker 模式 + zstd/br 壓縮,PostgreSQL 優先架構
- 完整生態系:組織架構、排程任務、檔案儲存、電子郵件系統、SunUI 元件庫等開箱即用
技術堆疊
| 層級 | 技術 |
|---|---|
| 語言 | PHP 8.2+ |
| 框架 | Symfony 7.4 LTS |
| 執行階段 | FrankenPHP (Worker 模式) via runtime/frankenphp-symfony |
| 資料庫 | PostgreSQL 14+ |
| ORM | Doctrine ORM + StofDoctrineExtensionsBundle (Gedmo) |
| 訊息佇列 | Symfony Messenger (Doctrine Transport) |
| 即時通訊 | Mercure SSE (dunglas/mercure) |
| AI | Symfony AI (MCP, Agent, Store, 多平台支援) |
| 認證 | WebAuthn (web-auth/webauthn-symfony-bundle) + JWT (firebase/jwt) |
| 檔案儲存 | League Flysystem (Local / OSS / S3) |
| 前端 | Twig + jQuery + SunUI 元件庫 |
| 工具庫 | PHPSpreadsheet, Imagine, Predis, Ramsey UUID |
系統需求
- PHP >= 8.2
- ext-ctype, ext-iconv
- PostgreSQL >= 14
- Composer >= 2.5
快速開始
安裝
bash
git clone git@github.com:doggy/skeleton.git my-app
cd my-app環境設定
bash
cp .env.example .env
# 编辑 .env 配置数据库连接与 Mercure JWT 密钥啟動資料庫
PostgreSQL 需要單獨安裝並執行:
bash
# macOS
brew install postgresql@14
brew services start postgresql@14
createdb app
# Ubuntu/Debian
sudo apt install postgresql-14
sudo systemctl start postgresql
sudo -u postgres createdb appMercure Hub 內建於 FrankenPHP,無需額外啟動。
存取
目錄結構
config/
├── bundles.php # 已启用的 Symfony Bundle 列表
├── packages/ # 各 Bundle 配置
└── services.yaml
src/
├── Annotation/ # 自定义注解:Ef.php, EfGroup.php
├── Command/ # 16 个 Console 命令
├── Controller/ # Admin, Api, Security 控制器
├── Entity/ # Doctrine 实体 + CommonTrait
│ ├── Organization/ # Department, Position 等
│ ├── Platform/ # 平台相关实体
│ ├── Security/ # User, Role, Permission
│ ├── Storage/ # 文件存储实体
│ └── System/ # 系统配置实体
├── Form/ # 表单类型
├── Message/ # 异步消息
├── MessageHandler/ # 消息处理器
├── Repository/ # Doctrine Repository
├── Security/ # WebAuthn, JWT, Voter
├── Service/ # AI, Calendar, Security, Storage, Task, View 等
└── Twig/ # TwigExtension
Caddyfile # FrankenPHP 配置(含 Mercure Hub、压缩、缓存)已啟用的核心 Bundle
| Bundle | 用途 |
|---|---|
| FrameworkBundle | Symfony 核心 |
| DoctrineBundle + MigrationsBundle | 資料庫 ORM 與遷移 |
| SecurityBundle | 安全認證與授權 |
| TwigBundle + TwigExtraBundle | 範本引擎 |
| MonologBundle | 日誌 |
| StofDoctrineExtensionsBundle | Gedmo 擴充(樹狀、時間戳記、軟刪除等) |
| NelmioCorsBundle | CORS 支援 |
| WebauthnBundle | WebAuthn 無密碼認證 |
| MercureBundle | 即時訊息推播 |
| AiBundle | Symfony AI 整合 |
| FlysystemBundle | 檔案儲存抽象 |
| HautelookAliceBundle | 測試夾具 |
核心概念
動態模型
透過 @Ef 註解標記業務欄位,搭配 PHP 8 Attributes 定義模型,自動完成:
- 資料庫遷移產生
- CRUD 介面渲染
- 資料驗證規則
- 權限檢查
php
use App\Annotation\Ef;
class Department
{
#[Ef(displayName: '部门名称', required: true)]
private string $name;
#[Ef(displayName: '部门编码', searchable: true)]
private string $code;
}參考:動態模型
實體通用 Trait
所有實體透過 CommonTrait 組合以下能力:
CommonTrait
├── BlameableTrait # 创建人/更新人自动记录
├── TimestampableTrait # 创建时间/更新时间自动记录
├── SoftDeleteTrait # 软删除
└── IdTrait # 自增主键組織架構
多層部門樹(Nested Set)、員工管理、職位體系,支援:
- 無限層級部門樹(Gedmo NestedTree)
- 多公司與多部門歸屬
- 職位與職級體系
- 批次使用者匯入匯出(PHPSpreadsheet)
參考:組織架構
安全體系
- WebAuthn 無密碼登入(支援 Passkey、安全金鑰、生物辨識)
- 三員分立(系統管理員、安全保密員、稽核員)
- 密碼複雜度與有效期限策略
- 全鏈路操作稽核
參考:WebAuthn 認證