Skip to content

Conversation

@JanZachmann
Copy link
Contributor

@JanZachmann JanZachmann commented Nov 14, 2025

Summary

  • Created Cargo workspace structure with backend in src/backend/
  • Moved Vue 3 frontend from vue/ to src/ui/
  • Updated build artifacts location from src/backend/static/ to dist/
  • Removed redundant root biome.json (frontend has its own)
  • Updated all Docker paths and build scripts for new structure

Purpose

This prepares the codebase for future Crux framework integration by establishing a clean workspace structure with properly separated concerns.

- Copy latest upstream/main src/ contents to src/backend/src/
- Rename vue/ to src/ui/ (previously src/frontend/)
- Update Dockerfile to reference src/ui paths
- Update build scripts for new structure
- Maintain workspace structure for future Crux integration

Signed-off-by: Jan Zachmann <[email protected]>
@JanZachmann JanZachmann force-pushed the refactor-repo-structure branch from 88dfcb4 to 9332652 Compare November 20, 2025 15:52
@JanZachmann JanZachmann marked this pull request as ready for review November 25, 2025 07:21
@JanZachmann JanZachmann changed the title [WIP] Restructure repository into workspace with separated backend and frontend [Restructure repository into workspace with separated backend and frontend Nov 25, 2025
@JanZachmann JanZachmann changed the title [Restructure repository into workspace with separated backend and frontend Restructure repository into workspace with separated backend and frontend Nov 25, 2025
Copy link
Member

@ronny-standtke ronny-standtke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary does not match actual changes, but changes lgtm.

Copy link
Contributor

@empwilli empwilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JanZachmann JanZachmann merged commit 533c985 into omnect:main Nov 25, 2025
1 of 6 checks passed
JanZachmann added a commit that referenced this pull request Nov 28, 2025
## Summary

This PR introduces the Crux Core/Shell architecture infrastructure to
omnect-ui, providing the foundation for separating business logic (Core)
from platform-specific UI code (Shell). The refactor builds on top of
the workspace restructuring from #68.

**Learn more about Crux:**
- [Crux Documentation](https://redbadger.github.io/crux/)
- [Crux GitHub Repository](https://github.com/redbadger/crux)
- [Crux Architecture Guide](https://redbadger.github.io/crux/guide.html)

### Key Changes

**Crux Core Architecture (`src/app/`)**
- New Cargo package `omnect-ui-core` with platform-agnostic business
logic framework
- Domain-based module organization: `auth`, `device`, `websocket`, `ui`
- Custom Centrifugo capability with Command API for WebSocket management
- HTTP capability migrated to Command API pattern
- WASM compilation target for web integration
- See
[src/app/README.md](../tree/refactor-frontend-to-use-crux/src/app/README.md)
for architecture details

**TypeScript Integration (`src/shared_types/`)**
- TypeGen-based type generation from Rust to TypeScript
- Automatic bincode serialization/deserialization bindings
- Type-safe communication between Core and Shell

**Frontend Shell (`src/ui/`)**
- Vue 3 composable (`useCore.ts`) bridging WASM Core and UI
- Effect handlers for HTTP requests and Centrifugo WebSocket
- Migrated `DeviceInfo` component to use Core (`DeviceInfoCore.vue`)
- Frontend assets embedded in backend binary via `static-files` crate

**Backend Updates (`src/backend/`)**
- Frontend assets embedded in binary (no separate static file serving)
- Improved build script with WASM compilation stage
- New `setup-password` utility binary for development
- CLI tool for creating/updating password files during local development
  - Integrated with VS Code launch tasks for automated setup
- Usage: `cargo run --bin setup-password --features=mock -- <password>`

**Build & Deployment**
- Consolidated build scripts with multi-architecture support
- Docker workflow improvements with WASM build stage
- Enhanced deployment script with registry push capabilities

## Architecture Notes

The Crux pattern separates concerns into three layers:

1. **Core** (Rust, compiled to WASM): All business logic, state
management, type definitions
2. **Shell** (Vue 3 TypeScript): UI rendering and effect execution
(HTTP, WebSocket)
3. **Communication**: Events (Shell → Core), Effects (Core → Shell),
ViewModel (Core → Shell)

**Benefits:**
- Platform-agnostic business logic testable without UI
- Type-safe frontend with auto-generated TypeScript bindings
- Clear separation of concerns between logic and presentation
- Potential for future multi-platform support (native apps, CLI, etc.)

**Event Flow:**
1. User action in Vue component
2. Component calls `sendEvent()` or convenience method (e.g., `login()`)
3. Event is serialized (bincode) and sent to WASM Core
4. Core processes event, updates Model, returns Effects
5. Shell processes Effects (HTTP request, render update, WebSocket
subscription)
6. ViewModel is updated and Vue reactively re-renders

## Current Status

### What This PR Delivers

✅ **Complete Crux Core Infrastructure:**
- Working WASM compilation pipeline with wasm-pack
- TypeScript type generation from Rust types
- HTTP and Centrifugo capabilities with Command API
- Domain-based module organization (auth, device, websocket, ui)
- Effect processing in Vue shell (HTTP, WebSocket, render)

✅ **Component Migration:**
- `DeviceInfo` successfully migrated to Core architecture
- Demonstrates full Core/Shell pattern with real functionality
- `useCore()` composable for easy Core integration

✅ **Build Pipeline:**
- Docker multi-stage build with WASM compilation
- Frontend assets embedded in backend binary
- Multi-architecture support (amd64, arm64)

✅ **Developer Experience:**
- `setup-password` CLI utility for local development
- VS Code tasks for automated pre-launch setup
- Improved build scripts and documentation

### Future Work (Separate PRs)

⚠️ **5 Vue components still use direct API calls** and need migration to
use the Core. See detailed migration plan in
[src/app/README.md](../tree/refactor-frontend-to-use-crux/src/app/README.md#vue-component-migration-future-prs).

**Components to Migrate (5 remaining):**
1. `DeviceActions.vue` - Reboot and factory reset actions
2. `DeviceNetworks.vue` - Network list and status
3. `NetworkSettings.vue` - Network configuration
4. `UpdateFileUpload.vue` - Firmware update upload
5. `UserMenu.vue` - User authentication actions

**Additional Tasks:**
- Remove `useCentrifuge` composable once all components migrated
- Comprehensive integration testing
- Performance optimization and bundle size analysis

This PR establishes the architectural foundation and demonstrates
successful component migration. Remaining component migrations will
proceed incrementally in follow-up PRs for easier review and testing.

---------

Signed-off-by: Jan Zachmann <[email protected]>
@JanZachmann JanZachmann deleted the refactor-repo-structure branch December 18, 2025 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants