Commit Graph

25 Commits

Author SHA1 Message Date
e81a128e7f feat(domain): implement RelayState enum with serialization support
Add RelayState enum to domain layer with:
- Display, Debug, Clone, Copy, PartialEq, Eq derives
- serde Serialize/Deserialize traits for API JSON handling
- Type-safe representation of relay on/off states

TDD green phase: Tests from T019 now pass.

Ref: T020 (specs/001-modbus-relay-control/tasks.md)
2026-01-22 00:57:11 +01:00
d6cbf0f4ae test(domain/relay): write failing tests for RelayState serialization
Tests verify serialization and deserialization of RelayState enum with
"on" and "off" states. Red phase of TDD - tests define expected behavior
before implementation.

Ref: T019 (specs/001-modbus-relay-control/tasks.md)
2026-01-22 00:57:11 +01:00
0ec7fdf11b feat(domain): implement RelayId newtype with validation
Implement smart constructor that validates relay IDs are within valid 
range (1-8 for 8-channel relay controller). Add accessor method as_u8() 
for safe access to inner value. Add comprehensive documentation to satisfy 
clippy requirements.

TDD green phase: Tests from T017 now pass.

Ref: T018 (specs/001-modbus-relay-control/tasks.md)
2026-01-22 00:57:11 +01:00
86b194ad74 test(domain): write failing tests for RelayId newtype validation
Tests cover validation requirements for the RelayId newtype:
- Valid relay IDs (1-8 for 8-channel controller)
- Invalid IDs outside valid range
- Smart constructor error handling
- Type-safe ID representation

TDD red phase: Tests fail until RelayId is implemented.

Ref: T017 (specs/001-modbus-relay-control/tasks.md)
2026-01-22 00:57:11 +01:00
c427007907 docs: document Phase 0.5 CORS configuration and production security
Add comprehensive CORS configuration section to CLAUDE.md including:
- Implementation patterns with From<CorsSettings> trait
- Development and production configuration examples
- Security constraints and fail-safe defaults
- Test coverage documentation (15 tests)
- Updated project structure showing CORS-related files
- Updated technology stack and active specification list

Updated tasks.md to reflect Phase 0.5 completion (T009-T016).

Phase: 0.5 - CORS Configuration & Production Security (Complete)
2026-01-22 00:57:11 +01:00
4929266a8e style: format backend 2026-01-22 00:57:11 +01:00
e16e214b74 test(cors): write integration tests for CORS headers
Added 9 comprehensive integration tests covering:
- Preflight OPTIONS requests
- Actual requests with CORS headers
- Max-age header validation
- Credentials configuration
- Allowed methods configuration
- Wildcard origins
- Multiple origins
- Unauthorized origin rejection

All tests pass successfully.

Ref: T016
2026-01-22 00:57:11 +01:00
b620c3d638 feat(middleware): configure CORS from settings in middleware chain
Replace Cors::new() with Cors::from(value.settings.cors.clone()) in the
From<Application> for RunnableApplication implementation to use CORS
settings from configuration instead of hardcoded defaults.

Changes:
- Use From<CorsSettings> for Cors trait to build CORS middleware
- Add unit test verifying CORS middleware uses settings
- Maintain correct middleware order: RateLimit → CORS → Data

Ref: T015
2026-01-22 00:57:11 +01:00
5d6c3208cc feat(cors): implement CORS configuration with From trait
Implement From<CorsSettings> for Cors trait to configure CORS middleware
with production-ready security validation.

- Move CorsSettings to backend/src/settings/cors.rs module
- Validate wildcard + credentials constraint (browser security policy)
- Configure allowed methods, headers, credentials, and max_age
- Add structured logging for CORS configuration
- Move tests from settings/mod.rs and startup.rs to cors module

Ref: T014
2026-01-22 00:57:11 +01:00
e577fb5095 test(cors): write tests for build_cors() function (TDD red)
Add failing test cases for the CORS configuration builder function.
Tests verify correct initialization of CorsSettings with allowed origins,
credentials, and max age configuration. These tests fail until build_cors()
is implemented in the green phase.

Ref: T013 (specs/001-modbus-relay-control)
2026-01-22 00:57:11 +01:00
5f0aaacb74 chore(config): configure CORS and update frontend URL in development settings
Set up CORS policy to allow requests from frontend development server and
update development.yaml with proper frontend origin URL configuration.

Ref: T011 (specs/001-modbus-relay-control)
2026-01-22 00:57:11 +01:00
9a55aa433c feat(settings): add CorsSettings struct for CORS configuration
Implements CorsSettings struct with validation and deserialization support
for configuring Cross-Origin Resource Sharing in the application settings.

