You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You are an expert Rust backend engineer, BAS/HVAC controls engineer, and security-minded platform engineer.
Your mission is to build a production-quality all-Rust project for a read-only BAS / Haystack / Open-FDD data lake control plane.
Do not stop at a sketch. Do not leave placeholder TODOs for core behavior. Iterate until the repository builds, tests pass, Docker runs, and the acceptance checkpoints below are complete.
Project name
bas-haystack-lake-rs
High-level purpose
Build a Rust service stack that can safely collect read-only telemetry from Niagara / JACE / nHaystack / Project Haystack endpoints over a private VPN/Tailscale network, store normalized point/current/history data in Postgres, expose a secure admin API for enabling/disabling sites, expose a sanitized read-only current-values API for Open-FDD, and provide operational health checks and stale-data alerts.
This is not a BAS write tool. It must never write to the control system. The only writes are to our own Postgres database.
Non-negotiable safety rule
Every BAS/Haystack station interaction must be read-only.
Allowed station operations:
about
ops
read
nav
hisRead
other explicitly read-only Haystack operations
Forbidden station operations:
writes
setpoint changes
command operations
priority-array writes
BACnet writes
anything that changes the live BAS
Enforce this in code with a read-only Haystack client wrapper that rejects any non-allowlisted operation before the request is sent.
Desired architecture
Niagara / JACE / nHaystack station
|
| private Tailscale / VPN only
v
Rust collector service
|
v
Postgres BAS lake
|
+--> sanitized read-only API for Open-FDD / external tools
|
+--> admin API for site enable/disable, status, onboarding
|
+--> alerts for stale site connections and failed polls
Required crates unless there is a strong reason to replace:
tokio
axum
tower
tower-http
serde
serde_json
serde_yaml
sqlx
reqwest
tracing
tracing-subscriber
thiserror
anyhow only at app boundaries, not in core domain crates
clap
uuid
time
argon2
jsonwebtoken
secrecy
dotenvy
url
prometheus or metrics-compatible equivalent
Use rusty-haystack from:
https://github.com/jscott3201/rusty-haystack
Try to integrate its Haystack client/core types directly. If its API does not cleanly support the required Niagara interaction yet, isolate that gap behind our own HaystackReadClient trait and implement a reqwest fallback adapter. Do not smear raw HTTP calls throughout the app.
Do not store raw secrets casually. Use environment references or encrypted/hashed/tokenized patterns. At minimum, keep secret material separate from normal site config and document how to use a real secret manager later.
points
site id
haystack id
sanitized id
display name
nav/slot path
unit
kind
has_his
tags as jsonb
first_seen_at
last_seen_at
current_values
site id
point id
numeric value nullable
string value nullable
bool value nullable
raw value jsonb
status
ts
quality/status fields
history_values
Native Haystack hisRead history for points that have native history.
polled_history
Change-of-value snapshots for all current values.
site_heartbeats
last_success_at
last_error_at
last_error_message
last_point_count
last_current_count
consecutive_failures
stale boolean
ingest_errors
Structured errors with site, phase, point id if applicable, message, timestamp.
audit_log
Every admin action must write who/what/when/before/after.
Collector behavior
Build a collector binary that supports:
cargo run -p collector -- doctor
cargo run -p collector -- poll-once --site <site_id>
cargo run -p collector -- run
Collector must:
Load enabled sites from Postgres.
For each enabled site, call read-only Haystack operations only.
Refresh point metadata.
Poll current values.
Upsert current values.
Append COV snapshots into polled_history.
Poll native Haystack history for has_his points using incremental watermarks.
Update site heartbeat.
Record ingest errors without killing the entire service.
Continue polling other sites if one site fails.
COV snapshot rules:
Write if numeric value changed beyond unit-specific deadband.
Write if boolean flips.
Write if string/status value changes.
Write heartbeat row if no value changed for configurable max interval.
Always preserve energy/power meter fidelity for units like kW, kWh, V, A, kVA, PF, Hz.
Admin API
Build an Axum admin API.
Required endpoints:
GET /health
GET /ready
POST /admin/login
GET /admin/sites
POST /admin/sites
GET /admin/sites/:site_id
PATCH /admin/sites/:site_id
POST /admin/sites/:site_id/pause
POST /admin/sites/:site_id/resume
POST /admin/sites/:site_id/poll-once
GET /admin/sites/:site_id/status
GET /admin/sites/:site_id/errors
GET /admin/audit
Admin API requirements:
JWT auth or strong API token auth.
Password/token hashes must use Argon2 or comparable secure hashing.
Every mutating admin action writes audit_log.
Pause/resume must only change polling/export state. It must not delete data.
API must be safe to expose only on Tailscale/private network by default.
Include rate limiting or basic abuse protection.
Include request IDs and structured logs.
Python/Excel management compatibility
Even though the server is all Rust, design the admin API so a simple local Python script can manage customers/sites from an Excel or CSV sheet.
Create docs and an example script spec, but do not make Python part of the server.
Rust BAS lake:
collect
normalize
store
replicate
alert
serve read-only data
Open-FDD:
model
point assignments
FDD equations
DataFusion SQL rules
plots
reports
operator workflows
Do not move Open-FDD logic into this project. This project feeds Open-FDD.
Replicator
Build a replicator crate/binary that supports safe read-only replica sync patterns.
Commands:
cargo run -p replicator -- sync-once
cargo run -p replicator -- run
Replicator behavior:
Source DB to replica DB.
Incremental watermark sync for append-only history tables.
Atomic truncate/reload for small mutable dimension tables.
Re-apply SELECT-only grants after sync.
Never sync admin secrets to public/collaborator replicas.
Include a dry-run mode.
Include docs.
Alerts
Build an alerts crate/binary.
Commands:
cargo run -p alerts -- check-once
cargo run -p alerts -- run
Alert conditions:
Site stale beyond stale_after_seconds.
Consecutive poll failures above threshold.
Point count drops unexpectedly.
Current-value count drops unexpectedly.
Haystack auth failures.
Postgres write failures.
Alert outputs:
Log warnings.
Webhook URL support.
Email support can be documented as future unless easy.
Include alert suppression/cooldown so it does not spam.
CLI
Use clap to make binaries discoverable and friendly.
Sanitized endpoint does not leak raw Haystack URL, IP, hostname, username, or customer name.
Alert checker flags stale site.
README explains how to run it.
No secrets are committed.
No core behavior is left as TODO.
No station write operation exists.
Final response includes exact commands run and their results.
Iteration rule
Work in loops:
Inspect current repo.
Implement the next smallest complete vertical slice.
Add or update tests.
Run format, clippy, tests, and build.
Fix failures.
Repeat until all acceptance checkpoints pass.
Do not stop after generating files. Do not say “you can add tests later.” Do not leave pseudo-code for core paths. If something must be deferred, mark it explicitly as non-core future enhancement and ensure all required core behavior still works.
Engineering style
Prefer boring, maintainable code.
Use:
clear domain structs
typed IDs
explicit errors
structured logs
config loaded from env
transaction boundaries for DB writes
idempotent upserts
safe defaults
testable traits around external systems
Avoid:
giant main.rs files
raw SQL scattered everywhere
unwraps in service code
storing raw secrets in logs
public network assumptions
fake green tests
shelling out when Rust can do it cleanly
UI work unless explicitly required
Final deliverable
When complete, provide:
Summary of what was built.
File tree.
Commands run.
Test/build results.
How to start locally.
How to add first real site.
How to pause/resume a client.
What remains future work, if anything.
Any security caveats.
Remember: this is a real Rust project, not a blog post. Build it until it works.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
You are an expert Rust backend engineer, BAS/HVAC controls engineer, and security-minded platform engineer.
Your mission is to build a production-quality all-Rust project for a read-only BAS / Haystack / Open-FDD data lake control plane.
Do not stop at a sketch. Do not leave placeholder TODOs for core behavior. Iterate until the repository builds, tests pass, Docker runs, and the acceptance checkpoints below are complete.
Project name
bas-haystack-lake-rsHigh-level purpose
Build a Rust service stack that can safely collect read-only telemetry from Niagara / JACE / nHaystack / Project Haystack endpoints over a private VPN/Tailscale network, store normalized point/current/history data in Postgres, expose a secure admin API for enabling/disabling sites, expose a sanitized read-only current-values API for Open-FDD, and provide operational health checks and stale-data alerts.
This is not a BAS write tool. It must never write to the control system. The only writes are to our own Postgres database.
Non-negotiable safety rule
Every BAS/Haystack station interaction must be read-only.
Allowed station operations:
aboutopsreadnavhisReadForbidden station operations:
Enforce this in code with a read-only Haystack client wrapper that rejects any non-allowlisted operation before the request is sent.
Desired architecture
Required Rust workspace layout
Create a clean Cargo workspace:
Rust expectations
Use modern, idiomatic Rust.
Required crates unless there is a strong reason to replace:
tokioaxumtowertower-httpserdeserde_jsonserde_yamlsqlxreqwesttracingtracing-subscriberthiserroranyhowonly at app boundaries, not in core domain cratesclapuuidtimeargon2jsonwebtokensecrecydotenvyurlprometheusor metrics-compatible equivalentUse
rusty-haystackfrom:https://github.com/jscott3201/rusty-haystackTry to integrate its Haystack client/core types directly. If its API does not cleanly support the required Niagara interaction yet, isolate that gap behind our own
HaystackReadClienttrait and implement areqwestfallback adapter. Do not smear raw HTTP calls throughout the app.Core data model
Create these Postgres tables with migrations:
Minimum table behavior:
clients
sites
site_auth_secrets
Do not store raw secrets casually. Use environment references or encrypted/hashed/tokenized patterns. At minimum, keep secret material separate from normal site config and document how to use a real secret manager later.
points
current_values
history_values
Native Haystack
hisReadhistory for points that have native history.polled_history
Change-of-value snapshots for all current values.
site_heartbeats
ingest_errors
Structured errors with site, phase, point id if applicable, message, timestamp.
audit_log
Every admin action must write who/what/when/before/after.
Collector behavior
Build a collector binary that supports:
Collector must:
polled_history.has_hispoints using incremental watermarks.COV snapshot rules:
kW,kWh,V,A,kVA,PF,Hz.Admin API
Build an Axum admin API.
Required endpoints:
Admin API requirements:
Python/Excel management compatibility
Even though the server is all Rust, design the admin API so a simple local Python script can manage customers/sites from an Excel or CSV sheet.
Create docs and an example script spec, but do not make Python part of the server.
The desired management flow:
The Rust side remains the source of truth. Excel/CSV is only an import/control surface.
Sanitized Open-FDD API
Build a separate read-only API for Open-FDD/current values.
Required endpoints:
Requirements:
json_apipull integration.{ "site_id": "demo_site", "ts": "2026-06-25T00:00:00Z", "values": { "ahu1.sat": 55.2, "ahu1.fan_status": true } }Open-FDD integration
Create
docs/OPENFDD_INTEGRATION.md.Explain how Open-FDD should consume:
Document clean separation:
Do not move Open-FDD logic into this project. This project feeds Open-FDD.
Replicator
Build a replicator crate/binary that supports safe read-only replica sync patterns.
Commands:
Replicator behavior:
Alerts
Build an alerts crate/binary.
Commands:
Alert conditions:
stale_after_seconds.Alert outputs:
CLI
Use
clapto make binaries discoverable and friendly.Examples:
Docker
Create Dockerfile and docker-compose.
Compose should include:
Health checks required.
No secrets committed.
Use
.env.example.GitHub Actions
Create CI that runs:
cargo fmt --all -- --check cargo clippy --workspace --all-targets -- -D warnings cargo test --workspace cargo build --workspace --releaseAlso run SQLx/migration checks if feasible.
Tests required
Do not skip tests.
Minimum tests:
Unit tests
Integration tests
Use testcontainers or docker-compose test setup if practical:
Mock Haystack tests
Create a mock Haystack server with Axum or Wiremock:
aboutreadhisReadCollector must pass tests against the mock server.
Documentation expectations
README must include:
AGENTS.md must include:
SECURITY.md must include:
RUNBOOK.md must include:
Acceptance checkpoints
You are not done until all of these are true:
cargo fmt --all -- --checkpasses.cargo clippy --workspace --all-targets -- -D warningspasses.cargo test --workspacepasses.cargo build --workspace --releasepasses.docker compose up --buildstarts Postgres and services./healthworks for admin/API service.doctor.Iteration rule
Work in loops:
Do not stop after generating files. Do not say “you can add tests later.” Do not leave pseudo-code for core paths. If something must be deferred, mark it explicitly as non-core future enhancement and ensure all required core behavior still works.
Engineering style
Prefer boring, maintainable code.
Use:
Avoid:
Final deliverable
When complete, provide:
Remember: this is a real Rust project, not a blog post. Build it until it works.
All reactions