news-classifier/crawler-module/docs/architecture.md

57 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 系统架构说明
## 整体架构
本项目采用分层架构设计:
```
┌─────────────────────────────────────┐
│ CLI Interface │ 命令行入口
└──────────────┬──────────────────────┘
┌──────────────▼──────────────────────┐
│ Crawler Layer │ 爬虫层
│ (StaticCrawler / DynamicCrawler) │
└──────────────┬──────────────────────┘
┌──────────────▼──────────────────────┐
│ Parser Layer │ 解析层
│ (NeteaseParser / Kr36Parser) │
└──────────────┬──────────────────────┘
┌──────────────▼──────────────────────┐
│ Database Layer │ 数据层
│ (Connection Pool / Repository) │
└─────────────────────────────────────┘
```
## 核心模块
### 1. 配置管理 (config/)
- 使用YAML格式存储配置
- 支持环境变量覆盖
- 类型安全的配置访问
### 2. 爬虫基类 (src/base/)
- `BaseCrawler`: 抽象基类
- `StaticCrawler`: 静态页面爬虫
- `DynamicCrawler`: 动态页面爬虫Selenium
- `Article`: 数据模型
### 3. 数据库优化 (src/database/)
- 连接池管理
- 上下文管理器
- 统一的CRUD接口
### 4. 工具模块 (src/utils/)
- 日志系统
- HTTP客户端
- Selenium驱动管理
## 设计模式
1. **模板方法模式**: 爬虫基类定义算法框架,子类实现具体步骤
2. **单例模式**: 配置管理器、连接池
3. **上下文管理器**: 数据库连接管理
4. **工厂模式**: 动态创建爬虫实例