File size: 5,833 Bytes
53c9876
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# Routing Guide

## Application Routes

### Main Routes

| Route | Description | Features |
|-------|-------------|----------|
| `/` | Home page with interactive map | View all sensors, click for overlay dashboard |
| `/sensor/[sensorId]` | Individual sensor detail page | Full dashboard, current readings, mini map |

### Examples

```
http://localhost:3000/                        # Map view
http://localhost:3000/sensor/SENSOR_NYC_001   # NYC sensor
http://localhost:3000/sensor/SENSOR_LON_001   # London sensor
http://localhost:3000/sensor/SENSOR_TKY_001   # Tokyo sensor
```

## Navigation Flow

### From Map to Sensor Detail

```
User Flow:
1. Visit homepage (/)
2. Click sensor marker on map
3. Side panel opens with quick dashboard
4. Click "Open Full Dashboard" button
5. Navigate to /sensor/[sensorId]
```

### Direct Access

Users can directly access any sensor page:
```
http://localhost:3000/sensor/SENSOR_NYC_001
```

This is useful for:
- Bookmarking favorite sensors
- Sharing specific sensor data
- Direct links in reports or emails
- Deep linking from other applications

### Return to Map

On any sensor detail page:
- Click the back arrow (←) in the header
- Returns to the map view

## URL Structure

### Sensor ID Pattern

Sensor IDs follow this format: `SENSOR_[LOCATION]_[NUMBER]`

Examples:
- `SENSOR_NYC_001` - New York City, sensor #1
- `SENSOR_LON_001` - London, sensor #1
- `SENSOR_TKY_001` - Tokyo, sensor #1

### Query Parameters

Currently not used, but can be added for:
- Time range: `?range=1w`
- Metric focus: `?metric=pH`
- Date filters: `?start=2024-01-01&end=2024-01-31`

## API Routes

### Get All Sensors
```
GET /api/sensors
```

Returns all sensors with their latest readings.

**Response:**
```json
[
  {
    "sensorId": "SENSOR_NYC_001",
    "latitude": 40.7128,
    "longitude": -74.0060,
    "locationName": "New York City, USA",
    "installedAt": "2020-01-15T00:00:00.000Z",
    "latestReading": {
      "pH": 7.2,
      "turbidity": 3.5,
      "temperature": 22.1,
      "hardness": 150.0,
      "timestamp": "2024-02-16T10:30:00.000Z"
    }
  }
]
```

### Get Sensor Readings
```
GET /api/readings?sensorId=SENSOR_NYC_001&timeRange=1d
```

**Query Parameters:**
- `sensorId` (required): Sensor identifier
- `timeRange`: `1h`, `1d`, `1w`, `1m` (default: `1d`)
- `startDate`: ISO date string (for custom range)
- `endDate`: ISO date string (for custom range)

**Response:**
```json
[
  {
    "sensorId": "SENSOR_NYC_001",
    "timestamp": "2024-02-16T10:30:00.000Z",
    "pH": 7.2,
    "turbidity": 3.5,
    "temperature": 22.1,
    "hardness": 150.0
  }
]
```

## Route Generation

### Static Routes
- `/` - Always available
- `/api/sensors` - API endpoint
- `/api/readings` - API endpoint

### Dynamic Routes
- `/sensor/[sensorId]` - Generated for each sensor in database

### 404 Handling

If a sensor doesn't exist:
```
http://localhost:3000/sensor/INVALID_SENSOR
```

Shows a custom 404 page with:
- "Sensor Not Found" message
- Link back to map view

## Programmatic Navigation

### Using Next.js Link Component

```tsx
import Link from 'next/link';

<Link href={`/sensor/${sensorId}`}>
  View Sensor
</Link>
```

### Using useRouter Hook

```tsx
import { useRouter } from 'next/navigation';

const router = useRouter();
router.push(`/sensor/${sensorId}`);
```

### Using Browser API

```javascript
window.location.href = `/sensor/${sensorId}`;
```

## SEO & Metadata

Each sensor page has dynamic metadata:

```tsx
// Generates:
<title>New York City, USA - Water Quality Monitor</title>
<meta name="description" content="View real-time water quality data..." />
```

This improves:
- Search engine indexing
- Social media sharing
- Browser tab titles
- Bookmark descriptions

## Deployment Considerations

### Environment Variables

For production, set:
```env
NEXT_PUBLIC_BASE_URL=https://your-domain.com
```

This ensures API calls work correctly when fetching sensor data.

### Vercel Deployment

Routes work automatically. Dynamic routes are:
- Pre-rendered at build time (if using Static Generation)
- Or rendered on-demand (Server-Side Rendering)

### Custom Domain

If deploying to custom domain:
```
https://water-quality.example.com/
https://water-quality.example.com/sensor/SENSOR_NYC_001
```

## Mobile Considerations

All routes are:
- βœ… Fully responsive
- βœ… Touch-friendly
- βœ… Mobile-optimized
- βœ… Work with mobile browsers

## Future Enhancements

### Potential New Routes

1. **Sensor Comparison**
   ```
   /compare?sensors=SENSOR_NYC_001,SENSOR_LON_001
   ```

2. **Analytics Dashboard**
   ```
   /analytics
   ```

3. **Admin Panel**
   ```
   /admin/sensors
   /admin/readings
   ```

4. **Export/Reports**
   ```
   /sensor/SENSOR_NYC_001/export
   /reports
   ```

5. **User Authentication**
   ```
   /login
   /dashboard
   /profile
   ```

### Query Parameter Options

Future query parameters for sensor pages:
```
/sensor/SENSOR_NYC_001?range=1w          # Time range
/sensor/SENSOR_NYC_001?metric=pH         # Focus on specific metric
/sensor/SENSOR_NYC_001?compare=true      # Compare with other sensors
/sensor/SENSOR_NYC_001?export=csv        # Export data
```

## Testing Routes

### Development
```bash
npm run dev

# Test routes:
open http://localhost:3000
open http://localhost:3000/sensor/SENSOR_NYC_001
```

### Production Build
```bash
npm run build
npm start

# All routes should work identically
```

### Using curl
```bash
# Test API
curl http://localhost:3000/api/sensors | jq

# Test specific sensor API
curl "http://localhost:3000/api/readings?sensorId=SENSOR_NYC_001&timeRange=1d" | jq
```

---

## Quick Reference

**Map View:** `/`  
**Sensor Detail:** `/sensor/[sensorId]`  
**Sensors API:** `/api/sensors`  
**Readings API:** `/api/readings?sensorId=XXX`

All routes are fast, SEO-friendly, and mobile-responsive! πŸš€