portal/docs/architecture.md
Hermes Agent ae06dda9da feat: portal webapp - CMS独立Web应用壳
- app/portal.py: 主入口,通过from cms.init import load_cms加载业务模块
- conf/config.json: 应用配置(ocai_cms数据库, 端口9090, cms模块wwwroot挂载到/cms)
- wwwroot/: 公开页面(index/news/cases/products)和公开API
- build.sh: 构建脚本(安装基础设施包+pip install cms模块+DDL/CRUD生成)
- deploy.sh: 一键部署脚本(构建→建表→初始数据→权限→启动)
- init_data.py: 从cms模块init/data.yaml加载初始数据
- init_any/superuser_permissions.py: RBAC权限初始化
2026-06-15 11:06:10 +08:00

140 lines
5.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Portal系统架构
## 项目概述
Portal是企业官网CMS系统的独立Web应用壳采用与pipeline-app相同的"壳+模块"架构模式。
Portal负责Web服务器启动、基础设施加载和公开前端页面CMS业务逻辑通过pip install以模块方式引入。
## 架构模式: 壳+模块
```
┌─────────────────────────────────────────────────┐
│ Portal (Web壳) │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ ahserver │ │ rbac │ │ appbase │ │
│ │ (Web服务) │ │ (认证) │ │ (基础) │ │
│ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ wwwroot/ (公开前端) │ │
│ │ index.ui products.ui news.ui ... │ │
│ │ api/get_published_content.dspy ... │ │
│ │ dingdingflow/index.ui ... │ │
│ └──────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ CMS模块 (pip install -e ~/repos/cms) │ │
│ │ │ │
│ │ ┌─────────┐ ┌──────────────┐ │ │
│ │ │ entcms │ │ dingdingflow │ │ │
│ │ │ 内容管理 │ │ 钉钉审批 │ │ │
│ │ │ CRUD页面│ │ CRUD页面 │ │ │
│ │ │ 数据模型 │ │ 数据模型 │ │ │
│ │ └─────────┘ └──────────────┘ │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
```
## 初始化流程
Portal启动时的加载顺序
```
1. set_globalvariable() — 注册全局函数 (get_module_dbname, UiError等)
2. load_pybricks() — 加载bricks前端框架
3. load_appbase() — 加载应用基础模块 (公共函数注册)
4. load_rbac() — 加载RBAC认证模块 (角色权限控制)
5. load_cms() — 加载CMS业务模块 (entcms + dingdingflow)
```
所有模块注册到 `ServerEnv`,供.dspy和.ui文件在运行时调用。
## 数据库
统一使用 `ocai_cms` 数据库:
| 模块 | 表 |
|------|-----|
| entcms | cms_content, cms_categories, cms_sections, cms_leads, cms_site_config |
| dingdingflow | dd_approvals, dd_approval_configs |
`get_module_dbname()` 对所有模块返回 `'ocai_cms'`
## 前端页面分层
### 公开页面 (Portal wwwroot/)
| 页面 | 权限 | 说明 |
|------|------|------|
| index.ui | any | 官网首页 (导航/Hero/产品/案例/新闻/页脚/浮动入口) |
| products.ui | any | 产品架构列表 |
| news.ui | any | 新闻列表 |
| news_detail.ui | any | 新闻详情 |
| cases.ui | any | 案例列表 |
| admin.ui | logined | 管理后台仪表盘 (入口) |
| menu.ui | logined | 管理菜单 |
### 公开API (Portal wwwroot/api/)
| API | 权限 | 说明 |
|-----|------|------|
| get_published_content.dspy | any | 获取已发布内容 |
| get_content_detail.dspy | any | 获取内容详情 |
| get_config.dspy | any | 获取站点配置 |
| get_sections.dspy | any | 获取栏目列表 |
| submit_lead.dspy | any | 提交商机线索 |
### 管理CRUD页面 (CMS模块wwwroot/)
由cms模块提供不在portal/wwwroot中
- cms_content_list (内容管理)
- cms_categories_list (分类管理)
- cms_sections_list (栏目管理)
- cms_leads_list (线索管理)
- cms_site_config_list (站点配置)
### 钉钉审批 (Portal wwwroot/dingdingflow/)
| 页面 | 权限 | 说明 |
|------|------|------|
| dingdingflow/index.ui | any | 审批列表入口 |
| dingdingflow/menu.ui | any | 审批菜单 |
| dingdingflow/api/*.dspy | any | 审批API |
## 技术栈
| 层 | 技术 |
|----|------|
| Web服务器 | ahserver (异步HTTP) |
| 前端框架 | bricks-framework (JSON UI DSL) |
| 数据库 | MySQL (async, sqlor连接池) |
| 认证 | RBAC (角色权限控制) |
| 基础设施 | appbase, apppublic, checklang |
| 业务模块 | cms (entcms + dingdingflow) |
## 部署架构
```
Nginx/LB (80/443)
Portal (ahserver :9090)
├── / wwwroot/ (公开页面 + API)
├── /bricks/ → pkgs/bricks/dist (前端框架)
└── CMS模块 (pip installed)
└── CRUD页面 + 业务逻辑
MySQL (ocai_cms)
Redis (session)
```
## 与pipeline-app对比
| 特征 | pipeline-app | portal |
|------|-------------|--------|
| 业务模块数 | 3 (core/ops/dist) | 1 (cms) |
| 模块安装方式 | 本地子目录 | editable pip install |
| 公开页面 | index.ui | index.ui + products + news + cases |
| 公开API | 无 | 5个只读接口 |
| 数据库 | pipeline_* | ocai_cms |
| 端口 | 8080 | 9090 |