\n```\n\n- **Replaces:** Top-level `let` declarations in non-runes mode.\n- **Class Fields:**\n\n```javascript\nclass Todo {\n\tdone = $state(false);\n\ttext = $state();\n\tconstructor(text) {\n\t\tthis.text = text;\n\t}\n}\n```\n\n- **Deep Reactivity:** Only plain objects and arrays become deeply reactive.\n\n#### $state.raw\n\n- **Purpose:** Declare state that cannot be mutated, only reassigned.\n- **Usage:**\n\n```javascript\n\n```\n\n- **Performance:** Improves with large arrays and objects.\n\n#### $state.snapshot\n\n- **Purpose:** Take a static snapshot of $state.\n- **Usage:**\n\n```javascript\n\n```\n\n#### $derived\n\n- **Purpose:** Declare derived state.\n- **Usage:**\n\n```javascript\n\n```\n\n- **Replaces:** Reactive variables computed using `$:` in non-runes mode.\n\n#### $derived.by\n\n- **Purpose:** Create complex derivations with a function.\n- **Usage:**\n\n```javascript\n\n```\n\n#### $effect\n\n- **Purpose:** Run side-effects when values change.\n- **Usage:**\n\n```javascript\n\n```\n\n- **Replacements:** $effect replaces a substantial part of `$: {}` blocks triggering side-effects.\n\n#### $effect.pre\n\n- **Purpose:** Run code before the DOM updates.\n- **Usage:**\n\n```javascript\n\n```\n\n- **Replaces:** beforeUpdate.\n\n#### $props\n\n- **Purpose:** Declare component props.\n- **Usage:**\n\n```javascript\n\n```\n\n- **Replaces:** export let syntax for declaring props.\n\n#### $bindable\n\n- **Purpose:** Declare bindable props.\n- **Usage:**\n\n```javascript\n\n```\n\n#### Overview of snippets in svelte 5\n\nSnippets, along with render tags, help create reusable chunks of markup inside your components, reducing duplication and enhancing maintainability.\n\n#### Snippets Usage\n\n- **Definition:** Use the `#snippet` syntax to define reusable markup sections.\n- **Basic Example:**\n\n```javascript\n{#snippet figure(image)}\n\t
\n\t\t{image.caption}\n\t\t
{image.caption}
\n\t
\n{/snippet}\n```\n\n- **Invocation:** Render predefined snippets with `@render`:\n\n```javascript\n{@render figure(image)}\n```\n\n#### Snippet Scope\n\n- **Scope Rules:** Snippets have lexical scoping rules; they are visible to everything in the same lexical scope:\n\n```javascript\n
\n\t{#snippet x()}\n\t\t{#snippet y()}...{/snippet}\n\n\t\t\n\t\t{@render y()}\n\t{/snippet}\n\n\t\n\t{@render y()}\n
\n\n\n{@render x()}\n```\n\n#### Passing Snippets to Components\n\n- **Direct Passing:**\n\n```javascript\n\n\n{#snippet header()}\n\tfruit\n\tqty\n\tprice\n\ttotal\n{/snippet}\n\n{#snippet row(fruit)}\n\t{fruit.name}\n\t{fruit.qty}\n\t{fruit.price}\n\t{fruit.qty * fruit.price}\n{/snippet}\n\n\n```\n\n#### Typing Snippets\n\n- **TypeScript Integration:**\n\n```typescript\n\n```\n\n# backend\n\nYou are an expert AI programming assistant specializing in building APIs with Go, using the standard library's net/http package and the new ServeMux.\n\nAlways use the latest stable version of Go (1.23) and be familiar with RESTful API design principles, best practices, and Go idioms.\n\nCORE PRINCIPLES:\n- Follow the user's requirements carefully & to the letter\n- First think step-by-step - describe your plan for the API structure, endpoints, and data flow in pseudocode\n- Confirm the plan, then write code\n- Write correct, up-to-date, bug-free, fully functional, secure, and efficient Go code for APIs\n- Leave NO todos, placeholders, or missing pieces in the API implementation\n- If unsure about a best practice or implementation detail, say so instead of guessing\n\nSTANDARD LIBRARY USAGE:\n1. HTTP Package\n- Use net/http package for API development\n- Utilize ServeMux for routing with new features:\n - Support multiple spaces/tabs after method names in patterns\n - Use wildcard matching and regex support\n- Implement proper HTTP method handlers\n- Use appropriate status codes\n- Format JSON responses correctly\n\n2. Cookie Handling (New in 1.23)\n- Use Cookie.Quoted field for preserving double quotes\n- Implement Request.CookiesNamed for multiple cookies\n- Support Cookie.Partitioned attribute\n- Use ParseCookie/ParseSetCookie functions appropriately\n\n3. Iterator Support (New in 1.23)\n- Use the iter package for user-defined iterators\n- Implement iterator functions matching patterns:\n func(func() bool)\n func(func(K) bool)\n func(func(K, V) bool)\n- Leverage slices package iterator functions:\n - All() for indexes and values\n - Values() for elements\n - Backward() for reverse iteration\n - Collect() for gathering values\n - AppendSeq() for appending values\n - Sorted/SortedFunc/SortedStableFunc for sorted collections\n\n4. Maps Package (New in 1.23)\n- Use maps package iterator functions:\n - All() for key-value pairs\n - Keys() for map keys\n - Values() for map values\n - Insert() for adding pairs\n - Collect() for gathering into maps\n\n5. Value Management (New in 1.23)\n- Use unique package for value canonicalization\n- Apply Handle[T] for efficient comparisons\n- Consider structs package for memory layout control\n- Use HostLayout when interfacing with platform APIs\n\nERROR HANDLING AND LOGGING:\n- Implement proper error handling, including custom error types\n- Properly wrap errors from driver.Valuer implementations\n- Use structured errors with unwrap support\n- Implement proper logging using standard library\n- Consider telemetry for monitoring and debugging\n\nPERFORMANCE AND SECURITY:\n- Timer Considerations (New in 1.23):\n - Handle unbuffered timer channels (capacity 0)\n - Manage timer garbage collection\n - Use GODEBUG=asynctimerchan=1 if needed\n- Utilize Go's built-in concurrency features\n- Implement rate limiting\n- Implement authentication/authorization\n- Apply proper input validation\n- Consider performance implications of struct layout\n\nMIDDLEWARE AND CROSS-CUTTING CONCERNS:\n- Implement middleware for logging, authentication, etc.\n- Consider cross-cutting concerns in API design\n- Handle timeouts and cancellation properly\n\nTESTING:\n- Provide suggestions for testing endpoints\n- Use Go's testing package effectively\n- Consider both unit and integration tests\n\nAlways prioritize:\n1. Security\n2. Scalability\n3. Maintainability\n4. Performance\n5. Code readability\n","breadcrumb":{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.notsobrightideas.com/"},{"@type":"ListItem","position":2,"name":"Cursor Rules","item":"https://www.notsobrightideas.com//cursorrules"},{"@type":"ListItem","position":3,"name":"Rule for raspberry-dashboard","item":"https://www.notsobrightideas.com//cursorrules/WVl2YW5ZYW5nL3Jhc3BiZXJyeS1kYXNoYm9hcmQvLmN1cnNvcnJ1bGVz"}]},"about":[{"@type":"SoftwareSourceCode","name":"raspberry-dashboard","codeRepository":"https://github.com/YYvanYang/raspberry-dashboard/blob/18f7582f118475eedf180dac4e694575acddf056/.cursorrules","programmingLanguage":"Svelte"},{"@type":"SoftwareSourceCode","name":"raspberry-dashboard","codeRepository":"https://github.com/YYvanYang/raspberry-dashboard/blob/18f7582f118475eedf180dac4e694575acddf056/.cursorrules","programmingLanguage":"Svelte"}]}

YYvanYang raspberry-dashboard .cursorrules file for Svelte

# 树莓派管理面板

一个用于监控和管理树莓派的全栈 Web 管理面板。

## 树莓派5多功能服务器完整解决方案

## 系统架构

```
[用户设备]
    ↓
[流量分流]
    |
    ├── Web管理面板访问 ─→ [Cloudflare CDN] ─→ [Cloudflare Tunnel] ─→ 树莓派
    |                                                                    ↓
    |                                                               [管理面板]
    |                                                               Go Backend
    |                                                             Svelte Frontend
    |
    ├── 科学上网请求 ──────→ [Hysteria2] ─────────────────────────→ 树莓派
    |                      (直连或可选CDN)                          ↓
    |                                                         [Hysteria2 Service]
    |
    └── 内网访问请求 ──────→ [WireGuard] ─────────────────────────→ 树莓派
                          (点对点直连)                              ↓
                                                              [WireGuard Service]
```

## 技术栈

### 前端 (frontend)
- SvelteKit 2.0
- Svelte 5.0 (使用 Runes)
- TailwindCSS
- TypeScript
- 主要功能组件:
  - 系统监控图表
  - 服务状态管理
  - 日志查看器
  - 配置编辑器
  - 用户认证

### 后端 (backend)
- Go
- SQLite
- Fiber Web 框架
- 主要功能:
  - RESTful API
  - JWT 认证
  - 系统监控
  - 服务管理
  - 日志管理
  - 配置管理

## 主要功能
- 实时系统资源监控 (CPU、内存、磁盘)
- 系统服务管理
- 系统日志查看
- 配置文件管理
- 用户认证和密码管理

## 项目结构
```
.
├── frontend/           # 前端项目目录
│   ├── src/           # 源代码
│   │   ├── lib/       # 组件和工具
│   │   └── routes/    # 页面路由
│   └── ...
└── backend/           # 后端项目目录
    ├── cmd/          # 入口文件
    └── internal/     # 内部包
        ├── api/      # API 处理
        ├── db/       # 数据库操作
        └── ...
```

# frontend

I'm using svelte 5 instead of svelte 4 here is an overview of the changes.

#### Overview

Svelte 5 introduces runes, a set of advanced primitives for controlling reactivity. The runes replace certain non-runes features and provide more explicit control over state and effects.

### Package manager
use pnpm instead of npm

### TypeScript
use typescript instead of javascript if possible

### Echarts
use echarts instead of chart.js

### fetch
use fetch instead of axios

#### $state

- **Purpose:** Declare reactive state.
- **Usage:**

```javascript
<script>let count = $state(0);</script>
```

- **Replaces:** Top-level `let` declarations in non-runes mode.
- **Class Fields:**

```javascript
class Todo {
	done = $state(false);
	text = $state();
	constructor(text) {
		this.text = text;
	}
}
```

- **Deep Reactivity:** Only plain objects and arrays become deeply reactive.

#### $state.raw

- **Purpose:** Declare state that cannot be mutated, only reassigned.
- **Usage:**

```javascript
<script>let numbers = $state.raw([1, 2, 3]);</script>
```

- **Performance:** Improves with large arrays and objects.

#### $state.snapshot

- **Purpose:** Take a static snapshot of $state.
- **Usage:**

```javascript
<script>
	let counter = $state({ count: 0 });

	function onClick() {
		console.log($state.snapshot(counter));
	}
</script>
```

#### $derived

- **Purpose:** Declare derived state.
- **Usage:**

```javascript
<script>
let count = $state(0); 
let doubled = $derived(count * 2);
</script>
```

- **Replaces:** Reactive variables computed using `$:` in non-runes mode.

#### $derived.by

- **Purpose:** Create complex derivations with a function.
- **Usage:**

```javascript
<script>
	let numbers = $state([1, 2, 3]); 
	let total = $derived.by(() => numbers.reduce((a, b) => a + b, 0));
</script>
```

#### $effect

- **Purpose:** Run side-effects when values change.
- **Usage:**

```javascript
<script>
	let size = $state(50);
	let color = $state('#ff3e00');

	$effect(() => {
		const context = canvas.getContext('2d');
		context.clearRect(0, 0, canvas.width, canvas.height);
		context.fillStyle = color;
		context.fillRect(0, 0, size, size);
	});
</script>
```

- **Replacements:** $effect replaces a substantial part of `$: {}` blocks triggering side-effects.

#### $effect.pre

- **Purpose:** Run code before the DOM updates.
- **Usage:**

```javascript
<script>
	$effect.pre(() => {
		// logic here
	});
</script>
```

- **Replaces:** beforeUpdate.

#### $props

- **Purpose:** Declare component props.
- **Usage:**

```javascript
<script>let { prop1, prop2 } = $props();</script>
```

- **Replaces:** export let syntax for declaring props.

#### $bindable

- **Purpose:** Declare bindable props.
- **Usage:**

```javascript
<script>let { bindableProp = $bindable('fallback') } = $props();</script>
```

#### Overview of snippets in svelte 5

Snippets, along with render tags, help create reusable chunks of markup inside your components, reducing duplication and enhancing maintainability.

#### Snippets Usage

- **Definition:** Use the `#snippet` syntax to define reusable markup sections.
- **Basic Example:**

```javascript
{#snippet figure(image)}
	<figure>
		<img src={image.src} alt={image.caption} width={image.width} height={image.height} />
		<figcaption>{image.caption}</figcaption>
	</figure>
{/snippet}
```

- **Invocation:** Render predefined snippets with `@render`:

```javascript
{@render figure(image)}
```

#### Snippet Scope

- **Scope Rules:** Snippets have lexical scoping rules; they are visible to everything in the same lexical scope:

```javascript
<div>
	{#snippet x()}
		{#snippet y()}...{/snippet}

		<!-- valid usage -->
		{@render y()}
	{/snippet}

	<!-- invalid usage -->
	{@render y()}
</div>

<!-- invalid usage -->
{@render x()}
```

#### Passing Snippets to Components

- **Direct Passing:**

```javascript
<script>
	import Table from './Table.svelte';
	const fruits = [{ name: 'apples', qty: 5, price: 2 }, ...];
</script>

{#snippet header()}
	<th>fruit</th>
	<th>qty</th>
	<th>price</th>
	<th>total</th>
{/snippet}

{#snippet row(fruit)}
	<td>{fruit.name}</td>
	<td>{fruit.qty}</td>
	<td>{fruit.price}</td>
	<td>{fruit.qty * fruit.price}</td>
{/snippet}

<Table data={fruits} {header} {row} />
```

#### Typing Snippets

- **TypeScript Integration:**

```typescript
<script lang="ts">
	import type { Snippet } from 'svelte';

	let { data, children, row }: {
		data: T[];
		children: Snippet;
		row: Snippet<[T]>;
	} = $props();
</script>
```

# backend

You are an expert AI programming assistant specializing in building APIs with Go, using the standard library's net/http package and the new ServeMux.

Always use the latest stable version of Go (1.23) and be familiar with RESTful API design principles, best practices, and Go idioms.

CORE PRINCIPLES:
- Follow the user's requirements carefully & to the letter
- First think step-by-step - describe your plan for the API structure, endpoints, and data flow in pseudocode
- Confirm the plan, then write code
- Write correct, up-to-date, bug-free, fully functional, secure, and efficient Go code for APIs
- Leave NO todos, placeholders, or missing pieces in the API implementation
- If unsure about a best practice or implementation detail, say so instead of guessing

STANDARD LIBRARY USAGE:
1. HTTP Package
- Use net/http package for API development
- Utilize ServeMux for routing with new features:
  - Support multiple spaces/tabs after method names in patterns
  - Use wildcard matching and regex support
- Implement proper HTTP method handlers
- Use appropriate status codes
- Format JSON responses correctly

2. Cookie Handling (New in 1.23)
- Use Cookie.Quoted field for preserving double quotes
- Implement Request.CookiesNamed for multiple cookies
- Support Cookie.Partitioned attribute
- Use ParseCookie/ParseSetCookie functions appropriately

3. Iterator Support (New in 1.23)
- Use the iter package for user-defined iterators
- Implement iterator functions matching patterns:
  func(func() bool)
  func(func(K) bool)
  func(func(K, V) bool)
- Leverage slices package iterator functions:
  - All() for indexes and values
  - Values() for elements
  - Backward() for reverse iteration
  - Collect() for gathering values
  - AppendSeq() for appending values
  - Sorted/SortedFunc/SortedStableFunc for sorted collections

4. Maps Package (New in 1.23)
- Use maps package iterator functions:
  - All() for key-value pairs
  - Keys() for map keys
  - Values() for map values
  - Insert() for adding pairs
  - Collect() for gathering into maps

5. Value Management (New in 1.23)
- Use unique package for value canonicalization
- Apply Handle[T] for efficient comparisons
- Consider structs package for memory layout control
- Use HostLayout when interfacing with platform APIs

ERROR HANDLING AND LOGGING:
- Implement proper error handling, including custom error types
- Properly wrap errors from driver.Valuer implementations
- Use structured errors with unwrap support
- Implement proper logging using standard library
- Consider telemetry for monitoring and debugging

PERFORMANCE AND SECURITY:
- Timer Considerations (New in 1.23):
  - Handle unbuffered timer channels (capacity 0)
  - Manage timer garbage collection
  - Use GODEBUG=asynctimerchan=1 if needed
- Utilize Go's built-in concurrency features
- Implement rate limiting
- Implement authentication/authorization
- Apply proper input validation
- Consider performance implications of struct layout

MIDDLEWARE AND CROSS-CUTTING CONCERNS:
- Implement middleware for logging, authentication, etc.
- Consider cross-cutting concerns in API design
- Handle timeouts and cancellation properly

TESTING:
- Provide suggestions for testing endpoints
- Use Go's testing package effectively
- Consider both unit and integration tests

Always prioritize:
1. Security
2. Scalability
3. Maintainability
4. Performance
5. Code readability
css
dockerfile
go
golang
html
java
javascript
jwt
+9 more

First Time Repository

Svelte

Languages:

CSS: 0.1KB
Dockerfile: 1.5KB
Go: 38.0KB
HTML: 0.5KB
JavaScript: 2.1KB
Shell: 5.0KB
Svelte: 62.1KB
TypeScript: 8.2KB
Created: 12/29/2024
Updated: 12/30/2024

All Repositories (1)