Ref: T010 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
b1fd30af67 test(settings): write tests for CorsSettings struct deserialization
Add 5 comprehensive tests for CorsSettings in TDD red phase:
- cors_settings_deserialize_from_yaml: YAML deserialization
- cors_settings_default_has_empty_origins: Default values
- cors_settings_with_wildcard_deserializes: Wildcard origin handling
- settings_loads_cors_section_from_yaml: Settings integration
- cors_settings_deserialize_with_defaults: Partial deserialization

Tests are intentionally failing (red phase) as CorsSettings struct
will be implemented in T010. Follows TDD requirement to write tests
before implementation.

Ref: T009 (specs/001-modbus-relay-control/tasks.md)
2026-01-22 00:57:10 +01:00
2365bbc9b3 docs(cors): add CORS configuration planning and tasks
Add comprehensive CORS planning documentation and task breakdown for
Phase 0.5 (8 tasks: T009-T016).

- Create research-cors.md with security analysis and decisions
- Add FR-022a to spec.md for production CORS requirements
- Update tasks.md: 94 → 102 tasks across 9 phases
- Document CORS in README and plan.md

Configuration approach: hybrid (configurable origins/credentials,
hardcoded methods/headers) with restrictive fail-safe defaults.
2026-01-22 00:57:10 +01:00
8e4433ceaa feat(api): generate TypeScript API client from OpenAPI specification
Create type-safe TypeScript API client automatically generated from the
OpenAPI specification. Includes generated schema types and documented client
wrapper for type-safe backend communication.

Ref: T008 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
837a49fc58 refactor: reorganize project into monorepo with frontend scaffolding
Convert project from single backend to monorepo structure with separate
frontend (Vue 3 + TypeScript + Vite) and backend directories. Updates
all configuration files and build system to support both workspaces.

Ref: T007 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
6903d76682 feat(persistence): initialize SQLite database module
- Add domain types: RelayId newtype and RepositoryError enum
- Implement SqliteRelayLabelRepository with in-memory test support
- Create relay_labels migration with SQLx compile-time verification
- Add comprehensive integration test suite (266 lines)

Ref: T006 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
d8a7ed5d29 feat(persistence): add SQLite schema for relay labels table
Create infrastructure/persistence/schema.sql with relay_labels table
definition. Table enforces relay_id range (1-8) and label length (max 50).

Ref: T005 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
2ee5405c05 docs: add README and AGPL-3.0 license
Add project README with development status and roadmap.
Add AGPL-3.0 license file.
2026-01-22 00:57:10 +01:00
10f31ea90d feat(settings): add modbus and relay configuration structs
Add ModbusSettings with host, port, slave_id, and timeout_secs fields.
Add RelaySettings with label_max_length field.
Integrate both into Settings struct and load from settings/base.yaml
with test Modbus TCP configuration.

Ref: T003 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
9bae638bd2 refactor(modbus): switch to native Modbus TCP protocol
Switch from Modbus RTU over TCP to native Modbus TCP based on hardware
testing. Uses standard MBAP header (no CRC16), port 502, and TCP-only
tokio-modbus feature for simpler implementation.

Updated: Cargo.toml, plan.md, research.md, tasks.md
2026-01-22 00:57:10 +01:00
ff0c0c39c0 feat(src): create hexagonal architecture module structure
Establish foundational module hierarchy following hexagonal architecture
(clean architecture) patterns: domain, application, infrastructure, and
presentation layers. Each module includes comprehensive documentation
explaining its architectural role and responsibilities.

Ref: T002 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
63875d4909 feat(deps): add modbus, database, mocking, and async trait dependencies
Adds tokio-modbus 0.17.0 for Modbus RTU over TCP communication,
sqlx with runtime-tokio and sqlite features for async database operations,
mockall 0.13 for trait mocking in tests, and async-trait 0.1 for async trait support.

Ref: T001 (specs/001-modbus-relay-control)
2026-01-22 00:57:10 +01:00
a683810bdc docs: add project specs and documentation for Modbus relay control
Initialize project documentation structure:
- Add CLAUDE.md with development guidelines and architecture principles
- Add project constitution (v1.1.0) with hexagonal architecture and SOLID principles
- Add MCP server configuration for Context7 integration

Feature specification (001-modbus-relay-control):
- Complete feature spec for web-based Modbus relay control system
- Implementation plan with TDD approach using SQLx for persistence
- Type-driven development design for domain types
- Technical decisions document (SQLx over rusqlite, SQLite persistence)
- Detailed task breakdown (94 tasks across 8 phases)
- Specification templates for future features

Documentation:
- Modbus POE ETH Relay hardware documentation
- Modbus Application Protocol specification (PDF)

Project uses SQLx for compile-time verified SQL queries, aligned with
type-driven development principles.
2026-01-22 00:57:10 +01:00
d5a2859b64 feat: rust project initialization 2026-01-11 00:39:18 +01:00