Update Architecture

2025-11-12 15:51:32 +00:00
parent 7897ef4937
commit acdca2c3fd

@@ -2,7 +2,7 @@
The bot follows a modular, async-first architecture designed for reliability, performance, and maintainability.
### System Architecture
## System Architecture
```
┌─────────────────────────────────────────────────────────────┐
@@ -45,9 +45,9 @@ The bot follows a modular, async-first architecture designed for reliability, pe
└─────────────────────────────────────────────────────────────┘
```
### Core Components
## Core Components
#### 1. **PterodactylBot** (`pterodisbot.py`)
### 1. **PterodactylBot** (`pterodisbot.py`)
Main orchestrator class that coordinates all bot operations.
**Responsibilities:**
@@ -70,7 +70,7 @@ Main orchestrator class that coordinates all bot operations.
- **Strategy Pattern**: Different update strategies based on state changes
- **Factory Pattern**: Creates embeds and views dynamically
#### 2. **PterodactylAPI** (`pterodisbot.py`)
### 2. **PterodactylAPI** (`pterodisbot.py`)
Abstraction layer for all Pterodactyl Panel API interactions.
**Responsibilities:**
@@ -90,7 +90,7 @@ Abstraction layer for all Pterodactyl Panel API interactions.
- Automatic retry with exponential backoff
- Comprehensive error response handling
#### 3. **ServerMetricsGraphs** (`server_metrics_graphs.py`)
### 3. **ServerMetricsGraphs** (`server_metrics_graphs.py`)
Time-series data tracking and visualization for individual servers.
**Responsibilities:**
@@ -116,7 +116,7 @@ deque([
], maxlen=6)
```
#### 4. **ServerMetricsManager** (`server_metrics_graphs.py`)
### 4. **ServerMetricsManager** (`server_metrics_graphs.py`)
Global coordinator for all server metrics tracking.
**Responsibilities:**
@@ -131,7 +131,7 @@ Global coordinator for all server metrics tracking.
- Summary statistics generation
- Thread-safe operations
#### 5. **ServerStatusView** (`pterodisbot.py`)
### 5. **ServerStatusView** (`pterodisbot.py`)
Discord UI component providing interactive server controls.
**Responsibilities:**
@@ -152,9 +152,9 @@ Discord UI component providing interactive server controls.
- Interaction-level authorization checks
- Ephemeral responses for sensitive data
### Data Flow
## Data Flow
#### Server Status Update Flow
### Server Status Update Flow
```
1. Background Task (every 10s)
@@ -184,7 +184,7 @@ Discord UI component providing interactive server controls.
└─> Determine if update needed
```
#### User Interaction Flow
### User Interaction Flow
```
1. User Types /server_status
@@ -211,7 +211,7 @@ Discord UI component providing interactive server controls.
└─> Send ephemeral response
```
### Configuration System
## Configuration System
The bot uses a multi-layer configuration system:
@@ -232,9 +232,9 @@ The bot uses a multi-layer configuration system:
- URL format (includes protocol)
- Raises `ConfigValidationError` on failure
### Persistent Storage
## Persistent Storage
#### Embed Locations (`embed/embed_locations.json`)
### Embed Locations (`embed/embed_locations.json`)
```json
{
"server_abc123": {
@@ -249,7 +249,7 @@ The bot uses a multi-layer configuration system:
- **Save**: After each embed create/delete
- **Cleanup**: Automatic on missing messages
#### Server State Tracking (in-memory)
### Server State Tracking (in-memory)
```python
{
"server_abc123": (
@@ -265,7 +265,7 @@ The bot uses a multi-layer configuration system:
- Reduces unnecessary Discord API calls
- Tracks force update intervals
### Async Architecture
## Async Architecture
The bot is built on asyncio for concurrent operations:
@@ -290,7 +290,7 @@ async with asyncio.gather(*[
- `asyncio.Lock()` for embed update cycles
- No blocking operations in event loop
### Error Handling Strategy
## Error Handling Strategy
**Levels:**
1. **Graceful Degradation**: Continue operating with reduced functionality
@@ -309,9 +309,9 @@ except Exception as e:
return {'attributes': {'current_state': 'offline'}}
```
### Performance Optimizations
## Performance Optimizations
#### 1. Smart Update Logic
### 1. Smart Update Logic
Only updates embeds when necessary:
- Power state changes (always)
- Significant CPU changes (>50% delta)
@@ -320,13 +320,13 @@ Only updates embeds when necessary:
**Impact**: ~90% reduction in Discord API calls
#### 2. FIFO Metric Queues
### 2. FIFO Metric Queues
`collections.deque(maxlen=6)` automatically rotates old data:
- O(1) append operations
- Automatic memory management
- No manual cleanup needed
#### 3. Request Locking
### 3. Request Locking
Prevents concurrent API access:
```python
async with self.lock:
@@ -339,7 +339,7 @@ async with self.lock:
- Prevents race conditions
- Ensures ordered operations
#### 4. Caching Strategy
### 4. Caching Strategy
- Server list cached between updates
- State tracking prevents redundant checks
- Embed locations loaded once at startup