Skip to main content

Architecture Documentation Index

This directory contains comprehensive architectural documentation for the Uptime-Watcher application, including Architecture Decision Records (ADRs), development patterns, code templates, and documentation standards.

๐Ÿ“ Directory Structureโ€‹

docs/Architecture/
โ”œโ”€โ”€ README.md # This file
โ”œโ”€โ”€ ADRs/ # Architecture Decision Records
โ”‚ โ”œโ”€โ”€ ADR-001-Repository-Pattern.md
โ”‚ โ”œโ”€โ”€ ADR-002-Event-Driven-Architecture.md
โ”‚ โ”œโ”€โ”€ ADR-003-Error-Handling-Strategy.md
โ”‚ โ”œโ”€โ”€ ADR-004-Frontend-State-Management.md
โ”‚ โ””โ”€โ”€ ADR-005-IPC-Communication-Protocol.md
โ”œโ”€โ”€ Patterns/ # Development patterns guide
โ”‚ โ””โ”€โ”€ Development-Patterns-Guide.md
โ”œโ”€โ”€ Templates/ # Code templates for common patterns
โ”‚ โ”œโ”€โ”€ Repository-Template.md
โ”‚ โ”œโ”€โ”€ Zustand-Store-Template.md
โ”‚ โ””โ”€โ”€ IPC-Handler-Template.md
โ””โ”€โ”€ TSDoc-Standards.md # Documentation standards

๐Ÿ—๏ธ Architecture Decision Records (ADRs)โ€‹

ADRs document the key architectural decisions made during development, their context, consequences, and implementation guidelines.

ADR-001: Repository Patternโ€‹

Status: Accepted - Establishes the repository pattern for all database access

  • Dual method pattern (public async + internal sync)
  • Transaction safety with executeTransaction()
  • Consistent error handling and event emission
  • All repositories follow this pattern: SiteRepository, MonitorRepository, HistoryRepository, SettingsRepository

ADR-002: Event-Driven Architectureโ€‹

Status: Accepted - Core communication mechanism using TypedEventBus

  • Type-safe event system with compile-time checking
  • Automatic metadata injection (correlation IDs, timestamps)
  • Domain-based event naming (domain:action)
  • IPC event forwarding for frontend integration

ADR-003: Error Handling Strategyโ€‹

Status: Accepted - Multi-layered error handling across all application layers

  • Shared withErrorHandling() utility with frontend/backend overloads
  • withDatabaseOperation() for retry logic and database operations
  • Error preservation principles maintaining stack traces
  • Safe store operations preventing cascading failures

ADR-004: Frontend State Managementโ€‹

Status: Accepted - Zustand-based state management with modular composition

  • Type-safe store interfaces with comprehensive TypeScript
  • Modular composition for complex stores
  • Selective persistence for user preferences
  • Integration with error handling and IPC systems

ADR-005: IPC Communication Protocolโ€‹

Status: Accepted - Standardized Electron IPC communication

  • Centralized IPC service with domain-specific handlers
  • Type-safe preload API with contextBridge isolation
  • Consistent validation and error handling
  • Event forwarding protocol for real-time updates

๐Ÿ“‹ Development Patternsโ€‹

Development Patterns Guideโ€‹

Comprehensive guide to all established patterns in the codebase:

  • Repository Pattern - Database access with transaction safety
  • Event-Driven Communication - TypedEventBus usage and event naming
  • Error Handling Patterns - Multi-layered error handling strategies
  • Frontend State Management - Zustand stores and modular composition
  • IPC Communication - Electron IPC patterns and type safety
  • Testing Patterns - Consistent testing approaches across layers

๐Ÿ› ๏ธ Code Templatesโ€‹

Ready-to-use templates for implementing common patterns:

Repository Templateโ€‹

Complete template for creating new repository classes:

  • Full TypeScript implementation with dual methods
  • Query constants and dependency injection
  • Comprehensive TSDoc documentation
  • Test template and integration checklist

Zustand Store Templateโ€‹

Templates for both simple and complex Zustand stores:

  • Simple store pattern for straightforward state
  • Complex store with modular composition
  • Module templates for focused functionality
  • Testing patterns and error integration

