moai-domain-backend by modu-ai/moai-adk
npx skills add https://github.com/modu-ai/moai-adk --skill moai-domain-backend后端开发精通 - 全面的后端开发模式,涵盖 API 设计、数据库集成、微服务和现代架构模式。
核心能力:
何时使用:
RESTful API 架构:
创建一个带有身份验证和响应模型的 FastAPI 应用程序。定义一个包含 id、email 和 name 字段的 Pydantic UserResponse 模型。实现带有 HTTPBearer 安全依赖项的 list_users 和 create_user 端点。list 端点返回一个 UserResponse 对象列表,而 create 端点接受一个 UserCreate 模型并返回一个 UserResponse。
GraphQL 实现:
使用 Strawberry 定义 GraphQL 类型。创建一个包含 id、email 和 name 字段的 User 类型。定义一个 Query 类型,其中包含一个异步返回 User 对象列表的 users 解析器。通过将 Query 类型传递给 strawberry.Schema 来生成模式。
使用 SQLAlchemy 的 PostgreSQL:
使用 declarative_base 定义 SQLAlchemy 模型。创建一个 User 模型,其中 id 为主键,email 为唯一字符串,name 为字符串列。使用连接池参数配置引擎,包括 pool_size 为 20,max_overflow 为 30,并启用 pool_pre_ping 以进行连接健康检查。
使用 Motor 的 MongoDB:
创建一个使用 AsyncIOMotorClient 初始化的 UserService 类。在构造函数中设置数据库和 users 集合。为 email(唯一)和 created_at 字段创建索引。实现 create_user 方法,该方法插入文档并将 inserted_id 作为字符串返回。
使用 Consul 的服务发现:
创建一个连接到 Consul 的 ServiceRegistry 类。实现 register_service 方法,该方法使用名称、id、端口和健康检查端点注册服务。实现 discover_service 方法,该方法查询健康服务并返回 adddess:port 字符串列表。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
事件驱动架构:
使用 aio_pika 创建一个用于 AMQP 消息传递的 EventBus 类。实现 connect 方法来建立连接和通道。实现 publish_event 方法,该方法将事件类型和数据序列化为 JSON,并使用与事件类型匹配的 routing_key 发布到默认交换器。
Redis 集成:
创建一个带有 Redis 连接的 CacheManager 类。实现一个接受 ttl 参数的 cache_result 装饰器。该装饰器从函数名称和参数生成缓存键,检查 Redis 中的缓存结果,在缓存未命中时执行函数,并存储带有过期时间的结果。使用 json.loads 和 json.dumps 进行序列化。
JWT 身份验证:
创建一个带有用于 bcrypt 密码哈希的 CryptContext 的 SecurityManager 类。使用该上下文实现 hash_password 和 verify_password 方法。实现 create_access_token,该方法使用 HS256 算法编码带有过期时间的 JWT。如果未指定,默认过期时间为 15 分钟。
数据库连接池:
创建一个优化的 SQLAlchemy 引擎,使用 QueuePool,pool_size 为 20,max_overflow 为 30,启用 pool_pre_ping,pool_recycle 为 3600 秒。添加 before_cursor_execute 和 after_cursor_execute 的事件监听器以跟踪查询时间。对超过 100ms 阈值的查询记录警告。
主要技术:
集成模式:
有关工作代码示例,请参阅 examples.md。
状态:生产就绪 最后更新:2026-01-11 维护者:MoAI-ADK 后端团队
每周安装次数
103
仓库
GitHub 星标数
888
首次出现
2026年1月19日
安全审计
安装于
codex82
gemini-cli80
opencode80
claude-code79
cursor77
antigravity76
Backend Development Mastery - Comprehensive backend development patterns covering API design, database integration, microservices, and modern architecture patterns.
Core Capabilities:
When to Use:
RESTful API Architecture:
Create a FastAPI application with authentication and response models. Define a Pydantic UserResponse model with id, email, and name fields. Implement list_users and create_user endpoints with HTTPBearer security dependency. The list endpoint returns a list of UserResponse objects, while the create endpoint accepts a UserCreate model and returns a single UserResponse.
GraphQL Implementation:
Use Strawberry to define GraphQL types. Create a User type with id, email, and name fields. Define a Query type with a users resolver that returns a list of User objects asynchronously. Generate the schema by passing the Query type to strawberry.Schema.
PostgreSQL with SQLAlchemy:
Define SQLAlchemy models using declarative_base. Create a User model with id as primary key, email as unique string, and name as string column. Configure the engine with connection pooling parameters including pool_size of 20, max_overflow of 30, and pool_pre_ping enabled for connection health checks.
MongoDB with Motor:
Create a UserService class that initializes with an AsyncIOMotorClient. Set up the database and users collection in the constructor. Create indexes for email (unique) and created_at fields. Implement create_user method that inserts a document and returns the inserted_id as string.
Service Discovery with Consul:
Create a ServiceRegistry class that connects to Consul. Implement register_service method that registers a service with name, id, port, and health check endpoint. Implement discover_service method that queries healthy services and returns list of adddess:port strings.
Event-Driven Architecture:
Create an EventBus class using aio_pika for AMQP messaging. Implement connect method to establish connection and channel. Implement publish_event method that serializes event type and data as JSON and publishes to the default exchange with routing_key matching the event type.
Redis Integration:
Create a CacheManager class with Redis connection. Implement a cache_result decorator that accepts ttl parameter. The decorator generates cache keys from function name and arguments, checks Redis for cached results, executes the function on cache miss, and stores results with expiration. Use json.loads and json.dumps for serialization.
JWT Authentication:
Create a SecurityManager class with CryptContext for bcrypt password hashing. Implement hash_password and verify_password methods using the context. Implement create_access_token that encodes a JWT with expiration time using HS256 algorithm. Default expiration is 15 minutes if not specified.
Database Connection Pooling:
Create an optimized SQLAlchemy engine with QueuePool, pool_size 20, max_overflow 30, pool_pre_ping enabled, and pool_recycle of 3600 seconds. Add event listeners for before_cursor_execute and after_cursor_execute to track query timing. Log warnings for queries exceeding 100ms threshold.
Primary Technologies:
Integration Patterns:
For working code examples, see examples.md.
Status: Production Ready Last Updated: 2026-01-11 Maintained by: MoAI-ADK Backend Team
Weekly Installs
103
Repository
GitHub Stars
888
First Seen
Jan 19, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex82
gemini-cli80
opencode80
claude-code79
cursor77
antigravity76
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
163,300 周安装