原文链接
https://novusai-saas.github.io/ja/ja/docs/business-services/common-business-services/common-business-services.md通用业务服务
本文引用的源码与文档
本文引用的文件
- auth_service.py
- email_service.py
- notification_service.py
- storage_quota_service.py
- email_templates.py
- image_process_service.py
- file_validator.py
- storage_config_resolver.py
- channels/base.py
- channels/email_channel.py
- channels/inbox_channel.py
- channels/webhook_channel.py
- channels/ws_channel.py
- auth_domains/admin_auth.py
- auth_domains/tenant_user_auth.py
- auth_domains/tenant_user_login.py
- auth_domains/tenant_user_login_code.py
- auth_domains/captcha_verification.py
- auth_domains/session_password.py
- auth_domains/login_security.py
- auth_domains/logging_bootstrap.py
- storage/manager.py
- storage/base.py
- storage/drivers/local.py
- tasks/email.py
- tasks/notification.py
- templates/email/base.html
- templates/email/login_code.html
- templates/email/password_reset.html
- templates/email/verification_code.html
- templates/email/welcome.html
- utils/image.py
- exceptions/base.py
- exceptions/storage.py
- core/security.py
- core/rate_limit.py
- core/runtime_identity.py
- core/redis.py
- core/database.py
- core/logging.py
- core/scope.py
- core/deps.py
- core/config.py
- core/base_service.py
- core/identity.py
- core/query_parser.py
- core/cors.py
- core/i18n.py
- core/org_authority.py
- core/data_permission.py
- core/recycle_bin.py
- core/response.py
- core/socketio_server.py
- core/sse.py
- core/sio_bridge.py
- core/host_read_facade.py
- core/github_source_policy.py
- core/hosts_helper.py
- core/tenant.py
- core/audit_log.py
- core/middleware/trace.py
- core/middleware/permission.py
- core/middleware/tenant.py
- core/middleware/dynamic_cors.py
- core/middleware/prometheus_metrics.py
- core/middleware/audit_log.py
- core/middleware/i18n.py
- core/middleware/access_control.py
- core/middleware/nocache.py
- core/middleware/maintenance.py
- core/middleware/prometheus_metrics.py
目录
简介
本文件系统性梳理通用业务服务的设计原则与实现模式,覆盖认证服务、邮件服务、通知服务、存储配额管理等跨领域能力,并对公共接口、安全机制、数据验证规则进行文档化。同时阐述邮件模板管理、图片处理流程与文件验证策略,说明通用服务与各业务域的集成方式与依赖关系,给出配置管理、错误处理与性能优化策略,并提供使用示例与扩展指导。
项目结构
通用业务服务主要位于后端应用的服务层 common 包中,围绕认证、邮件、通知、存储配额、通道分发、模板与工具展开;存储子系统独立于通用服务但被其复用;任务层负责异步处理邮件与通知;模板目录提供邮件 HTML 模板;工具模块提供图片处理能力。
图表来源
- auth_service.py
- email_service.py
- notification_service.py
- storage_quota_service.py
- email_templates.py
- image_process_service.py
- file_validator.py
- storage_config_resolver.py
- channels/base.py
- channels/email_channel.py
- channels/inbox_channel.py
- channels/webhook_channel.py
- channels/ws_channel.py
- storage/manager.py
- storage/base.py
- storage/drivers/local.py
- tasks/email.py
- tasks/notification.py
- templates/email/base.html
- utils/image.py
章节来源
- auth_service.py
- email_service.py
- notification_service.py
- storage_quota_service.py
- email_templates.py
- image_process_service.py
- file_validator.py
- storage_config_resolver.py
- channels/base.py
- channels/email_channel.py
- channels/inbox_channel.py
- channels/webhook_channel.py
- channels/ws_channel.py
- storage/manager.py
- storage/base.py
- storage/drivers/local.py
- tasks/email.py
- tasks/notification.py
- templates/email/base.html
- utils/image.py
核心组件
- 认证服务:统一登录态管理、会话密码校验、登录安全策略、验证码校验与登录域适配(管理员域、租户用户域)。
- 邮件服务:邮件发送、模板渲染、模板管理、异步任务编排。
- 通知服务:多通道分发(站内信、Webhook、WebSocket),偏好与清理策略。
- 存储配额服务:配额计算、限额检查、用量追踪与回收站联动。
- 图片处理服务:缩略图生成、尺寸裁剪、格式转换与水印等。
- 文件验证器:类型白名单、大小限制、内容安全扫描。
- 存储配置解析:按租户/环境选择存储驱动与参数。
- 通道体系:抽象通道基类与具体通道实现,支持扩展与组合。
章节来源
- auth_service.py
- email_service.py
- notification_service.py
- storage_quota_service.py
- email_templates.py
- image_process_service.py
- file_validator.py
- storage_config_resolver.py
- channels/base.py
- channels/email_channel.py
- channels/inbox_channel.py
- channels/webhook_channel.py
- channels/ws_channel.py
架构总览
通用服务通过“服务层 + 通道层 + 存储层 + 任务层 + 模板层 + 工具层”的协作,形成可插拔 、可扩展的跨域通用能力。认证域适配不同登录场景;邮件与通知通过通道分发到多种下游;存储配额与文件验证贯穿上传链路;图片处理与模板渲染提升用户体验。
图表来源
- auth_service.py
- email_service.py
- notification_service.py
- storage_quota_service.py
- email_templates.py
- channels/base.py
- channels/email_channel.py
- channels/inbox_channel.py
- channels/webhook_channel.py
- channels/ws_channel.py
- storage/manager.py
- storage/drivers/local.py
- tasks/email.py
- tasks/notification.py
- image_process_service.py
- utils/image.py
- file_validator.py