Files
labFusion/frontend
GSRN 4b2ef7e246
Some checks failed
API Gateway (Java Spring Boot) / test (21) (push) Successful in 2m2s
API Gateway (Java Spring Boot) / test (17) (push) Successful in 2m2s
Frontend (React) / test (20) (push) Successful in 2m11s
Integration Tests / integration-tests (push) Failing after 25s
Integration Tests / performance-tests (push) Has been skipped
API Docs (Node.js Express) / test (20) (push) Successful in 2m36s
API Gateway (Java Spring Boot) / build (push) Failing after 40s
Service Adapters (Python FastAPI) / test (3.11) (push) Successful in 1m24s
Service Adapters (Python FastAPI) / test (3.12) (push) Successful in 1m27s
Service Adapters (Python FastAPI) / test (3.13) (push) Successful in 1m27s
Frontend (React) / build (push) Failing after 58s
Service Adapters (Python FastAPI) / build (push) Failing after 21s
Frontend (React) / lighthouse (push) Has been skipped
API Docs (Node.js Express) / build (push) Failing after 1m24s
chore: Remove legacy Docker configuration and documentation
### Summary of Changes
- Deleted `docker-compose.dev.yml` and `docker-compose.yml` files to streamline the project structure.
- Removed outdated Dockerfiles for services (API Gateway, Service Adapters, API Docs, and Frontend) to eliminate redundancy.
- Updated `env.example` to reflect changes in service configurations, including local host settings for PostgreSQL and Redis.
- Revised `README.md` to remove references to Docker deployment and clarify local development setup instructions.
- Cleaned up documentation structure by removing obsolete files related to Docker rate limits and compatibility fixes.

### Expected Results
- Simplified project setup and improved clarity for developers by focusing on current configurations and removing legacy artifacts.
2025-09-18 00:50:03 +02:00
..
2025-09-11 22:08:12 +02:00

LabFusion Frontend

A modern React frontend for the LabFusion homelab dashboard, built with clean code principles and offline resilience.

Features

  • Clean Code Architecture: Modular components following React best practices
  • Offline Mode: Works gracefully when backend services are unavailable
  • Real-time Monitoring: Service status and system metrics
  • Error Resilience: Comprehensive error handling and recovery
  • Responsive Design: Mobile-friendly interface with Ant Design
  • Type Safety: PropTypes validation for better development experience

Architecture

Component Structure

src/
├── components/
│   ├── common/           # Reusable UI components
│   │   ├── ErrorBoundary.js    # Error boundary component
│   │   ├── LoadingSpinner.js   # Loading state component
│   │   └── StatusIcon.js       # Status icon component
│   ├── dashboard/        # Dashboard-specific components
│   │   ├── SystemStatsCards.js # System statistics cards
│   │   ├── ServiceStatusList.js # Service status list
│   │   └── RecentEventsList.js # Recent events list
│   └── [main components] # Main application components
├── hooks/               # Custom React hooks
│   └── useServiceStatus.js # Service status and data hooks
├── services/            # API and external services
│   └── api.js           # Centralized API client
├── utils/               # Utility functions
│   └── errorHandling.js # Error handling utilities
├── constants/           # Configuration constants
│   └── index.js         # UI constants, colors, messages
└── [app files]          # Main application files

Clean Code Principles

1. Single Responsibility Principle (SRP)

  • Each component has one clear purpose
  • SystemStatsCards only handles system statistics display
  • ServiceStatusList only manages service status display
  • StatusIcon only renders status icons

2. Don't Repeat Yourself (DRY)

  • Centralized status icon logic in StatusIcon component
  • Reusable loading component in LoadingSpinner
  • Centralized error handling in utils/errorHandling.js
  • All constants extracted to constants/index.js

3. Component Composition

  • Large components broken into smaller, focused components
  • Clear prop interfaces with PropTypes validation
  • Easy to test and maintain

4. Error Handling

  • Error boundaries for graceful error recovery
  • User-friendly error messages
  • Development-friendly error details

Offline Mode & Resilience

Service Status Monitoring

  • Real-time health checks every 30 seconds
  • Automatic retry when services come back online
  • Clear status indicators (online, partial, offline)

Graceful Degradation

  • Fallback data when services are unavailable
  • Loading states during data fetching
  • Clear error messages instead of crashes

Error Recovery

  • 5-second timeout for all API calls
  • Connection error detection
  • Automatic retry mechanisms

Development

Prerequisites

  • Node.js 16+
  • npm or yarn

Installation

cd frontend
npm install

Development Server

npm start

The app will open at http://localhost:3000

Building for Production

npm run build

Testing

npm test

Configuration

Environment Variables

REACT_APP_API_URL=http://localhost:8080
REACT_APP_ADAPTERS_URL=http://localhost:8000
REACT_APP_DOCS_URL=http://localhost:8083

Service URLs

Component Documentation

Common Components

ErrorBoundary

Catches JavaScript errors anywhere in the component tree and displays a fallback UI.

LoadingSpinner

Reusable loading component with customizable message and size.

StatusIcon

Consistent status icon rendering with color coding.

Dashboard Components

SystemStatsCards

Displays system metrics (CPU, Memory, Disk, Network) with progress bars.

ServiceStatusList

Shows service status with uptime information and status indicators.

RecentEventsList

Displays recent events with timestamps and service information.

Hooks

useServiceStatus

Monitors service health and provides status information.

useSystemData

Fetches and manages system data with fallback handling.

API Integration

Centralized API Client

All API calls are centralized in services/api.js with:

  • Consistent error handling
  • Timeout configuration
  • Fallback data support

Service Endpoints

  • API Gateway: Health, dashboards, system data
  • Service Adapters: Home Assistant, Frigate, Immich, events
  • API Docs: Service health and documentation

Error Handling

Error Types

  • Connection Timeout: Request timeout handling
  • Service Error: HTTP error responses
  • Service Unavailable: Network connectivity issues
  • Unknown Error: Unexpected errors

Error Recovery

  • Automatic retry mechanisms
  • Fallback data display
  • User-friendly error messages
  • Development error details

Performance

Optimizations

  • Smaller components for better React optimization
  • Reduced re-renders through focused components
  • Memoization opportunities for pure components

Code Splitting Ready

  • Modular structure supports code splitting
  • Easy to lazy load dashboard components
  • Clear separation enables tree shaking

Testing

Testable Components

  • Pure functions in utils
  • Isolated component logic
  • Clear prop interfaces
  • Mockable dependencies

Test Structure

describe('SystemStatsCards', () => {
  it('renders CPU usage correctly', () => {
    // Test focused component
  });
});

Documentation

Contributing

  1. Follow clean code principles
  2. Add PropTypes to new components
  3. Write tests for new functionality
  4. Update documentation as needed
  5. Follow the established component structure

License

This project is licensed under the MIT License - see the LICENSE file for details.