aury-boot 0.0.2__py3-none-any.whl → 0.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aury/boot/__init__.py +66 -0
- aury/boot/_version.py +2 -2
- aury/boot/application/__init__.py +120 -0
- aury/boot/application/app/__init__.py +39 -0
- aury/boot/application/app/base.py +511 -0
- aury/boot/application/app/components.py +434 -0
- aury/boot/application/app/middlewares.py +101 -0
- aury/boot/application/config/__init__.py +44 -0
- aury/boot/application/config/settings.py +663 -0
- aury/boot/application/constants/__init__.py +19 -0
- aury/boot/application/constants/components.py +50 -0
- aury/boot/application/constants/scheduler.py +28 -0
- aury/boot/application/constants/service.py +29 -0
- aury/boot/application/errors/__init__.py +55 -0
- aury/boot/application/errors/chain.py +80 -0
- aury/boot/application/errors/codes.py +67 -0
- aury/boot/application/errors/exceptions.py +238 -0
- aury/boot/application/errors/handlers.py +320 -0
- aury/boot/application/errors/response.py +120 -0
- aury/boot/application/interfaces/__init__.py +76 -0
- aury/boot/application/interfaces/egress.py +224 -0
- aury/boot/application/interfaces/ingress.py +98 -0
- aury/boot/application/middleware/__init__.py +22 -0
- aury/boot/application/middleware/logging.py +451 -0
- aury/boot/application/migrations/__init__.py +13 -0
- aury/boot/application/migrations/manager.py +685 -0
- aury/boot/application/migrations/setup.py +237 -0
- aury/boot/application/rpc/__init__.py +63 -0
- aury/boot/application/rpc/base.py +108 -0
- aury/boot/application/rpc/client.py +294 -0
- aury/boot/application/rpc/discovery.py +218 -0
- aury/boot/application/scheduler/__init__.py +13 -0
- aury/boot/application/scheduler/runner.py +123 -0
- aury/boot/application/server/__init__.py +296 -0
- aury/boot/commands/__init__.py +30 -0
- aury/boot/commands/add.py +76 -0
- aury/boot/commands/app.py +105 -0
- aury/boot/commands/config.py +177 -0
- aury/boot/commands/docker.py +367 -0
- aury/boot/commands/docs.py +284 -0
- aury/boot/commands/generate.py +1277 -0
- aury/boot/commands/init.py +890 -0
- aury/boot/commands/migrate/__init__.py +37 -0
- aury/boot/commands/migrate/app.py +54 -0
- aury/boot/commands/migrate/commands.py +303 -0
- aury/boot/commands/scheduler.py +124 -0
- aury/boot/commands/server/__init__.py +21 -0
- aury/boot/commands/server/app.py +541 -0
- aury/boot/commands/templates/generate/api.py.tpl +105 -0
- aury/boot/commands/templates/generate/model.py.tpl +17 -0
- aury/boot/commands/templates/generate/repository.py.tpl +19 -0
- aury/boot/commands/templates/generate/schema.py.tpl +29 -0
- aury/boot/commands/templates/generate/service.py.tpl +48 -0
- aury/boot/commands/templates/project/CLI.md.tpl +92 -0
- aury/boot/commands/templates/project/DEVELOPMENT.md.tpl +1397 -0
- aury/boot/commands/templates/project/README.md.tpl +111 -0
- aury/boot/commands/templates/project/admin_console_init.py.tpl +50 -0
- aury/boot/commands/templates/project/config.py.tpl +30 -0
- aury/boot/commands/templates/project/conftest.py.tpl +26 -0
- aury/boot/commands/templates/project/env.example.tpl +213 -0
- aury/boot/commands/templates/project/gitignore.tpl +128 -0
- aury/boot/commands/templates/project/main.py.tpl +41 -0
- aury/boot/commands/templates/project/modules/api.py.tpl +19 -0
- aury/boot/commands/templates/project/modules/exceptions.py.tpl +84 -0
- aury/boot/commands/templates/project/modules/schedules.py.tpl +18 -0
- aury/boot/commands/templates/project/modules/tasks.py.tpl +20 -0
- aury/boot/commands/worker.py +143 -0
- aury/boot/common/__init__.py +35 -0
- aury/boot/common/exceptions/__init__.py +114 -0
- aury/boot/common/i18n/__init__.py +16 -0
- aury/boot/common/i18n/translator.py +272 -0
- aury/boot/common/logging/__init__.py +716 -0
- aury/boot/contrib/__init__.py +10 -0
- aury/boot/contrib/admin_console/__init__.py +18 -0
- aury/boot/contrib/admin_console/auth.py +137 -0
- aury/boot/contrib/admin_console/discovery.py +69 -0
- aury/boot/contrib/admin_console/install.py +172 -0
- aury/boot/contrib/admin_console/utils.py +44 -0
- aury/boot/domain/__init__.py +79 -0
- aury/boot/domain/exceptions/__init__.py +132 -0
- aury/boot/domain/models/__init__.py +51 -0
- aury/boot/domain/models/base.py +69 -0
- aury/boot/domain/models/mixins.py +135 -0
- aury/boot/domain/models/models.py +96 -0
- aury/boot/domain/pagination/__init__.py +279 -0
- aury/boot/domain/repository/__init__.py +23 -0
- aury/boot/domain/repository/impl.py +423 -0
- aury/boot/domain/repository/interceptors.py +47 -0
- aury/boot/domain/repository/interface.py +106 -0
- aury/boot/domain/repository/query_builder.py +348 -0
- aury/boot/domain/service/__init__.py +11 -0
- aury/boot/domain/service/base.py +73 -0
- aury/boot/domain/transaction/__init__.py +404 -0
- aury/boot/infrastructure/__init__.py +104 -0
- aury/boot/infrastructure/cache/__init__.py +31 -0
- aury/boot/infrastructure/cache/backends.py +348 -0
- aury/boot/infrastructure/cache/base.py +68 -0
- aury/boot/infrastructure/cache/exceptions.py +37 -0
- aury/boot/infrastructure/cache/factory.py +94 -0
- aury/boot/infrastructure/cache/manager.py +274 -0
- aury/boot/infrastructure/database/__init__.py +39 -0
- aury/boot/infrastructure/database/config.py +71 -0
- aury/boot/infrastructure/database/exceptions.py +44 -0
- aury/boot/infrastructure/database/manager.py +317 -0
- aury/boot/infrastructure/database/query_tools/__init__.py +164 -0
- aury/boot/infrastructure/database/strategies/__init__.py +198 -0
- aury/boot/infrastructure/di/__init__.py +15 -0
- aury/boot/infrastructure/di/container.py +393 -0
- aury/boot/infrastructure/events/__init__.py +33 -0
- aury/boot/infrastructure/events/bus.py +362 -0
- aury/boot/infrastructure/events/config.py +52 -0
- aury/boot/infrastructure/events/consumer.py +134 -0
- aury/boot/infrastructure/events/middleware.py +51 -0
- aury/boot/infrastructure/events/models.py +63 -0
- aury/boot/infrastructure/monitoring/__init__.py +529 -0
- aury/boot/infrastructure/scheduler/__init__.py +19 -0
- aury/boot/infrastructure/scheduler/exceptions.py +37 -0
- aury/boot/infrastructure/scheduler/manager.py +478 -0
- aury/boot/infrastructure/storage/__init__.py +38 -0
- aury/boot/infrastructure/storage/base.py +164 -0
- aury/boot/infrastructure/storage/exceptions.py +37 -0
- aury/boot/infrastructure/storage/factory.py +88 -0
- aury/boot/infrastructure/tasks/__init__.py +24 -0
- aury/boot/infrastructure/tasks/config.py +45 -0
- aury/boot/infrastructure/tasks/constants.py +37 -0
- aury/boot/infrastructure/tasks/exceptions.py +37 -0
- aury/boot/infrastructure/tasks/manager.py +490 -0
- aury/boot/testing/__init__.py +24 -0
- aury/boot/testing/base.py +122 -0
- aury/boot/testing/client.py +163 -0
- aury/boot/testing/factory.py +154 -0
- aury/boot/toolkit/__init__.py +21 -0
- aury/boot/toolkit/http/__init__.py +367 -0
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.3.dist-info}/METADATA +3 -2
- aury_boot-0.0.3.dist-info/RECORD +137 -0
- aury_boot-0.0.2.dist-info/RECORD +0 -5
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.3.dist-info}/WHEEL +0 -0
- {aury_boot-0.0.2.dist-info → aury_boot-0.0.3.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# {project_name}
|
|
2
|
+
|
|
3
|
+
基于 [Aury Boot](https://github.com/AuriMyth/aury-boot) 构建的 API 服务。
|
|
4
|
+
|
|
5
|
+
## 快速开始
|
|
6
|
+
|
|
7
|
+
### 安装依赖
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv sync
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 配置环境变量
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cp .env.example .env
|
|
17
|
+
# 编辑 .env 文件
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### 启动开发服务器
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
aury server dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 管理后台(可选)
|
|
27
|
+
|
|
28
|
+
默认提供 SQLAdmin 管理后台扩展(默认路径:`/api/admin-console`),适合快速搭建项目的后台管理能力。
|
|
29
|
+
|
|
30
|
+
1) 安装扩展依赖:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv add "aury-boot[admin]"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2) 在 `.env` 中启用并配置认证(至少 basic 或 bearer 之一):
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
ADMIN_ENABLED=true
|
|
40
|
+
ADMIN_PATH=/api/admin-console
|
|
41
|
+
ADMIN_AUTH_MODE=basic
|
|
42
|
+
ADMIN_AUTH_SECRET_KEY=CHANGE_ME_TO_A_RANDOM_SECRET
|
|
43
|
+
ADMIN_AUTH_BASIC_USERNAME=admin
|
|
44
|
+
ADMIN_AUTH_BASIC_PASSWORD=change_me
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
3) 启动后访问:
|
|
48
|
+
|
|
49
|
+
- `http://127.0.0.1:8000/api/admin-console`
|
|
50
|
+
|
|
51
|
+
### 生成代码
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 生成完整 CRUD(交互式,推荐)
|
|
55
|
+
aury generate crud user -i
|
|
56
|
+
|
|
57
|
+
# 单独生成(添加 -i 参数可交互式配置)
|
|
58
|
+
aury generate model user -i # SQLAlchemy 模型
|
|
59
|
+
aury generate repo user # Repository
|
|
60
|
+
aury generate service user # Service
|
|
61
|
+
aury generate api user # API 路由
|
|
62
|
+
aury generate schema user # Pydantic Schema
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 数据库迁移
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# 生成迁移
|
|
69
|
+
aury migrate make -m "add user table"
|
|
70
|
+
|
|
71
|
+
# 执行迁移
|
|
72
|
+
aury migrate up
|
|
73
|
+
|
|
74
|
+
# 查看状态
|
|
75
|
+
aury migrate status
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 调度器和 Worker
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# 独立运行调度器
|
|
82
|
+
aury scheduler
|
|
83
|
+
|
|
84
|
+
# 运行任务队列 Worker
|
|
85
|
+
aury worker
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## 项目结构
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
{project_name}/
|
|
92
|
+
├── main.py # 应用入口
|
|
93
|
+
├── app/ # 代码包(默认 app,可通过 aury init <pkg> 自定义)
|
|
94
|
+
│ ├── config.py # 配置定义
|
|
95
|
+
│ ├── api/ # API 路由
|
|
96
|
+
│ ├── services/ # 业务逻辑
|
|
97
|
+
│ ├── models/ # SQLAlchemy 模型
|
|
98
|
+
│ ├── repositories/ # 数据访问层
|
|
99
|
+
│ ├── schemas/ # Pydantic 模型
|
|
100
|
+
│ ├── exceptions/ # 自定义异常
|
|
101
|
+
│ ├── schedules/ # 定时任务
|
|
102
|
+
│ └── tasks/ # 异步任务
|
|
103
|
+
├── migrations/ # 数据库迁移
|
|
104
|
+
└── tests/ # 测试
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 文档
|
|
108
|
+
|
|
109
|
+
- [DEVELOPMENT.md](./DEVELOPMENT.md) - 开发指南(代码组织与规范)
|
|
110
|
+
- [CLI.md](./CLI.md) - CLI 命令参考
|
|
111
|
+
- [Aury Boot 文档](https://github.com/AuriMyth/aury-boot)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""管理后台(Admin Console)项目侧扩展点。
|
|
2
|
+
|
|
3
|
+
说明:
|
|
4
|
+
- 框架会在启用 ADMIN_ENABLED=true 时自动尝试加载本模块,并调用 register_admin(admin)
|
|
5
|
+
- 用于注册 SQLAdmin 的 ModelView(展示/编辑你的业务模型)
|
|
6
|
+
- 认证默认推荐使用环境变量(basic/bearer);如需深度自定义,可在本模块实现 register_admin_auth(config)
|
|
7
|
+
(注意:一旦定义 register_admin_auth,会覆盖内置认证逻辑)
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def register_admin(admin) -> None:
|
|
14
|
+
"""注册 SQLAdmin Views。
|
|
15
|
+
|
|
16
|
+
你可以在这里添加你的 ModelView:
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from sqladmin import ModelView
|
|
20
|
+
from {import_prefix}models.user import User
|
|
21
|
+
|
|
22
|
+
class UserAdmin(ModelView, model=User):
|
|
23
|
+
column_list = [User.id, User.email]
|
|
24
|
+
|
|
25
|
+
admin.add_view(UserAdmin)
|
|
26
|
+
```
|
|
27
|
+
"""
|
|
28
|
+
# 默认不注册任何 view,避免生成项目缺少模型时报错
|
|
29
|
+
return
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
# 如需自定义认证(覆盖 basic/bearer),取消注释并实现:
|
|
33
|
+
#
|
|
34
|
+
# def register_admin_auth(config):
|
|
35
|
+
# from sqladmin.authentication import AuthenticationBackend
|
|
36
|
+
# from starlette.requests import Request
|
|
37
|
+
#
|
|
38
|
+
# class MyAuth(AuthenticationBackend):
|
|
39
|
+
# async def login(self, request: Request) -> bool:
|
|
40
|
+
# return False
|
|
41
|
+
#
|
|
42
|
+
# async def logout(self, request: Request) -> bool:
|
|
43
|
+
# return True
|
|
44
|
+
#
|
|
45
|
+
# async def authenticate(self, request: Request) -> bool:
|
|
46
|
+
# return False
|
|
47
|
+
#
|
|
48
|
+
# return MyAuth(secret_key=config.admin.auth.secret_key)
|
|
49
|
+
|
|
50
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""应用配置。
|
|
2
|
+
|
|
3
|
+
配置优先级:命令行参数 > 环境变量 > .env 文件 > 默认值
|
|
4
|
+
|
|
5
|
+
环境变量示例:
|
|
6
|
+
DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/mydb
|
|
7
|
+
CACHE_TYPE=redis
|
|
8
|
+
CACHE_REDIS_URL=redis://localhost:6379/0
|
|
9
|
+
LOG_LEVEL=INFO
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from aury.boot.application.config import BaseConfig
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AppConfig(BaseConfig):
|
|
16
|
+
"""{project_name} 配置。
|
|
17
|
+
|
|
18
|
+
继承 BaseConfig 获得所有默认配置项:
|
|
19
|
+
- server: 服务器配置
|
|
20
|
+
- database: 数据库配置
|
|
21
|
+
- cache: 缓存配置
|
|
22
|
+
- log: 日志配置
|
|
23
|
+
- migration: 迁移配置
|
|
24
|
+
|
|
25
|
+
可以在这里添加自定义配置项。
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
# 添加自定义配置项
|
|
29
|
+
# my_setting: str = Field(default="value", description="自定义配置")
|
|
30
|
+
pass
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Pytest 配置和 fixtures。"""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from collections.abc import AsyncGenerator, Generator
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
from sqlalchemy.ext.asyncio import AsyncSession
|
|
8
|
+
|
|
9
|
+
from aury.boot.infrastructure.database import DatabaseManager
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture(scope="session")
|
|
13
|
+
def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
|
|
14
|
+
"""创建事件循环。"""
|
|
15
|
+
loop = asyncio.get_event_loop_policy().new_event_loop()
|
|
16
|
+
yield loop
|
|
17
|
+
loop.close()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@pytest.fixture
|
|
21
|
+
async def db_session() -> AsyncGenerator[AsyncSession, None]:
|
|
22
|
+
"""获取数据库会话。"""
|
|
23
|
+
db_manager = DatabaseManager.get_instance()
|
|
24
|
+
async with db_manager.session() as session:
|
|
25
|
+
yield session
|
|
26
|
+
await session.rollback()
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# {project_name} 环境变量配置
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# 复制此文件为 .env 并根据实际情况修改
|
|
5
|
+
# 所有配置项均有默认值,只需取消注释并修改需要覆盖的项
|
|
6
|
+
|
|
7
|
+
# =============================================================================
|
|
8
|
+
# 服务配置 (SERVICE_)
|
|
9
|
+
# =============================================================================
|
|
10
|
+
# 服务名称,用于日志目录区分
|
|
11
|
+
SERVICE_NAME={project_name_snake}
|
|
12
|
+
# 服务类型: api / worker
|
|
13
|
+
# SERVICE_TYPE=api
|
|
14
|
+
|
|
15
|
+
# =============================================================================
|
|
16
|
+
# 服务器配置 (SERVER_)
|
|
17
|
+
# =============================================================================
|
|
18
|
+
# SERVER_HOST=127.0.0.1
|
|
19
|
+
# SERVER_PORT=8000
|
|
20
|
+
# 工作进程数(生产环境建议设为 CPU 核心数)
|
|
21
|
+
# SERVER_WORKERS=1
|
|
22
|
+
# 是否启用热重载(生产环境应设为 false)
|
|
23
|
+
# SERVER_RELOAD=true
|
|
24
|
+
|
|
25
|
+
# =============================================================================
|
|
26
|
+
# 数据库配置 (DATABASE_)
|
|
27
|
+
# =============================================================================
|
|
28
|
+
# 数据库连接字符串(默认 SQLite)
|
|
29
|
+
# DATABASE_URL=sqlite+aiosqlite:///./dev.db
|
|
30
|
+
# PostgreSQL: postgresql+asyncpg://user:pass@localhost:5432/{project_name_snake}
|
|
31
|
+
# MySQL: mysql+aiomysql://user:pass@localhost:3306/{project_name_snake}
|
|
32
|
+
|
|
33
|
+
# 连接池大小
|
|
34
|
+
# DATABASE_POOL_SIZE=5
|
|
35
|
+
# 连接池最大溢出连接数
|
|
36
|
+
# DATABASE_MAX_OVERFLOW=10
|
|
37
|
+
# 连接回收时间(秒)
|
|
38
|
+
# DATABASE_POOL_RECYCLE=3600
|
|
39
|
+
# 获取连接超时时间(秒)
|
|
40
|
+
# DATABASE_POOL_TIMEOUT=30
|
|
41
|
+
# 是否在获取连接前 PING
|
|
42
|
+
# DATABASE_POOL_PRE_PING=true
|
|
43
|
+
# 是否输出 SQL 语句(调试用)
|
|
44
|
+
# DATABASE_ECHO=false
|
|
45
|
+
|
|
46
|
+
# =============================================================================
|
|
47
|
+
# 缓存配置 (CACHE_)
|
|
48
|
+
# =============================================================================
|
|
49
|
+
# 缓存类型: memory / redis / memcached
|
|
50
|
+
# CACHE_TYPE=memory
|
|
51
|
+
# Redis/Memcached URL
|
|
52
|
+
# CACHE_URL=redis://localhost:6379/0
|
|
53
|
+
# 内存缓存最大大小
|
|
54
|
+
# CACHE_MAX_SIZE=1000
|
|
55
|
+
|
|
56
|
+
# =============================================================================
|
|
57
|
+
# 日志配置 (LOG_)
|
|
58
|
+
# =============================================================================
|
|
59
|
+
# 日志级别: DEBUG / INFO / WARNING / ERROR / CRITICAL
|
|
60
|
+
# LOG_LEVEL=INFO
|
|
61
|
+
# 日志文件目录
|
|
62
|
+
# LOG_DIR=logs
|
|
63
|
+
# 日志文件轮转时间 (HH:MM 格式)
|
|
64
|
+
# LOG_ROTATION_TIME=00:00
|
|
65
|
+
# 日志文件轮转大小阈值
|
|
66
|
+
# LOG_ROTATION_SIZE=100 MB
|
|
67
|
+
# 日志文件保留天数
|
|
68
|
+
# LOG_RETENTION_DAYS=7
|
|
69
|
+
# 是否启用日志文件轮转
|
|
70
|
+
# LOG_ENABLE_FILE_ROTATION=true
|
|
71
|
+
# 是否输出日志到控制台
|
|
72
|
+
# LOG_ENABLE_CONSOLE=true
|
|
73
|
+
|
|
74
|
+
# =============================================================================
|
|
75
|
+
# 健康检查配置 (HEALTH_CHECK_)
|
|
76
|
+
# =============================================================================
|
|
77
|
+
# 健康检查端点路径
|
|
78
|
+
# HEALTH_CHECK_PATH=/api/health
|
|
79
|
+
# 是否启用健康检查端点
|
|
80
|
+
# HEALTH_CHECK_ENABLED=true
|
|
81
|
+
|
|
82
|
+
# =============================================================================
|
|
83
|
+
# 管理后台配置 (ADMIN_) - SQLAdmin Admin Console
|
|
84
|
+
# =============================================================================
|
|
85
|
+
# 是否启用管理后台(生产建议仅内网或配合反向代理)
|
|
86
|
+
# ADMIN_ENABLED=false
|
|
87
|
+
# 管理后台路径(默认 /api/admin-console,避免与业务 URL 冲突)
|
|
88
|
+
# ADMIN_PATH=/api/admin-console
|
|
89
|
+
#
|
|
90
|
+
# SQLAdmin 通常要求同步 SQLAlchemy Engine:
|
|
91
|
+
# - 若 DATABASE_URL 使用的是异步驱动(如 postgresql+asyncpg),建议显式提供同步 URL 覆盖
|
|
92
|
+
# ADMIN_DATABASE_URL=postgresql+psycopg://user:pass@localhost:5432/{project_name_snake}
|
|
93
|
+
#
|
|
94
|
+
# 可选:显式指定项目侧模块(用于注册 views/auth)
|
|
95
|
+
# ADMIN_VIEWS_MODULE={project_name_snake}.admin_console
|
|
96
|
+
#
|
|
97
|
+
# 认证(默认建议 basic / bearer;jwt/custom 通常需要自定义 backend)
|
|
98
|
+
# ADMIN_AUTH_MODE=basic
|
|
99
|
+
# ADMIN_AUTH_SECRET_KEY=CHANGE_ME_TO_A_RANDOM_SECRET
|
|
100
|
+
#
|
|
101
|
+
# basic:登录页用户名/密码
|
|
102
|
+
# ADMIN_AUTH_BASIC_USERNAME=admin
|
|
103
|
+
# ADMIN_AUTH_BASIC_PASSWORD=change_me
|
|
104
|
+
#
|
|
105
|
+
# bearer:token 白名单(也支持在登录页输入 token)
|
|
106
|
+
# ADMIN_AUTH_BEARER_TOKENS=["change_me_token"]
|
|
107
|
+
#
|
|
108
|
+
# custom/jwt:自定义认证后端(动态导入)
|
|
109
|
+
# ADMIN_AUTH_BACKEND=yourpkg.admin_auth:backend
|
|
110
|
+
|
|
111
|
+
# =============================================================================
|
|
112
|
+
# CORS 配置 (CORS_)
|
|
113
|
+
# =============================================================================
|
|
114
|
+
# 允许的 CORS 源(生产环境应设置具体域名)
|
|
115
|
+
# CORS_ORIGINS=["*"]
|
|
116
|
+
# 是否允许 CORS 凭据
|
|
117
|
+
# CORS_ALLOW_CREDENTIALS=true
|
|
118
|
+
# 允许的 CORS 方法
|
|
119
|
+
# CORS_ALLOW_METHODS=["*"]
|
|
120
|
+
# 允许的 CORS 头
|
|
121
|
+
# CORS_ALLOW_HEADERS=["*"]
|
|
122
|
+
|
|
123
|
+
# =============================================================================
|
|
124
|
+
# 调度器配置 (SCHEDULER_)
|
|
125
|
+
# =============================================================================
|
|
126
|
+
# 是否在 API 服务中启用内嵌调度器
|
|
127
|
+
# SCHEDULER_ENABLED=true
|
|
128
|
+
# 定时任务模块列表(为空时自动发现 schedules 模块)
|
|
129
|
+
# SCHEDULER_SCHEDULE_MODULES=[]
|
|
130
|
+
|
|
131
|
+
# =============================================================================
|
|
132
|
+
# 任务队列配置 (TASK_)
|
|
133
|
+
# =============================================================================
|
|
134
|
+
# 任务队列代理 URL(如 Redis 或 RabbitMQ)
|
|
135
|
+
# TASK_BROKER_URL=redis://localhost:6379/1
|
|
136
|
+
# 最大重试次数
|
|
137
|
+
# TASK_MAX_RETRIES=3
|
|
138
|
+
# 任务超时时间(秒)
|
|
139
|
+
# TASK_TIMEOUT=3600
|
|
140
|
+
|
|
141
|
+
# =============================================================================
|
|
142
|
+
# 事件总线配置 (EVENT_)
|
|
143
|
+
# =============================================================================
|
|
144
|
+
# 事件总线代理 URL(如 RabbitMQ)
|
|
145
|
+
# EVENT_BROKER_URL=amqp://guest:guest@localhost:5672/
|
|
146
|
+
# 事件交换机名称
|
|
147
|
+
# EVENT_EXCHANGE_NAME=aury.events
|
|
148
|
+
|
|
149
|
+
# =============================================================================
|
|
150
|
+
# 数据库迁移配置 (MIGRATION_)
|
|
151
|
+
# =============================================================================
|
|
152
|
+
# Alembic 配置文件路径
|
|
153
|
+
# MIGRATION_CONFIG_PATH=alembic.ini
|
|
154
|
+
# Alembic 迁移脚本目录
|
|
155
|
+
# MIGRATION_SCRIPT_LOCATION=migrations
|
|
156
|
+
# 是否自动创建迁移配置和目录
|
|
157
|
+
# MIGRATION_AUTO_CREATE=true
|
|
158
|
+
|
|
159
|
+
# =============================================================================
|
|
160
|
+
# 对象存储配置 (STORAGE_) - 基于 aury-sdk-storage
|
|
161
|
+
# =============================================================================
|
|
162
|
+
# 是否启用存储组件
|
|
163
|
+
# STORAGE_ENABLED=true
|
|
164
|
+
# 存储类型: local / s3 / cos / oss
|
|
165
|
+
# STORAGE_TYPE=local
|
|
166
|
+
#
|
|
167
|
+
# 本地存储(开发环境)
|
|
168
|
+
# STORAGE_BASE_PATH=./storage
|
|
169
|
+
#
|
|
170
|
+
# S3/COS/OSS 通用配置
|
|
171
|
+
# STORAGE_ACCESS_KEY_ID=AKIDxxxxx
|
|
172
|
+
# STORAGE_ACCESS_KEY_SECRET=xxxxx
|
|
173
|
+
# STORAGE_SESSION_TOKEN=
|
|
174
|
+
# STORAGE_ENDPOINT=https://cos.ap-guangzhou.myqcloud.com
|
|
175
|
+
# STORAGE_REGION=ap-guangzhou
|
|
176
|
+
# STORAGE_BUCKET_NAME=my-bucket-1250000000
|
|
177
|
+
# STORAGE_ADDRESSING_STYLE=virtual
|
|
178
|
+
#
|
|
179
|
+
# STS AssumeRole(可选,服务端自动刷新凭证)
|
|
180
|
+
# STORAGE_ROLE_ARN=
|
|
181
|
+
# STORAGE_ROLE_SESSION_NAME=aury-storage
|
|
182
|
+
# STORAGE_EXTERNAL_ID=
|
|
183
|
+
# STORAGE_STS_ENDPOINT=
|
|
184
|
+
# STORAGE_STS_REGION=
|
|
185
|
+
# STORAGE_STS_DURATION_SECONDS=3600
|
|
186
|
+
|
|
187
|
+
# =============================================================================
|
|
188
|
+
# RPC 客户端配置 (RPC_CLIENT_)
|
|
189
|
+
# =============================================================================
|
|
190
|
+
# 服务地址映射 {{service_name: url}}
|
|
191
|
+
# RPC_CLIENT_SERVICES={{"user-service": "http://localhost:8001"}}
|
|
192
|
+
# 默认超时时间(秒)
|
|
193
|
+
# RPC_CLIENT_DEFAULT_TIMEOUT=30
|
|
194
|
+
# 默认重试次数
|
|
195
|
+
# RPC_CLIENT_DEFAULT_RETRY_TIMES=3
|
|
196
|
+
# DNS 解析使用的协议
|
|
197
|
+
# RPC_CLIENT_DNS_SCHEME=http
|
|
198
|
+
# DNS 解析默认端口
|
|
199
|
+
# RPC_CLIENT_DNS_PORT=80
|
|
200
|
+
# 是否使用 DNS 回退(K8s/Docker Compose 自动 DNS)
|
|
201
|
+
# RPC_CLIENT_USE_DNS_FALLBACK=true
|
|
202
|
+
|
|
203
|
+
# =============================================================================
|
|
204
|
+
# RPC 服务注册配置 (RPC_SERVICE_)
|
|
205
|
+
# =============================================================================
|
|
206
|
+
# 服务名称(用于注册)
|
|
207
|
+
# RPC_SERVICE_NAME={project_name_snake}
|
|
208
|
+
# 服务地址(用于注册)
|
|
209
|
+
# RPC_SERVICE_URL=http://localhost:8000
|
|
210
|
+
# 健康检查 URL(用于注册)
|
|
211
|
+
# RPC_SERVICE_HEALTH_CHECK_URL=http://localhost:8000/api/health
|
|
212
|
+
# 是否自动注册到服务注册中心
|
|
213
|
+
# RPC_SERVICE_AUTO_REGISTER=false
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# {project_name} .gitignore
|
|
3
|
+
# =============================================================================
|
|
4
|
+
|
|
5
|
+
# -----------------------------------------------------------------------------
|
|
6
|
+
# Python
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*$py.class
|
|
11
|
+
*.so
|
|
12
|
+
.Python
|
|
13
|
+
*.manifest
|
|
14
|
+
*.spec
|
|
15
|
+
|
|
16
|
+
# -----------------------------------------------------------------------------
|
|
17
|
+
# 虚拟环境
|
|
18
|
+
# -----------------------------------------------------------------------------
|
|
19
|
+
.venv/
|
|
20
|
+
venv/
|
|
21
|
+
ENV/
|
|
22
|
+
env/
|
|
23
|
+
.eggs/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
*.egg
|
|
26
|
+
|
|
27
|
+
# -----------------------------------------------------------------------------
|
|
28
|
+
# 包管理
|
|
29
|
+
# -----------------------------------------------------------------------------
|
|
30
|
+
# uv
|
|
31
|
+
.uv/
|
|
32
|
+
|
|
33
|
+
# pip
|
|
34
|
+
pip-log.txt
|
|
35
|
+
pip-delete-this-directory.txt
|
|
36
|
+
|
|
37
|
+
# -----------------------------------------------------------------------------
|
|
38
|
+
# 测试和覆盖率
|
|
39
|
+
# -----------------------------------------------------------------------------
|
|
40
|
+
.pytest_cache/
|
|
41
|
+
.coverage
|
|
42
|
+
.coverage.*
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
*.py,cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
|
|
51
|
+
# -----------------------------------------------------------------------------
|
|
52
|
+
# 类型检查和静态分析
|
|
53
|
+
# -----------------------------------------------------------------------------
|
|
54
|
+
.mypy_cache/
|
|
55
|
+
.dmypy.json
|
|
56
|
+
dmypy.json
|
|
57
|
+
.ruff_cache/
|
|
58
|
+
.pytype/
|
|
59
|
+
|
|
60
|
+
# -----------------------------------------------------------------------------
|
|
61
|
+
# 构建和分发
|
|
62
|
+
# -----------------------------------------------------------------------------
|
|
63
|
+
dist/
|
|
64
|
+
build/
|
|
65
|
+
*.egg-info/
|
|
66
|
+
.eggs/
|
|
67
|
+
sdist/
|
|
68
|
+
wheels/
|
|
69
|
+
MANIFEST
|
|
70
|
+
|
|
71
|
+
# -----------------------------------------------------------------------------
|
|
72
|
+
# 环境配置(敏感信息)
|
|
73
|
+
# -----------------------------------------------------------------------------
|
|
74
|
+
.env
|
|
75
|
+
.env.local
|
|
76
|
+
.env.*.local
|
|
77
|
+
*.local.yml
|
|
78
|
+
*.local.yaml
|
|
79
|
+
|
|
80
|
+
# -----------------------------------------------------------------------------
|
|
81
|
+
# 日志
|
|
82
|
+
# -----------------------------------------------------------------------------
|
|
83
|
+
logs/
|
|
84
|
+
*.log
|
|
85
|
+
|
|
86
|
+
# -----------------------------------------------------------------------------
|
|
87
|
+
# IDE 和编辑器
|
|
88
|
+
# -----------------------------------------------------------------------------
|
|
89
|
+
.idea/
|
|
90
|
+
.vscode/
|
|
91
|
+
*.swp
|
|
92
|
+
*.swo
|
|
93
|
+
*~
|
|
94
|
+
*.sublime-project
|
|
95
|
+
*.sublime-workspace
|
|
96
|
+
|
|
97
|
+
# -----------------------------------------------------------------------------
|
|
98
|
+
# macOS
|
|
99
|
+
# -----------------------------------------------------------------------------
|
|
100
|
+
.DS_Store
|
|
101
|
+
.AppleDouble
|
|
102
|
+
.LSOverride
|
|
103
|
+
|
|
104
|
+
# -----------------------------------------------------------------------------
|
|
105
|
+
# Windows
|
|
106
|
+
# -----------------------------------------------------------------------------
|
|
107
|
+
Thumbs.db
|
|
108
|
+
ehthumbs.db
|
|
109
|
+
Desktop.ini
|
|
110
|
+
|
|
111
|
+
# -----------------------------------------------------------------------------
|
|
112
|
+
# 项目特定
|
|
113
|
+
# -----------------------------------------------------------------------------
|
|
114
|
+
# 数据库文件(开发用 SQLite)
|
|
115
|
+
*.db
|
|
116
|
+
*.sqlite
|
|
117
|
+
*.sqlite3
|
|
118
|
+
|
|
119
|
+
# 上传文件
|
|
120
|
+
uploads/
|
|
121
|
+
media/
|
|
122
|
+
|
|
123
|
+
# 临时文件
|
|
124
|
+
tmp/
|
|
125
|
+
temp/
|
|
126
|
+
|
|
127
|
+
# 缓存
|
|
128
|
+
.cache/
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""应用入口。
|
|
2
|
+
|
|
3
|
+
使用方式:
|
|
4
|
+
# 开发模式
|
|
5
|
+
aury server dev
|
|
6
|
+
|
|
7
|
+
# 生产模式
|
|
8
|
+
aury server prod
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from aury.boot.application.app.base import FoundationApp
|
|
12
|
+
|
|
13
|
+
from {import_prefix}api import router as api_router
|
|
14
|
+
from {import_prefix}config import AppConfig
|
|
15
|
+
|
|
16
|
+
# 创建配置
|
|
17
|
+
config = AppConfig()
|
|
18
|
+
|
|
19
|
+
# 创建应用
|
|
20
|
+
#
|
|
21
|
+
# 框架默认注册端点:
|
|
22
|
+
# - GET /api/health 健康检查(检查数据库/缓存状态)
|
|
23
|
+
#
|
|
24
|
+
# 可通过环境变量配置:
|
|
25
|
+
# - HEALTH_CHECK_PATH: 健康检查路径(默认 /api/health)
|
|
26
|
+
# - HEALTH_CHECK_ENABLED: 是否启用(默认 true)
|
|
27
|
+
#
|
|
28
|
+
app = FoundationApp(
|
|
29
|
+
title="{project_name}",
|
|
30
|
+
version="0.1.0",
|
|
31
|
+
description="{project_name} - 基于 Aury Boot",
|
|
32
|
+
config=config,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# 注册 API 路由
|
|
36
|
+
app.include_router(api_router, prefix="/api")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
import uvicorn
|
|
41
|
+
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""API 路由模块。
|
|
2
|
+
|
|
3
|
+
路由结构:
|
|
4
|
+
api/
|
|
5
|
+
├── __init__.py # 本文件,汇总路由
|
|
6
|
+
├── user.py # prefix="/v1/users"
|
|
7
|
+
└── article.py # prefix="/v1/articles"
|
|
8
|
+
|
|
9
|
+
main.py 中注册:app.include_router(api_router, prefix="/api")
|
|
10
|
+
最终路径:/api/v1/users, /api/v1/articles
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from fastapi import APIRouter
|
|
14
|
+
|
|
15
|
+
router = APIRouter()
|
|
16
|
+
|
|
17
|
+
# 注册子路由(示例)
|
|
18
|
+
# from . import example
|
|
19
|
+
# router.include_router(example.router)
|