Architecture Document - Minimalistic Monitoring Tool¶
Overview¶
This document outlines the architecture for a minimalistic monitoring tool implemented as a Python library. The tool follows a clean architecture approach with an event-driven core and separation between the library, agents, and frontend components.
System Components¶
Core Library¶
The core library contains the business logic for monitoring and is published as a PyPI package using uv for package management.
Components¶
Domain Model
Check: Represents a monitoring check with parametersResult: Represents the outcome of an executed checkService: Represents a monitored service
Message Bus
Central event dispatcher
Handles commands and events
Implements publish-subscribe pattern
Commands
ExecuteChecks: Triggers execution of pending checksRegisterCheck: Registers a new checkDeleteCheck: Removes a check
Events
CheckSucceeded: Emitted when a check succeedsCheckFailed: Emitted when a check failsServiceStatusChanged: Emitted when service status changes
Command Handlers
Execute domain logic
Validate input
Emit events
Check Executors
HttpCheckExecutor: Performs HTTP requests and reports status (current implementation)DnsCheckExecutor: Resolves DNS records and validates expected IPsPlanned: Additional executors (JSON validation, ping, metrics) will extend the same interface in future iterations
Repository Interfaces
CheckRepository: Interface for storing and retrieving checksResultRepository: Interface for storing and retrieving check results
Agent¶
The agent executes checks and has no direct knowledge of the database implementation.
Components¶
Check Scheduler
Retrieves checks from repository
Schedules check execution
Check Runner
Executes checks using appropriate check executors
Publishes check results
See
docs/async-check-runner.mdfor a detailed walkthrough of the asynchronous runner implementationSee
docs/concurrency-overview.mdfor a high-level description of the runtime threading & event-loop model
Repository Implementations
Concrete implementation of repository interfaces for SQLite
Frontend (Django)¶
The frontend is implemented as a Django application and provides a user interface for monitoring and configuration.
Components¶
Django Models
Maps to database tables
Implements persistence for checks and results
Views
Dashboard: Overview of service status
Check Management: Create, update, delete checks
Results: View check execution history
Data Flow¶
Check Creation
User creates check via Django frontend
Check is persisted in database via Django ORM
RegisterCheckcommand is published
Check Execution
Agent fetches checks from repository
Agent issues
ExecuteCheckfor each checkCommand handler executes check via appropriate executor
CheckExecutedevent is emitted with resultResult is stored in repository
If service status changes,
ServiceStatusChangedevent is emitted
Monitoring
Frontend queries database for current status
Dashboard displays service health
Message Bus Concept¶
The message bus will:
Register handlers for commands and events
Route commands to appropriate handlers
Distribute events to all subscribers
Support synchronous and asynchronous execution models
Agent Concept¶
The agent will:
Connect to the repository to fetch checks
Use the core library to execute checks
Store results back to the repository
Handle scheduling and retries
Django Frontend Concept¶
The Django frontend will:
Provide database models for checks and results
Use Django ORM for database access
Render dashboard views of monitoring status
Support CRUD operations for check configurations