IPC Handler Templateโ€‹

Complete IPC communication implementation:

  • Handler registration with validation
  • Preload API extensions
  • Type definitions and error handling
  • Test templates and naming conventions

๐Ÿ“š Documentation Standardsโ€‹

TSDoc Standardsโ€‹

Standardized documentation patterns for inline code examples:

  • Repository pattern documentation examples
  • Event system documentation standards
  • Frontend store documentation patterns
  • Error handling documentation
  • IPC communication documentation
  • Code example categories and validation checklist

๐ŸŽฏ Using This Documentationโ€‹

For New Developersโ€‹

  1. Start with ADRs - Understand the architectural decisions and their context
  2. Read the Patterns Guide - Learn the established patterns and conventions
  3. Use Templates - Implement new features using the provided templates
  4. Follow TSDoc Standards - Document your code using the established patterns

For Existing Developersโ€‹

  1. Reference ADRs - When making architectural changes, consult existing decisions
  2. Update Patterns - If you discover new patterns, document them in the guide
  3. Improve Templates - Update templates based on learnings and improvements
  4. Maintain Standards - Follow and improve the documentation standards

For Code Reviewsโ€‹

  1. Check Pattern Compliance - Ensure new code follows established patterns
  2. Verify Documentation - Check that TSDoc follows the standards
  3. Validate Architecture - Ensure changes align with ADR decisions
  4. Template Usage - Verify that new repositories/stores/handlers use templates

๐Ÿ”„ Maintenance Guidelinesโ€‹

When to Update ADRsโ€‹

  • Status Changes - Mark ADRs as superseded when patterns evolve
  • New Decisions - Create new ADRs for significant architectural changes
  • Context Updates - Update context and consequences as understanding improves

Pattern Evolutionโ€‹

  • Document New Patterns - Add emerging patterns to the guide
  • Update Templates - Evolve templates based on best practices
  • Maintain Consistency - Ensure all patterns work together harmoniously

Documentation Qualityโ€‹

  • Regular Reviews - Periodically review and update documentation
  • Example Accuracy - Ensure code examples remain current and accurate
  • Cross-References - Maintain links between related documents

๐Ÿ“Š Compliance Trackingโ€‹

Repository Patternโ€‹

  • โœ… All database access uses repository pattern
  • โœ… All repositories implement dual-method pattern
  • โœ… All mutations use executeTransaction()
  • โœ… All operations use withDatabaseOperation()

Event Systemโ€‹

  • โœ… All communication uses TypedEventBus
  • โœ… All events follow naming conventions
  • โœ… All events include proper metadata
  • โœ… IPC events are automatically forwarded

Error Handlingโ€‹

  • โœ… All layers use appropriate error handling utilities
  • โœ… All errors preserve original context
  • โœ… All operations emit appropriate events
  • โœ… Frontend stores use safe operations

Frontend Stateโ€‹

  • โœ… All stores use TypeScript interfaces
  • โœ… Complex stores use modular composition
  • โœ… Persistence is selective and purposeful
  • โœ… Actions include consistent logging

IPC Communicationโ€‹

  • โœ… All handlers use standardized registration
  • โœ… All parameters are validated
  • โœ… All channels follow naming conventions
  • โœ… Preload API is type-safe

๐Ÿš€ Quick Startโ€‹

To implement a new feature:

  1. Identify the pattern - Determine which architectural pattern applies
  2. Use the template - Start with the appropriate template
  3. Follow the standards - Use TSDoc standards for documentation
  4. Test thoroughly - Use testing patterns from the guide
  5. Review compliance - Ensure the implementation follows all relevant ADRs

๐Ÿ“ž Supportโ€‹

For questions about architectural patterns or documentation:

  1. Check the ADRs - Look for existing decisions
  2. Review the patterns guide - Find established conventions
  3. Use the templates - Adapt templates to your needs
  4. Follow the standards - Use TSDoc standards for consistency

This documentation represents the living architectural knowledge of the Uptime-Watcher project. It should be updated as the architecture evolves and new patterns emerge.