Senior Architect
Architecture design and analysis tools for making informed technical decisions.
Table of Contents
-
Architecture Diagram Generator
-
Dependency Analyzer
-
Project Architect
-
Database Selection
-
Architecture Pattern Selection
-
Monolith vs Microservices
Quick Start
CODEBLOCK0
Tools Overview
1. Architecture Diagram Generator
Generates architecture diagrams from project structure in multiple formats.
Solves: "I need to visualize my system architecture for documentation or team discussion"
Input: Project directory path
Output: Diagram code (Mermaid, PlantUML, or ASCII)
Supported diagram types:
- -
component - Shows modules and their relationships - INLINECODE1 - Shows architectural layers (presentation, business, data)
- INLINECODE2 - Shows deployment topology
Usage:
CODEBLOCK1
Example output (Mermaid):
graph TD
A[API Gateway] --> B[Auth Service]
A --> C[User Service]
B --> D[(PostgreSQL)]
C --> D
2. Dependency Analyzer
Analyzes project dependencies for coupling, circular dependencies, and outdated packages.
Solves: "I need to understand my dependency tree and identify potential issues"
Input: Project directory path
Output: Analysis report (JSON or human-readable)
Analyzes:
- - Dependency tree (direct and transitive)
- Circular dependencies between modules
- Coupling score (0-100)
- Outdated packages
Supported package managers:
- - npm/yarn (
package.json) - Python (
requirements.txt, pyproject.toml) - Go (
go.mod) - Rust (
Cargo.toml)
Usage:
CODEBLOCK3
Example output:
Dependency Analysis Report
==========================
Total dependencies: 47 (32 direct, 15 transitive)
Coupling score: 72/100 (moderate)
Issues found:
- CIRCULAR: auth → user → permissions → auth
- OUTDATED: lodash 4.17.15 → 4.17.21 (security)
Recommendations:
1. Extract shared interface to break circular dependency
2. Update lodash to fix CVE-2020-8203
3. Project Architect
Analyzes project structure and detects architectural patterns, code smells, and improvement opportunities.
Solves: "I want to understand the current architecture and identify areas for improvement"
Input: Project directory path
Output: Architecture assessment report
Detects:
- - Architectural patterns (MVC, layered, hexagonal, microservices indicators)
- Code organization issues (god classes, mixed concerns)
- Layer violations
- Missing architectural components
Usage:
CODEBLOCK5
Example output:
Architecture Assessment
=======================
Detected pattern: Layered Architecture (confidence: 85%)
Structure analysis:
✓ controllers/ - Presentation layer detected
✓ services/ - Business logic layer detected
✓ repositories/ - Data access layer detected
⚠ models/ - Mixed domain and DTOs
Issues:
- LARGE FILE: UserService.ts (1,847 lines) - consider splitting
- MIXED CONCERNS: PaymentController contains business logic
Recommendations:
1. Split UserService into focused services
2. Move business logic from controllers to services
3. Separate domain models from DTOs
Decision Workflows
Database Selection Workflow
Use when choosing a database for a new project or migrating existing data.
Step 1: Identify data characteristics
| Characteristic | Points to SQL | Points to NoSQL |
|---|
| Structured with relationships | ✓ | |
| ACID transactions required |
✓ | |
| Flexible/evolving schema | | ✓ |
| Document-oriented data | | ✓ |
| Time-series data | | ✓ (specialized) |
Step 2: Evaluate scale requirements
- - <1M records, single region → PostgreSQL or MySQL
- 1M-100M records, read-heavy → PostgreSQL with read replicas
- >100M records, global distribution → CockroachDB, Spanner, or DynamoDB
- High write throughput (>10K/sec) → Cassandra or ScyllaDB
Step 3: Check consistency requirements
- - Strong consistency required → SQL or CockroachDB
- Eventual consistency acceptable → DynamoDB, Cassandra, MongoDB
Step 4: Document decision
Create an ADR (Architecture Decision Record) with:
- - Context and requirements
- Options considered
- Decision and rationale
- Trade-offs accepted
Quick reference:
PostgreSQL → Default choice for most applications
MongoDB → Document store, flexible schema
Redis → Caching, sessions, real-time features
DynamoDB → Serverless, auto-scaling, AWS-native
TimescaleDB → Time-series data with SQL interface
Architecture Pattern Selection Workflow
Use when designing a new system or refactoring existing architecture.
Step 1: Assess team and project size
| Team Size | Recommended Starting Point |
|---|
| 1-3 developers | Modular monolith |
| 4-10 developers |
Modular monolith or service-oriented |
| 10+ developers | Consider microservices |
Step 2: Evaluate deployment requirements
- - Single deployment unit acceptable → Monolith
- Independent scaling needed → Microservices
- Mixed (some services scale differently) → Hybrid
Step 3: Consider data boundaries
- - Shared database acceptable → Monolith or modular monolith
- Strict data isolation required → Microservices with separate DBs
- Event-driven communication fits → Event-sourcing/CQRS
Step 4: Match pattern to requirements
| Requirement | Recommended Pattern |
|---|
| Rapid MVP development | Modular Monolith |
| Independent team deployment |
Microservices |
| Complex domain logic | Domain-Driven Design |
| High read/write ratio difference | CQRS |
| Audit trail required | Event Sourcing |
| Third-party integrations | Hexagonal/Ports & Adapters |
See references/architecture_patterns.md for detailed pattern descriptions.
Monolith vs Microservices Decision
Choose Monolith when:
- - [ ] Team is small (<10 developers)
- [ ] Domain boundaries are unclear
- [ ] Rapid iteration is priority
- [ ] Operational complexity must be minimized
- [ ] Shared database is acceptable
Choose Microservices when:
- - [ ] Teams can own services end-to-end
- [ ] Independent deployment is critical
- [ ] Different scaling requirements per component
- [ ] Technology diversity is needed
- [ ] Domain boundaries are well understood
Hybrid approach:
Start with a modular monolith. Extract services only when:
- 1. A module has significantly different scaling needs
- A team needs independent deployment
- Technology constraints require separation
Reference Documentation
Load these files for detailed information:
| File | Contains | Load when user asks about |
|---|
| INLINECODE9 | 9 architecture patterns with trade-offs, code examples, and when to use | "which pattern?", "microservices vs monolith", "event-driven", "CQRS" |
| INLINECODE10 |
6 step-by-step workflows for system design tasks | "how to design?", "capacity planning", "API design", "migration" |
|
references/tech_decision_guide.md | Decision matrices for technology choices | "which database?", "which framework?", "which cloud?", "which cache?" |
Tech Stack Coverage
Languages: TypeScript, JavaScript, Python, Go, Swift, Kotlin, Rust
Frontend: React, Next.js, Vue, Angular, React Native, Flutter
Backend: Node.js, Express, FastAPI, Go, GraphQL, REST
Databases: PostgreSQL, MySQL, MongoDB, Redis, DynamoDB, Cassandra
Infrastructure: Docker, Kubernetes, Terraform, AWS, GCP, Azure
CI/CD: GitHub Actions, GitLab CI, CircleCI, Jenkins
Common Commands
CODEBLOCK8
Getting Help
- 1. Run any script with
--help for usage information - Check reference documentation for detailed patterns and workflows
- Use
--verbose flag for detailed explanations and recommendations
高级架构师
用于做出明智技术决策的架构设计与分析工具。
目录
-
架构图生成器
-
依赖分析器
-
项目架构师
-
数据库选型
-
架构模式选型
-
单体架构与微服务
快速开始
bash
从项目生成架构图
python scripts/architecture
diagramgenerator.py ./my-project --format mermaid
分析依赖问题
python scripts/dependency_analyzer.py ./my-project --output json
获取架构评估
python scripts/project_architect.py ./my-project --verbose
工具概览
1. 架构图生成器
从项目结构生成多种格式的架构图。
解决问题: 我需要可视化系统架构,用于文档编写或团队讨论
输入: 项目目录路径
输出: 图表代码(Mermaid、PlantUML 或 ASCII)
支持的图表类型:
- - component - 展示模块及其关系
- layer - 展示架构层级(表现层、业务层、数据层)
- deployment - 展示部署拓扑
使用方法:
bash
Mermaid 格式(默认)
python scripts/architecture
diagramgenerator.py ./project --format mermaid --type component
PlantUML 格式
python scripts/architecture
diagramgenerator.py ./project --format plantuml --type layer
ASCII 格式(终端友好)
python scripts/architecture
diagramgenerator.py ./project --format ascii
保存到文件
python scripts/architecture
diagramgenerator.py ./project -o architecture.md
示例输出(Mermaid):
mermaid
graph TD
A[API 网关] --> B[认证服务]
A --> C[用户服务]
B --> D[(PostgreSQL)]
C --> D
2. 依赖分析器
分析项目依赖中的耦合、循环依赖和过时包。
解决问题: 我需要了解依赖树并识别潜在问题
输入: 项目目录路径
输出: 分析报告(JSON 或人类可读格式)
分析内容:
- - 依赖树(直接和传递依赖)
- 模块间的循环依赖
- 耦合度评分(0-100)
- 过时包
支持的包管理器:
- - npm/yarn(package.json)
- Python(requirements.txt、pyproject.toml)
- Go(go.mod)
- Rust(Cargo.toml)
使用方法:
bash
人类可读报告
python scripts/dependency_analyzer.py ./project
JSON 输出,用于 CI/CD 集成
python scripts/dependency_analyzer.py ./project --output json
仅检查循环依赖
python scripts/dependency_analyzer.py ./project --check circular
详细模式,附带建议
python scripts/dependency_analyzer.py ./project --verbose
示例输出:
依赖分析报告
==========================
总依赖数:47(32 个直接依赖,15 个传递依赖)
耦合度评分:72/100(中等)
发现的问题:
- - 循环依赖:auth → user → permissions → auth
- 过时包:lodash 4.17.15 → 4.17.21(安全问题)
建议:
- 1. 提取共享接口以打破循环依赖
- 更新 lodash 以修复 CVE-2020-8203
3. 项目架构师
分析项目结构,检测架构模式、代码异味和改进机会。
解决问题: 我想了解当前架构并识别改进领域
输入: 项目目录路径
输出: 架构评估报告
检测内容:
- - 架构模式(MVC、分层架构、六边形架构、微服务特征)
- 代码组织问题(上帝类、关注点混杂)
- 层级违规
- 缺失的架构组件
使用方法:
bash
全面评估
python scripts/project_architect.py ./project
详细模式,附带具体建议
python scripts/project_architect.py ./project --verbose
JSON 输出
python scripts/project_architect.py ./project --output json
检查特定方面
python scripts/project_architect.py ./project --check layers
示例输出:
架构评估
=======================
检测到的模式:分层架构(置信度:85%)
结构分析:
✓ controllers/ - 检测到表现层
✓ services/ - 检测到业务逻辑层
✓ repositories/ - 检测到数据访问层
⚠ models/ - 领域模型与 DTO 混杂
问题:
- - 文件过大:UserService.ts(1,847 行)- 建议拆分
- 关注点混杂:PaymentController 包含业务逻辑
建议:
- 1. 将 UserService 拆分为专注的服务
- 将业务逻辑从控制器移至服务层
- 分离领域模型与 DTO
决策工作流
数据库选型工作流
适用于为新项目选择数据库或迁移现有数据时使用。
步骤 1:识别数据特征
| 特征 | 倾向于 SQL | 倾向于 NoSQL |
|---|
| 结构化且有关联 | ✓ | |
| 需要 ACID 事务 |
✓ | |
| 灵活/演进的模式 | | ✓ |
| 面向文档的数据 | | ✓ |
| 时序数据 | | ✓(专用) |
步骤 2:评估规模需求
- - <100 万条记录,单区域 → PostgreSQL 或 MySQL
- 100 万至 1 亿条记录,读密集型 → PostgreSQL 搭配只读副本
- >1 亿条记录,全球分布 → CockroachDB、Spanner 或 DynamoDB
- 高写入吞吐量(>1 万/秒)→ Cassandra 或 ScyllaDB
步骤 3:检查一致性需求
- - 需要强一致性 → SQL 或 CockroachDB
- 可接受最终一致性 → DynamoDB、Cassandra、MongoDB
步骤 4:记录决策
创建 ADR(架构决策记录),包含:
快速参考:
PostgreSQL → 大多数应用的默认选择
MongoDB → 文档存储,灵活模式
Redis → 缓存、会话、实时功能
DynamoDB → 无服务器、自动扩展、AWS 原生
TimescaleDB → 时序数据,支持 SQL 接口
架构模式选型工作流
适用于设计新系统或重构现有架构时使用。
步骤 1:评估团队和项目规模
| 团队规模 | 推荐的起点 |
|---|
| 1-3 名开发者 | 模块化单体架构 |
| 4-10 名开发者 |
模块化单体架构或面向服务架构 |
| 10 名以上开发者 | 考虑微服务 |
步骤 2:评估部署需求
- - 可接受单一部署单元 → 单体架构
- 需要独立扩展 → 微服务
- 混合模式(部分服务扩展需求不同)→ 混合架构
步骤 3:考虑数据边界
- - 可接受共享数据库 → 单体架构或模块化单体架构
- 需要严格数据隔离 → 微服务搭配独立数据库
- 适合事件驱动通信 → 事件溯源/CQRS
步骤 4:匹配模式与需求
| 需求 | 推荐模式 |
|---|
| 快速 MVP 开发 | 模块化单体架构 |
| 独立团队部署 |
微服务 |
| 复杂领域逻辑 | 领域驱动设计 |
| 读写比例差异大 | CQRS |
| 需要审计追踪 | 事件溯源 |
| 第三方集成 | 六边形架构/端口与适配器 |
详细模式描述请参见 references/architecture_patterns.md。
单体架构与微服务决策
选择单体架构的情况:
- - [ ] 团队规模小(少于 10 名开发者)
- [ ] 领域边界不清晰
- [ ] 快速迭代是优先事项
- [ ] 必须最小化运维复杂度
- [ ] 可接受共享数据库
选择微服务的情况:
- - [ ] 团队可以端到端拥有服务
- [ ] 独立部署至关重要
- [ ] 各组件扩展需求不同
- [ ] 需要技术多样性
- [ ] 领域边界清晰明确
混合方法: