docs: add frontend development guidelines
This commit is contained in:
5
.trellis/spec/frontend/component-guidelines.md
Normal file
5
.trellis/spec/frontend/component-guidelines.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Component Guidelines
|
||||
|
||||
Use typed React function components. `App.tsx` owns session/editor composition, while reusable map and UI concerns live in named components. Prefer the shared `ui/button.tsx` primitive for commands. Do not create business UI with `querySelector` or `innerHTML`.
|
||||
|
||||
Forms use controlled inputs and submit handlers. Keep map canvas DOM owned by OpenLayers and surrounding controls owned by React.
|
||||
5
.trellis/spec/frontend/directory-structure.md
Normal file
5
.trellis/spec/frontend/directory-structure.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Directory Structure
|
||||
|
||||
The Vite workbench lives in `workbench/client/`. Application code is under `src/`: `components/` for UI, `map/` for OpenLayers adapters, `lib/` for API clients, `types/` for API contracts, and `ui/` for shared primitives. The Node HTTP server remains `workbench/server.js`.
|
||||
|
||||
Keep OpenLayers construction and source mutation outside page components; `src/components/MapCanvas.tsx` owns lifecycle and `src/map/layers.ts` owns the layer registry.
|
||||
3
.trellis/spec/frontend/hook-guidelines.md
Normal file
3
.trellis/spec/frontend/hook-guidelines.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Hook Guidelines
|
||||
|
||||
Use effects for imperative OpenLayers lifecycle only. `MapCanvas.tsx` constructs one map on mount, updates sources when server state changes, and updates visibility separately. Store callback-sensitive values such as selected road and scene mode in refs so stable OpenLayers style callbacks see current values.
|
||||
39
.trellis/spec/frontend/index.md
Normal file
39
.trellis/spec/frontend/index.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Frontend Development Guidelines
|
||||
|
||||
> Best practices for frontend development in this project.
|
||||
|
||||
---
|
||||
|
||||
## Overview
|
||||
|
||||
This directory contains guidelines for frontend development. Fill in each file with your project's specific conventions.
|
||||
|
||||
---
|
||||
|
||||
## Guidelines Index
|
||||
|
||||
| Guide | Description | Status |
|
||||
|-------|-------------|--------|
|
||||
| [Directory Structure](./directory-structure.md) | Module organization and file layout | To fill |
|
||||
| [Component Guidelines](./component-guidelines.md) | Component patterns, props, composition | To fill |
|
||||
| [Hook Guidelines](./hook-guidelines.md) | Custom hooks, data fetching patterns | To fill |
|
||||
| [State Management](./state-management.md) | Local state, global state, server state | To fill |
|
||||
| [Quality Guidelines](./quality-guidelines.md) | Code standards, forbidden patterns | To fill |
|
||||
| [Type Safety](./type-safety.md) | Type patterns, validation | To fill |
|
||||
|
||||
---
|
||||
|
||||
## How to Fill These Guidelines
|
||||
|
||||
For each guideline file:
|
||||
|
||||
1. Document your project's **actual conventions** (not ideals)
|
||||
2. Include **code examples** from your codebase
|
||||
3. List **forbidden patterns** and why
|
||||
4. Add **common mistakes** your team has made
|
||||
|
||||
The goal is to help AI assistants and new team members understand how YOUR project works.
|
||||
|
||||
---
|
||||
|
||||
**Language**: All documentation should be written in **English**.
|
||||
3
.trellis/spec/frontend/state-management.md
Normal file
3
.trellis/spec/frontend/state-management.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# State Management
|
||||
|
||||
Use component `useState` for server state, selection, staged overrides, layer visibility and UI filters. `src/lib/api.ts` is the sole browser HTTP boundary. Keep staged overrides separate from persisted `WorkbenchState.overrides`; save them before compile.
|
||||
3
.trellis/spec/frontend/type-safety.md
Normal file
3
.trellis/spec/frontend/type-safety.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Type Safety
|
||||
|
||||
Define browser contracts in `src/types/state.ts` from actual workbench API payloads. Use `unknown` for extensible GeoJSON properties and comparison payloads, then narrow locally. Run `npm run test:client` after TypeScript changes; avoid `any` and broad assertions.
|
||||
Reference in New Issue
Block a user