Loading...
Loading...
Compare original and translation side by side
/architect [arguments]/architect [arguments]undefinedundefinedundefinedundefined┌─────────────────────────────────────────────┐
│ Client Apps │
│ (Web, iOS, Android) │
└────────────────┬────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ API Gateway / Load Balancer │
└────────────────┬────────────────────────────┘
│
┌────────┴────────┐
▼ ▼
┌───────────────┐ ┌───────────────┐
│ Auth │ │ Core API │
│ Service │ │ Service │
└───────┬───────┘ └───────┬───────┘
│ │
│ ┌────────┴────────┐
│ ▼ ▼
│ ┌──────────────┐ ┌──────────────┐
│ │ PostgreSQL │ │ Redis │
│ │ (Primary) │ │ (Cache) │
│ └──────────────┘ └──────────────┘
│
▼
┌───────────────┐
│ User DB │
└───────────────┘undefined┌─────────────────────────────────────────────┐
│ Client Apps │
│ (Web, iOS, Android) │
└────────────────┬────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ API Gateway / Load Balancer │
└────────────────┬────────────────────────────┘
│
┌────────┴────────┐
▼ ▼
┌───────────────┐ ┌───────────────┐
│ Auth │ │ Core API │
│ Service │ │ Service │
└───────┬───────┘ └───────┬───────┘
│ │
│ ┌────────┴────────┐
│ ▼ ▼
│ ┌──────────────┐ ┌──────────────┐
│ │ PostgreSQL │ │ Redis │
│ │ (Primary) │ │ (Cache) │
│ └──────────────┘ └──────────────┘
│
▼
┌───────────────┐
│ User DB │
└───────────────┘undefinedundefinedundefinedundefinedundefined{
"email": "user@example.com",
"password": "secure_password"
}{
"token": "eyJ...",
"user": {
"id": "123",
"email": "user@example.com",
"name": "John Doe"
}
}undefined{
"email": "user@example.com",
"password": "secure_password"
}{
"token": "eyJ...",
"user": {
"id": "123",
"email": "user@example.com",
"name": "John Doe"
}
}undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
┌─────────────┐ ┌─────────────┐ ┌──────────────┐
│ Client │────▶│ API │────▶│ Database │
└─────────────┘ └─────────────┘ └──────────────┘
│
▼
┌─────────────┐
│ Cache │
└─────────────┘
┌─────────────┐ ┌─────────────┐ ┌──────────────┐
│ Client │────▶│ API │────▶│ Database │
└─────────────┘ └─────────────┘ └──────────────┘
│
▼
┌─────────────┐
│ Cache │
└─────────────┘
| Risk | Impact | Probability | Mitigation |
|---|---|---|---|
| [Risk 1] | High | Medium | [How to mitigate] |
| [Risk 2] | Medium | Low | [How to mitigate] |
| 风险 | 影响 | 概率 | 缓解方案 |
|---|---|---|---|
| [风险1] | 高 | 中 | [缓解措施] |
| [风险2] | 中 | 低 | [缓解措施] |
undefinedundefinedBAD: Microservices from day 1 with 20 services
GOOD: Start with monolith, split when needed错误做法:第一天就搭建20个服务的微服务架构
正确做法:从单体应用开始,需要时再拆分GOOD:
- Auth Service: Authentication only
- User Service: User profile management
- Order Service: Order processing
BAD:
- God Service: Does everything正确做法:
- 认证服务:仅负责认证
- 用户服务:仅负责用户资料管理
- 订单服务:仅负责订单处理
错误做法:
- 上帝服务:包揽所有功能// BAD: Tight coupling
class OrderService {
constructor(private db: PostgresDatabase) {}
}
// GOOD: Loose coupling
class OrderService {
constructor(private db: Database) {} // Interface
}// 错误:紧耦合
class OrderService {
constructor(private db: PostgresDatabase) {}
}
// 正确:松耦合
class OrderService {
constructor(private db: Database) {} // 接口
}GOOD:
user/
- create_user.ts
- update_user.ts
- delete_user.ts
- user_repository.ts
BAD:
create/
- create_user.ts
- create_order.ts
update/
- update_user.ts
- update_order.ts正确做法:
user/
- create_user.ts
- update_user.ts
- delete_user.ts
- user_repository.ts
错误做法:
create/
- create_user.ts
- create_order.ts
update/
- update_user.ts
- update_order.ts// BAD: Implicit dependency
function processOrder(orderId: string) {
const db = global.database // Where does this come from?
// ...
}
// GOOD: Explicit dependency
function processOrder(
orderId: string,
db: Database,
logger: Logger
) {
// Dependencies are clear
}// 错误:隐式依赖
function processOrder(orderId: string) {
const db = global.database // 这个来自哪里?
// ...
}
// 正确:显式依赖
function processOrder(
orderId: string,
db: Database,
logger: Logger
) {
// 依赖关系清晰
}// BAD: Silent failure
function divide(a: number, b: number) {
if (b === 0) return 0 // Wrong!
return a / b
}
// GOOD: Fail fast
function divide(a: number, b: number) {
if (b === 0) {
throw new Error('Division by zero')
}
return a / b
}// 错误:静默失败
function divide(a: number, b: number) {
if (b === 0) return 0 // 错误!
return a / b
}
// 正确:快速失败
function divide(a: number, b: number) {
if (b === 0) {
throw new Error('Division by zero')
}
return a / b
}// BAD: Hard to test
class OrderService {
processOrder(orderId: string) {
const db = new PostgresDatabase() // Can't mock
const api = new PaymentAPI() // Can't mock
// ...
}
}
// GOOD: Easy to test
class OrderService {
constructor(
private db: Database, // Can inject mock
private api: PaymentAPI // Can inject mock
) {}
processOrder(orderId: string) {
// ...
}
}// 错误:难以测试
class OrderService {
processOrder(orderId: string) {
const db = new PostgresDatabase() // 无法模拟
const api = new PaymentAPI() // 无法模拟
// ...
}
}
// 正确:易于测试
class OrderService {
constructor(
private db: Database, // 可注入模拟实现
private api: PaymentAPI // 可注入模拟实现
) {}
processOrder(orderId: string) {
// ...
}
}┌─────────────────────┐
│ Presentation │ (UI, API controllers)
├─────────────────────┤
│ Business Logic │ (Domain, services)
├─────────────────────┤
│ Data Access │ (Repositories, ORMs)
├─────────────────────┤
│ Database │ (Storage)
└─────────────────────┘┌─────────────────────┐
│ 表现层 │ (UI、API控制器)
├─────────────────────┤
│ 业务逻辑层 │ (领域模型、服务)
├─────────────────────┤
│ 数据访问层 │ (仓库、ORM)
├─────────────────────┤
│ 数据库层 │ (存储)
└─────────────────────┘ ┌───────────────────────┐
│ External Systems │
│ (UI, DB, APIs) │
└──────────┬────────────┘
│
┌──────────▼────────────┐
│ Adapters │ (Implementation)
│ (REST, PostgreSQL) │
└──────────┬────────────┘
│
┌──────────▼────────────┐
│ Ports │ (Interfaces)
│ (IUserRepo, IAuth) │
└──────────┬────────────┘
│
┌──────────▼────────────┐
│ Core Domain │ (Business logic)
│ (Pure logic) │
└───────────────────────┘ ┌───────────────────────┐
│ 外部系统 │
│ (UI、DB、APIs) │
└──────────┬────────────┘
│
┌──────────▼────────────┐
│ 适配器 │ (实现)
│ (REST、PostgreSQL) │
└──────────┬────────────┘
│
┌──────────▼────────────┐
│ 端口 │ (接口)
│ (IUserRepo、IAuth) │
└──────────┬────────────┘
│
┌──────────▼────────────┐
│ 核心领域 │ (业务逻辑)
│ (纯逻辑) │
└───────────────────────┘┌─────────┐ ┌─────────┐ ┌─────────┐
│ User │ │ Order │ │ Payment │
│ Service │ │ Service │ │ Service │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
└────────────┴────────────┘
│
┌───────▼────────┐
│ Message Bus │
│ (Event-driven)│
└────────────────┘┌─────────┐ ┌─────────┐ ┌─────────┐
│ 用户服务│ │ 订单服务│ │ 支付服务│
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
└────────────┴────────────┘
│
┌───────▼────────┐
│ 消息总线 │
│ (事件驱动) │
└────────────────┘┌─────────┐ ┌─────────────┐ ┌─────────┐
│Producer │──────▶│ Event Bus │──────▶│Consumer │
└─────────┘ └─────────────┘ └─────────┘┌─────────┐ ┌─────────────┐ ┌─────────┐
│生产者 │──────▶│ 事件总线 │──────▶│消费者 │
└─────────┘ └─────────────┘ └─────────┘BAD: Build microservices for 100 users
GOOD: Start with monolith, split when needed错误做法:为100个用户搭建微服务
正确做法:从单体应用开始,需要时再拆分BAD: "I want to learn Kubernetes, let's use it"
GOOD: "Kubernetes fits our scale needs"错误做法:「我想学习Kubernetes,所以我们用它」
正确做法:「Kubernetes符合我们的规模需求」BAD: Service A can't deploy without Service B
GOOD: Services are independently deployable错误做法:服务A部署必须依赖服务B
正确做法:服务可独立部署BAD: Any code can call any other code
GOOD: Clear layers and boundaries错误做法:任何代码都能调用其他代码
正确做法:清晰的分层与边界BAD: Spend months on perfect architecture
GOOD: Design enough to start, iterate错误做法:花费数月追求完美架构
正确做法:设计到足够启动的程度,再迭代优化