RoyAalekh commited on
Commit
04315ad
·
1 Parent(s): df236f5

docs(cache): document HF Spaces cache resolution; bump SW VERSION to invalidate old assets

Browse files
Files changed (2) hide show
  1. llm.txt +604 -597
  2. static/sw.js +1 -1
llm.txt CHANGED
@@ -1,597 +1,604 @@
1
- # TreeTrack - Professional Field Research Platform - LLM Knowledge Base
2
-
3
- ## PROJECT OVERVIEW
4
- TreeTrack is a comprehensive tree mapping and urban forestry management web application with Supabase cloud database, modular JavaScript architecture, and beautiful interactive mapping. Deployed on **Hugging Face Spaces** using **Docker**.
5
-
6
- ### Current Status & Direct Access
7
- - **Live Application**: https://huggingface.co/spaces/RoyAalekh/TreeTrack
8
- - **Main Interface**: https://royaalekh-treetrack.hf.space/
9
- - **Interactive Map**: https://royaalekh-treetrack.hf.space/map
10
- - **API Documentation**: https://royaalekh-treetrack.hf.space/docs
11
- - **Health Check**: https://royaalekh-treetrack.hf.space/health
12
- - **Login Page**: https://royaalekh-treetrack.hf.space/login
13
- - **Repository**: https://huggingface.co/spaces/RoyAalekh/TreeTrack/tree/main
14
-
15
- ### Key Information:
16
- - **Platform**: Hugging Face Spaces (Docker deployment)
17
- - **Database**: Supabase PostgreSQL with cloud storage
18
- - **Technology Stack**: FastAPI + Supabase + Modular JavaScript (ES6) + Interactive Maps
19
- - **Purpose**: Professional field research tool for tree documentation with 12 comprehensive data fields
20
- - **Architecture**: Modular design with 6 specialized JavaScript modules + beautiful tree-shaped map pins
21
- - **Version**: 3.0.0 (Latest: Supabase Edition with enhanced mapping)
22
- - **Authentication**: Multi-role system (admin, researcher, viewer)
23
-
24
- ## CURRENT DATABASE ARCHITECTURE (SUPABASE)
25
-
26
- ### Database Provider: Supabase
27
- - **Type**: PostgreSQL cloud database
28
- - **Storage**: Supabase Storage for file uploads
29
- - **Real-time**: Supabase real-time capabilities
30
- - **Authentication**: Supabase Auth integration
31
- - **URL**: Configured via environment variables
32
-
33
- ### Key Database Files
34
- - **supabase_client.py**: Supabase client configuration and connection
35
- - **supabase_database.py**: Database operations and queries
36
- - **supabase_storage.py**: File storage operations
37
- - **master_tree_database.py**: Master tree species database with autocomplete
38
- - **auth.py**: Authentication logic and user management
39
-
40
- ### Database Tables
41
- 1. **trees**: Main tree records table with all 12 fields
42
- 2. **users**: User authentication and permissions
43
- 3. **file_uploads**: Tracking uploaded images/audio files
44
- 4. **master_species**: Reference database of tree species for autocomplete
45
-
46
- ## INTERACTIVE MAPPING SYSTEM
47
-
48
- ### Current Map Features
49
- - **Technology**: Leaflet.js with custom styling
50
- - **Map Interface**: https://royaalekh-treetrack.hf.space/map
51
- - **Beautiful Tree Pins**:
52
- - Red tree-shaped pins for new locations (temporary)
53
- - Green tree-shaped pins for existing trees (permanent)
54
- - 3D layered design with drop shadows
55
- - Multiple highlight layers for realistic appearance
56
-
57
- ### Pin Design Specifications
58
- - **Temporary Pins**: 32x40 pixels, red base (#dc2626) with tree icon
59
- - **Tree Markers**: 36x44 pixels, green base (#16a34a) with detailed tree design
60
- - **User Location**: 24x32 pixels, blue pin (#3b82f6)
61
- - **Features**: SVG-based, scalable, professional appearance
62
-
63
- ### Map Functionality
64
- - **Pin Dropping**: Click anywhere to drop location pin
65
- - **Location Transfer**: Selected coordinates auto-fill form
66
- - **Tree Popups**: Enhanced modal with proper close button and responsive design
67
- - **GPS Location**: Get current user location
68
- - **Tree Clustering**: Multiple trees in same area
69
- - **Fixed Issues**: Popup overflow, button positioning, close button functionality
70
-
71
- ## AUTHENTICATION SYSTEM
72
-
73
- ### User Roles & Permissions
74
- 1. **Admin**: Full access (create, read, update, delete all)
75
- 2. **System**: Full administrative access
76
- 3. **Researcher**: Can add and edit own trees, view all
77
- 4. **Viewer**: Read-only access to tree data
78
-
79
- ### Authentication Features
80
- - **Multi-role System**: Role-based access control
81
- - **Session Management**: Secure token-based sessions
82
- - **Login UI**: Professional login interface at /login
83
- - **Permission Checking**: Per-operation permission validation
84
-
85
- ### Default Authentication (configured in auth.py)
86
- - Admin user with full permissions
87
- - System user for automated operations
88
- - Role-based tree editing and deletion rights
89
-
90
- ## DEPLOYMENT ARCHITECTURE
91
-
92
- ### Hugging Face Spaces Configuration
93
- - **App Port**: 7860 (required by HF Spaces)
94
- - **SDK**: docker
95
- - **Command**: `uvicorn app:app --host 0.0.0.0 --port 7860`
96
- - **User Context**: Non-root user (uid 1000) for security
97
- - **Base Image**: python:3.11-slim
98
-
99
- ### Docker Configuration
100
- ```dockerfile
101
- FROM python:3.11-slim
102
- RUN useradd -m -u 1000 user
103
- USER user
104
- WORKDIR /app
105
- EXPOSE 7860
106
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
107
- ```
108
-
109
- ## MODULAR ARCHITECTURE (Version 3.0.0)
110
-
111
- ### Current Implementation
112
- - **Architecture**: Fully modular design with 6 specialized JavaScript modules
113
- - **Benefits**: Better maintainability, testability, and performance
114
- - **Design**: Clean separation of concerns with dependency injection
115
- - **UI**: Professional emoji-free interface suitable for research
116
-
117
- ### Modular Architecture
118
-
119
- #### Module Structure
120
- ```
121
- static/js/
122
- ├── modules/
123
- │ ├── auth-manager.js - Authentication & permissions (95 lines)
124
- │ ├── api-client.js - API communication (148 lines)
125
- │ ├── ui-manager.js - User interface & messaging (192 lines)
126
- │ ├── form-manager.js - Form handling & validation (285 lines)
127
- │ ├── autocomplete-manager.js - Smart suggestions (322 lines)
128
- │ └── media-manager.js - File uploads & recording (268 lines)
129
- └── tree-track-app.js - Main orchestrator (206 lines)
130
- ```
131
-
132
- #### Module Dependencies
133
- ```
134
- TreeTrackApp
135
- ├── AuthManager (independent)
136
- ├── ApiClient (depends on AuthManager)
137
- ├── UIManager (depends on AuthManager)
138
- ├── FormManager (depends on ApiClient, UIManager)
139
- ├── AutoCompleteManager (depends on ApiClient, UIManager)
140
- └── MediaManager (depends on FormManager, UIManager)
141
- ```
142
-
143
- #### Key Improvements
144
- - **Separation of Concerns**: Each module has single responsibility
145
- - **Dependency Injection**: Clean dependencies between modules
146
- - **ES6 Modules**: Modern import/export structure
147
- - **Event Delegation**: Replaced global functions with proper event handling
148
- - **Performance**: Debounced search, Promise.all(), DOM caching
149
- - **Error Handling**: Centralized error management
150
- - **Code Reuse**: Shared utilities across modules
151
-
152
- ## TECHNOLOGY STACK
153
-
154
- ### Backend
155
- - **Framework**: FastAPI 0.115.0+
156
- - **Server**: Uvicorn with standard extras
157
- - **Database**: Supabase PostgreSQL (cloud-hosted)
158
- - **Storage**: Supabase Storage for file uploads
159
- - **Authentication**: Supabase Auth integration
160
- - **File Handling**: aiofiles for async file operations
161
- - **Validation**: Pydantic 2.10.0+ with custom validators
162
- - **Configuration**: pydantic-settings for environment-based config
163
-
164
- ### Frontend (Refactored)
165
- - **JavaScript**: Modular ES6+ with 6 specialized modules
166
- - **Architecture**: Dependency injection pattern
167
- - **Performance**: Debounced search (300ms), parallel API calls
168
- - **CSS**: Custom responsive design with Inter font (emoji-free)
169
- - **PWA**: Service Worker for offline capabilities
170
- - **Maps**: Interactive mapping with marker clustering
171
- - **Media**: Camera integration and audio recording
172
-
173
- ### Dependencies
174
- ```
175
- fastapi>=0.115.0
176
- uvicorn[standard]>=0.32.0
177
- python-multipart>=0.0.12
178
- pydantic>=2.10.0
179
- pydantic-settings>=2.6.0
180
- pandas>=2.3.1
181
- aiofiles>=24.1.0
182
- GitPython>=3.1.40
183
- huggingface-hub>=0.19.0
184
- ```
185
-
186
- ## DATA MODEL - 12 COMPREHENSIVE FIELDS
187
-
188
- ### Core Tree Data Structure
189
- 1. **Geolocation** (Required)
190
- - Latitude: REAL (-90 to 90)
191
- - Longitude: REAL (-180 to 180)
192
-
193
- 2. **Identification**
194
- - Local Name (Assamese): TEXT (max 200 chars)
195
- - Scientific Name: TEXT (max 200 chars)
196
- - Common Name: TEXT (max 200 chars)
197
- - Tree Reference Code: TEXT (max 20 chars, e.g., "C.A", "A-G1")
198
-
199
- 3. **Physical Measurements**
200
- - Height: REAL (meters, 0-200)
201
- - Width/Girth: REAL (cm, 0-2000)
202
-
203
- 4. **Ecological & Cultural Data**
204
- - Utility: JSON array of selected utilities
205
- - Valid options: "Religious", "Timber", "Biodiversity", "Hydrological benefit", "Faunal interaction", "Food", "Medicine", "Shelter", "Cultural"
206
-
207
- 5. **Phenology Assessment**
208
- - Stages: JSON array of current development stages
209
- - Valid options: "New leaves", "Old leaves", "Open flowers", "Fruiting", "Ripe fruit", "Recent fruit drop", "Other"
210
-
211
- 6. **Documentation**
212
- - Photographs: JSON object with categories and file paths
213
- - Categories: "Leaf", "Bark", "Fruit", "Seed", "Flower", "Full tree"
214
- - Storytelling Text: TEXT (max 5000 chars)
215
- - Storytelling Audio: File path to audio recording
216
-
217
- 7. **Field Notes**
218
- - Notes: TEXT (max 2000 chars) for additional observations
219
-
220
- ### System Fields
221
- - ID: Auto-increment primary key
222
- - Timestamp: Auto-generated creation time
223
- - Created_by: Default 'system'
224
- - Updated_at: Auto-updated modification time
225
-
226
- ## SECURITY ARCHITECTURE
227
-
228
- ### Multi-Layer Security
229
- - **Input Validation**: Pydantic models with custom validators
230
- - **SQL Injection Prevention**: Parameterized queries only
231
- - **XSS Protection**: Content Security Policy headers
232
- - **CORS**: Configured for specific origins
233
- - **File Security**: Secure path validation, type checking
234
- - **Rate Limiting**: Configurable request limits
235
- - **Error Handling**: Comprehensive exception management
236
-
237
- ### Production Security Settings
238
- - Secret key validation (min 32 chars)
239
- - Debug mode disabled
240
- - Secure headers (X-Frame-Options, X-Content-Type-Options, etc.)
241
- - Trusted host middleware available
242
-
243
- ## CACHE MANAGEMENT SYSTEM
244
-
245
- ### Current Issue: Aggressive Service Worker Caching
246
- The app uses a Service Worker (`sw.js`) for PWA capabilities and offline support, but this causes caching issues during development.
247
-
248
- ### Service Worker Configuration
249
- - **Cache Name**: `treetrack-v{timestamp}` (dynamic versioning implemented)
250
- - **Cached Resources**: HTML, JS, CSS, external fonts/libraries
251
- - **Cache Strategy**: Cache-first for production, network-first for development
252
- - **Development Mode Detection**: `isDevelopment = self.location.hostname === 'localhost' || '127.0.0.1'`
253
-
254
- ### Cache Busting Solutions Implemented
255
-
256
- #### 1. Dynamic Service Worker Versioning
257
- ```javascript
258
- const VERSION = new Date().getTime(); // Dynamic versioning
259
- const CACHE_NAME = `treetrack-v${VERSION}`;
260
- ```
261
-
262
- #### 2. Development Mode Cache Bypass
263
- ```javascript
264
- if (isDevelopment && event.request.url.includes('/static/')) {
265
- event.respondWith(
266
- fetch(event.request, { cache: 'no-cache' })
267
- );
268
- }
269
- ```
270
-
271
- #### 3. Version Management API
272
- - **GET /api/version**: Returns current version info
273
- - **POST /api/version/update**: Forces version update and cache clear
274
-
275
- #### 4. HTML Cache Busting
276
- ```html
277
- <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
278
- <meta http-equiv="Pragma" content="no-cache">
279
- <meta http-equiv="Expires" content="0">
280
- <script src="/static/app.js?v=3.{timestamp}&t={timestamp}">
281
- ```
282
-
283
- #### 5. FastAPI Middleware
284
- ```python
285
- @app.middleware("http")
286
- async def add_cache_headers(request: Request, call_next):
287
- if request.url.path.startswith("/static/"):
288
- response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
289
- ```
290
-
291
- ## FILE STRUCTURE (Current)
292
-
293
- ```
294
- TreeTrack/
295
- ├── README.md # HF Spaces config + documentation
296
- ├── Dockerfile # HF Spaces Docker configuration
297
- ├── requirements.txt # Python dependencies
298
- ├── llm.txt # LLM knowledge base (this file)
299
- ├── app.py # Main FastAPI application
300
- ├── config.py # Comprehensive configuration system
301
- ├── constants.py # Application constants
302
- ├── auth.py # Authentication system
303
- ├── supabase_client.py # Supabase connection client
304
- ├── supabase_database.py # Database operations
305
- ├── supabase_storage.py # File storage operations
306
- ├── master_tree_database.py # Tree species autocomplete
307
- ├── .env.example # Environment variables template
308
- ├── .gitattributes # Git configuration
309
- ├── .gitignore # Git ignore patterns
310
- ├── data/
311
- │ └── master_trees.db # Local SQLite for tree species
312
- └── static/
313
- ├── css/
314
- │ └── design-system.css # Professional design system
315
- ├── index.html # Main application interface
316
- ├── login.html # Login page
317
- ├── map.html # Interactive map interface
318
- ├── map.js # Map functionality
319
- ├── sw.js # Service Worker for PWA
320
- └── js/
321
- ├── modules/
322
- ├── auth-manager.js # Authentication module
323
- ├── api-client.js # API communication module
324
- ├── ui-manager.js # UI management module
325
- ├── form-manager.js # Form handling module
326
- ├── autocomplete-manager.js # Smart suggestions module
327
- └── media-manager.js # Media handling module
328
- └── tree-track-app.js # Main orchestrator
329
- ```
330
-
331
- ## API ENDPOINTS
332
-
333
- ### Core Tree Management
334
- - `GET /api/trees` - List trees with filtering/pagination
335
- - `POST /api/trees` - Create new tree record
336
- - `GET /api/trees/{id}` - Get specific tree
337
- - `PUT /api/trees/{id}` - Update tree record
338
- - `DELETE /api/trees/{id}` - Delete tree record
339
-
340
- ### File Upload
341
- - `POST /api/upload/image` - Upload categorized photos
342
- - `POST /api/upload/audio` - Upload storytelling audio
343
- - `GET /api/files/{type}/{filename}` - Serve uploaded files
344
-
345
- ### Form Data Helpers
346
- - `GET /api/utilities` - Valid utility options
347
- - `GET /api/phenology-stages` - Valid phenology stages
348
- - `GET /api/photo-categories` - Valid photo categories
349
-
350
- ### System Management
351
- - `GET /health` - Health check
352
- - `GET /api/stats` - Comprehensive statistics
353
- - `GET /api/version` - Current version info
354
- - `POST /api/version/update` - Force cache clear
355
- - `GET /api/persistence/status` - Database backup status
356
- - `POST /api/persistence/backup` - Force database backup
357
-
358
- ### Frontend Routes
359
- - `GET /` - Main application (index.html)
360
- - `GET /map` - Interactive map interface
361
- - `GET /docs` - FastAPI auto-generated API documentation
362
-
363
- ## CONFIGURATION SYSTEM
364
-
365
- ### Environment-Based Settings (config.py)
366
- - **DatabaseConfig**: SQLite settings, backup configuration
367
- - **SecurityConfig**: Authentication, CORS, CSP, rate limiting
368
- - **ServerConfig**: Host, port, workers, timeout settings
369
- - **LoggingConfig**: File logging, rotation, access logs
370
- - **CacheConfig**: TTL settings, cache sizes
371
- - **MonitoringConfig**: Metrics, health checks, alerting
372
- - **ApplicationConfig**: Feature flags, validation rules
373
-
374
- ### Configuration Hierarchy
375
- 1. Environment variables
376
- 2. `.env` file
377
- 3. Default values in config classes
378
-
379
- ## COMMON ISSUES & SOLUTIONS
380
-
381
- ### Cache Issues (PRIMARY ISSUE)
382
- **Problem**: Service Worker aggressively caches static files
383
- **Solutions**:
384
- 1. Run `python clear_cache.py` to update all version files
385
- 2. Manually clear Service Worker in DevTools > Application > Service Workers
386
- 3. Use `Ctrl+Shift+R` for hard refresh
387
- 4. Open in incognito/private mode for testing
388
- 5. Use version API endpoints to force cache updates
389
-
390
- ### Deployment to HF Spaces
391
- **Remember**: This app runs on Hugging Face Spaces, not localhost
392
- - Port must be 7860
393
- - Use Docker deployment
394
- - Non-root user for security
395
- - Static files served through FastAPI
396
-
397
- ### Development vs Production
398
- - Development: Cache bypassing enabled
399
- - Production: Full caching for performance
400
- - Environment detection via hostname
401
-
402
- ## CACHE BUSTING WORKFLOW
403
-
404
- ### For Hugging Face Spaces Deployment (PRIMARY)
405
- ```bash
406
- # Run HF Spaces optimized cache manager
407
- python hf_cache_manager.py
408
- ```
409
-
410
- ### For Local Development
411
- ```bash
412
- # Run comprehensive cache buster
413
- python clear_cache.py
414
-
415
- # Or use batch file on Windows
416
- clear_cache.bat
417
- ```
418
-
419
- ### Manual Steps
420
- 1. Update service worker version: `const VERSION = {timestamp}`
421
- 2. Update HTML cache busting parameters
422
- 3. Update version.json file
423
- 4. Clear browser service worker
424
- 5. Hard refresh browser
425
- 6. Test in incognito mode
426
-
427
- ### API-Based Solution
428
- ```bash
429
- # Update version via API (when server running)
430
- curl -X POST http://localhost:7860/api/version/update
431
-
432
- # Check current version
433
- curl http://localhost:7860/api/version
434
- ```
435
-
436
- ## DEVELOPMENT GUIDELINES
437
-
438
- ### Adding New Features
439
- 1. Update Pydantic models in app.py
440
- 2. Add API endpoints with proper validation
441
- 3. Update frontend JavaScript
442
- 4. Add appropriate tests
443
- 5. Update cache version if static files change
444
-
445
- ### Database Schema Changes
446
- - Use SQLite migrations carefully
447
- - Backup database before schema changes
448
- - Update Pydantic models to match
449
- - Test with existing data
450
-
451
- ### Security Considerations
452
- - Always validate input with Pydantic
453
- - Use parameterized queries
454
- - Implement rate limiting for public endpoints
455
- - Regular security header updates
456
- - Monitor for suspicious activity
457
-
458
- ## CACHE VERSION HISTORY
459
- - v3.0: Initial version with basic cache busting
460
- - v3.{timestamp}: Dynamic versioning system
461
- - Current: Automated cache management with API endpoints
462
-
463
- ## TROUBLESHOOTING CHECKLIST
464
-
465
- ### UI Not Updating
466
- 1. Check if service worker is registered (DevTools > Application)
467
- 2. Unregister service worker if present
468
- 3. Hard refresh browser (Ctrl+Shift+R)
469
- 4. Check Network tab for 304 (cached) responses
470
- 5. Try incognito/private mode
471
- 6. Run cache buster script
472
- 7. Verify version.json timestamp is recent
473
-
474
- ### Deployment Issues
475
- 1. Verify Dockerfile uses port 7860
476
- 2. Check requirements.txt is complete
477
- 3. Ensure non-root user setup
478
- 4. Verify static files are copied correctly
479
- 5. Check HF Spaces logs for errors
480
-
481
- ## CURRENT STATUS ENDPOINTS & DATA ACCESS
482
-
483
- ### System Status URLs
484
- - **Health Check**: https://royaalekh-treetrack.hf.space/health
485
- - **API Stats**: https://royaalekh-treetrack.hf.space/api/stats
486
- - **Version Info**: https://royaalekh-treetrack.hf.space/api/version
487
- - **Tree Data**: https://royaalekh-treetrack.hf.space/api/trees
488
-
489
- ### Interactive API Documentation
490
- - **Swagger UI**: https://royaalekh-treetrack.hf.space/docs
491
- - **ReDoc**: https://royaalekh-treetrack.hf.space/redoc
492
-
493
- ## RECENT MAJOR UPDATES (Latest Commits)
494
-
495
- ### Repository Cleanup (Latest)
496
- - Removed development documentation files
497
- - Cleaned up repository structure
498
- - Preserved all core functionality
499
- - Maintained Supabase integration files
500
-
501
- ### Enhanced Map Pins (Recent)
502
- - Beautiful tree-shaped SVG pins with 3D design
503
- - Fixed popup modal overflow and layout issues
504
- - Improved responsive design for mobile
505
- - Enhanced close button functionality
506
- - Better coordinate transfer from map to form
507
-
508
- ### Modular Architecture (Version 3.0.0)
509
- - Complete modular design with 6 specialized modules
510
- - Professional emoji-free interface
511
- - Enhanced button design with improved UX
512
- - Better performance and maintainability
513
-
514
- ## FILE LOCATIONS FOR SPECIFIC FUNCTIONALITY
515
-
516
- ### Authentication & Users
517
- - **Backend**: `auth.py` (user management and permissions)
518
- - **Frontend**: `static/js/modules/auth-manager.js`
519
- - **Login Page**: `static/login.html`
520
-
521
- ### Database Operations
522
- - **Main Database**: `supabase_database.py` (all CRUD operations)
523
- - **Supabase Client**: `supabase_client.py` (connection and config)
524
- - **Storage**: `supabase_storage.py` (file uploads)
525
- - **Species Data**: `master_tree_database.py` (autocomplete)
526
-
527
- ### Interactive Mapping
528
- - **Map Logic**: `static/map.js` (all mapping functionality)
529
- - **Map Interface**: `static/map.html` (map page UI)
530
- - **Pin Design**: Look for SVG definitions in map.js
531
- - **Popup Modals**: Enhanced popup content in map.js
532
-
533
- ### Form Handling
534
- - **Main Form**: `static/index.html` (12-field tree form)
535
- - **Form Logic**: `static/js/modules/form-manager.js`
536
- - **Validation**: Both client-side and server-side in app.py
537
- - **Autocomplete**: `static/js/modules/autocomplete-manager.js`
538
-
539
- ### File Uploads & Media
540
- - **Media Handling**: `static/js/modules/media-manager.js`
541
- - **Camera Integration**: Photo capture functionality
542
- - **Audio Recording**: Voice memo functionality
543
- - **File Processing**: Server-side in app.py upload endpoints
544
-
545
- ### User Interface
546
- - **UI Updates**: `static/js/modules/ui-manager.js`
547
- - **Messages**: Success/error message system
548
- - **Tree List**: Dynamic tree list rendering
549
- - **Loading States**: Progress indicators and feedback
550
-
551
- ## USAGE INSTRUCTIONS FOR LLMs
552
-
553
- ### To Understand Project Structure:
554
- 1. **Main Application Logic**: Review app.py for API endpoints and business logic
555
- 2. **Frontend Architecture**: Check static/js/modules/ for modular components
556
- 3. **Database Schema**: Look at Pydantic models in app.py and Supabase operations
557
- 4. **Authentication Flow**: Review auth.py and auth-manager.js
558
- 5. **Mapping Features**: Examine map.js for interactive map functionality
559
-
560
- ### To Debug Specific Issues:
561
- 1. **API Problems**: Test endpoints via /docs interface
562
- 2. **Database Issues**: Check supabase_database.py operations
563
- 3. **UI Problems**: Review browser console and specific module files
564
- 4. **Authentication**: Check auth.py user configuration
565
- 5. **Map Problems**: Look at map.js event handlers and pin creation
566
-
567
- ### To Add New Features:
568
- 1. **Backend**: Extend app.py with new FastAPI routes
569
- 2. **Database**: Add operations to supabase_database.py
570
- 3. **Frontend**: Extend appropriate JavaScript module
571
- 4. **UI Changes**: Modify HTML files in static/
572
- 5. **New Pages**: Add route in app.py and HTML file in static/
573
-
574
- ### To Modify Existing Features:
575
- 1. **Tree Data Model**: Update Pydantic models in app.py
576
- 2. **Form Fields**: Modify index.html and form-manager.js
577
- 3. **Map Functionality**: Update map.js and map.html
578
- 4. **Authentication**: Modify auth.py and auth-manager.js
579
- 5. **File Handling**: Update media-manager.js and storage operations
580
-
581
- ## DEPLOYMENT STATUS & MONITORING
582
-
583
- ### Current Deployment Status
584
- - **Status**: LIVE and OPERATIONAL
585
- - **Platform**: Hugging Face Spaces Docker
586
- - **Build Status**: Automatic deployment from main branch
587
- - **Health Monitoring**: Real-time via /health endpoint
588
- - **Performance**: Monitored via Supabase dashboard
589
-
590
- ### Key Metrics to Monitor
591
- - **Response Time**: API endpoint performance
592
- - **Database Load**: Supabase connection usage
593
- - **Storage Usage**: File upload storage consumption
594
- - **User Activity**: Authentication and session metrics
595
- - **Error Rates**: Application error frequency
596
-
597
- This comprehensive knowledge base reflects the current state of TreeTrack as of the latest updates and serves as the definitive guide for understanding the project's architecture, implementation, and operational status.
 
 
 
 
 
 
 
 
1
+ # TreeTrack - Professional Field Research Platform - LLM Knowledge Base
2
+
3
+ ## PROJECT OVERVIEW
4
+ TreeTrack is a comprehensive tree mapping and urban forestry management web application with Supabase cloud database, modular JavaScript architecture, and beautiful interactive mapping. Deployed on **Hugging Face Spaces** using **Docker**.
5
+
6
+ ### Current Status & Direct Access
7
+ - **Live Application**: https://huggingface.co/spaces/RoyAalekh/TreeTrack
8
+ - **Main Interface**: https://royaalekh-treetrack.hf.space/
9
+ - **Interactive Map**: https://royaalekh-treetrack.hf.space/map
10
+ - **API Documentation**: https://royaalekh-treetrack.hf.space/docs
11
+ - **Health Check**: https://royaalekh-treetrack.hf.space/health
12
+ - **Login Page**: https://royaalekh-treetrack.hf.space/login
13
+ - **Repository**: https://huggingface.co/spaces/RoyAalekh/TreeTrack/tree/main
14
+
15
+ ### Key Information:
16
+ - **Platform**: Hugging Face Spaces (Docker deployment)
17
+ - **Database**: Supabase PostgreSQL with cloud storage
18
+ - **Technology Stack**: FastAPI + Supabase + Modular JavaScript (ES6) + Interactive Maps
19
+ - **Purpose**: Professional field research tool for tree documentation with 12 comprehensive data fields
20
+ - **Architecture**: Modular design with 6 specialized JavaScript modules + beautiful tree-shaped map pins
21
+ - **Version**: 3.0.0 (Latest: Supabase Edition with enhanced mapping)
22
+ - **Authentication**: Multi-role system (admin, researcher, viewer)
23
+
24
+ ## CURRENT DATABASE ARCHITECTURE (SUPABASE)
25
+
26
+ ### Database Provider: Supabase
27
+ - **Type**: PostgreSQL cloud database
28
+ - **Storage**: Supabase Storage for file uploads
29
+ - **Real-time**: Supabase real-time capabilities
30
+ - **Authentication**: Supabase Auth integration
31
+ - **URL**: Configured via environment variables
32
+
33
+ ### Key Database Files
34
+ - **supabase_client.py**: Supabase client configuration and connection
35
+ - **supabase_database.py**: Database operations and queries
36
+ - **supabase_storage.py**: File storage operations
37
+ - **master_tree_database.py**: Master tree species database with autocomplete
38
+ - **auth.py**: Authentication logic and user management
39
+
40
+ ### Database Tables
41
+ 1. **trees**: Main tree records table with all 12 fields
42
+ 2. **users**: User authentication and permissions
43
+ 3. **file_uploads**: Tracking uploaded images/audio files
44
+ 4. **master_species**: Reference database of tree species for autocomplete
45
+
46
+ ## INTERACTIVE MAPPING SYSTEM
47
+
48
+ ### Current Map Features
49
+ - **Technology**: Leaflet.js with custom styling
50
+ - **Map Interface**: https://royaalekh-treetrack.hf.space/map
51
+ - **Beautiful Tree Pins**:
52
+ - Red tree-shaped pins for new locations (temporary)
53
+ - Green tree-shaped pins for existing trees (permanent)
54
+ - 3D layered design with drop shadows
55
+ - Multiple highlight layers for realistic appearance
56
+
57
+ ### Pin Design Specifications
58
+ - **Temporary Pins**: 32x40 pixels, red base (#dc2626) with tree icon
59
+ - **Tree Markers**: 36x44 pixels, green base (#16a34a) with detailed tree design
60
+ - **User Location**: 24x32 pixels, blue pin (#3b82f6)
61
+ - **Features**: SVG-based, scalable, professional appearance
62
+
63
+ ### Map Functionality
64
+ - **Pin Dropping**: Click anywhere to drop location pin
65
+ - **Location Transfer**: Selected coordinates auto-fill form
66
+ - **Tree Popups**: Enhanced modal with proper close button and responsive design
67
+ - **GPS Location**: Get current user location
68
+ - **Tree Clustering**: Multiple trees in same area
69
+ - **Fixed Issues**: Popup overflow, button positioning, close button functionality
70
+
71
+ ## AUTHENTICATION SYSTEM
72
+
73
+ ### User Roles & Permissions
74
+ 1. **Admin**: Full access (create, read, update, delete all)
75
+ 2. **System**: Full administrative access
76
+ 3. **Researcher**: Can add and edit own trees, view all
77
+ 4. **Viewer**: Read-only access to tree data
78
+
79
+ ### Authentication Features
80
+ - **Multi-role System**: Role-based access control
81
+ - **Session Management**: Secure token-based sessions
82
+ - **Login UI**: Professional login interface at /login
83
+ - **Permission Checking**: Per-operation permission validation
84
+
85
+ ### Default Authentication (configured in auth.py)
86
+ - Admin user with full permissions
87
+ - System user for automated operations
88
+ - Role-based tree editing and deletion rights
89
+
90
+ ## DEPLOYMENT ARCHITECTURE
91
+
92
+ ### Hugging Face Spaces Configuration
93
+ - **App Port**: 7860 (required by HF Spaces)
94
+ - **SDK**: docker
95
+ - **Command**: `uvicorn app:app --host 0.0.0.0 --port 7860`
96
+ - **User Context**: Non-root user (uid 1000) for security
97
+ - **Base Image**: python:3.11-slim
98
+
99
+ ### Docker Configuration
100
+ ```dockerfile
101
+ FROM python:3.11-slim
102
+ RUN useradd -m -u 1000 user
103
+ USER user
104
+ WORKDIR /app
105
+ EXPOSE 7860
106
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
107
+ ```
108
+
109
+ ## MODULAR ARCHITECTURE (Version 3.0.0)
110
+
111
+ ### Current Implementation
112
+ - **Architecture**: Fully modular design with 6 specialized JavaScript modules
113
+ - **Benefits**: Better maintainability, testability, and performance
114
+ - **Design**: Clean separation of concerns with dependency injection
115
+ - **UI**: Professional emoji-free interface suitable for research
116
+
117
+ ### Modular Architecture
118
+
119
+ #### Module Structure
120
+ ```
121
+ static/js/
122
+ ├── modules/
123
+ │ ├── auth-manager.js - Authentication & permissions (95 lines)
124
+ │ ├── api-client.js - API communication (148 lines)
125
+ │ ├── ui-manager.js - User interface & messaging (192 lines)
126
+ │ ├── form-manager.js - Form handling & validation (285 lines)
127
+ │ ├── autocomplete-manager.js - Smart suggestions (322 lines)
128
+ │ └── media-manager.js - File uploads & recording (268 lines)
129
+ └── tree-track-app.js - Main orchestrator (206 lines)
130
+ ```
131
+
132
+ #### Module Dependencies
133
+ ```
134
+ TreeTrackApp
135
+ ├── AuthManager (independent)
136
+ ├── ApiClient (depends on AuthManager)
137
+ ├── UIManager (depends on AuthManager)
138
+ ├── FormManager (depends on ApiClient, UIManager)
139
+ ├── AutoCompleteManager (depends on ApiClient, UIManager)
140
+ └── MediaManager (depends on FormManager, UIManager)
141
+ ```
142
+
143
+ #### Key Improvements
144
+ - **Separation of Concerns**: Each module has single responsibility
145
+ - **Dependency Injection**: Clean dependencies between modules
146
+ - **ES6 Modules**: Modern import/export structure
147
+ - **Event Delegation**: Replaced global functions with proper event handling
148
+ - **Performance**: Debounced search, Promise.all(), DOM caching
149
+ - **Error Handling**: Centralized error management
150
+ - **Code Reuse**: Shared utilities across modules
151
+
152
+ ## TECHNOLOGY STACK
153
+
154
+ ### Backend
155
+ - **Framework**: FastAPI 0.115.0+
156
+ - **Server**: Uvicorn with standard extras
157
+ - **Database**: Supabase PostgreSQL (cloud-hosted)
158
+ - **Storage**: Supabase Storage for file uploads
159
+ - **Authentication**: Supabase Auth integration
160
+ - **File Handling**: aiofiles for async file operations
161
+ - **Validation**: Pydantic 2.10.0+ with custom validators
162
+ - **Configuration**: pydantic-settings for environment-based config
163
+
164
+ ### Frontend (Refactored)
165
+ - **JavaScript**: Modular ES6+ with 6 specialized modules
166
+ - **Architecture**: Dependency injection pattern
167
+ - **Performance**: Debounced search (300ms), parallel API calls
168
+ - **CSS**: Custom responsive design with Inter font (emoji-free)
169
+ - **PWA**: Service Worker for offline capabilities
170
+ - **Maps**: Interactive mapping with marker clustering
171
+ - **Media**: Camera integration and audio recording
172
+
173
+ ### Dependencies
174
+ ```
175
+ fastapi>=0.115.0
176
+ uvicorn[standard]>=0.32.0
177
+ python-multipart>=0.0.12
178
+ pydantic>=2.10.0
179
+ pydantic-settings>=2.6.0
180
+ pandas>=2.3.1
181
+ aiofiles>=24.1.0
182
+ GitPython>=3.1.40
183
+ huggingface-hub>=0.19.0
184
+ ```
185
+
186
+ ## DATA MODEL - 12 COMPREHENSIVE FIELDS
187
+
188
+ ### Core Tree Data Structure
189
+ 1. **Geolocation** (Required)
190
+ - Latitude: REAL (-90 to 90)
191
+ - Longitude: REAL (-180 to 180)
192
+
193
+ 2. **Identification**
194
+ - Local Name (Assamese): TEXT (max 200 chars)
195
+ - Scientific Name: TEXT (max 200 chars)
196
+ - Common Name: TEXT (max 200 chars)
197
+ - Tree Reference Code: TEXT (max 20 chars, e.g., "C.A", "A-G1")
198
+
199
+ 3. **Physical Measurements**
200
+ - Height: REAL (meters, 0-200)
201
+ - Width/Girth: REAL (cm, 0-2000)
202
+
203
+ 4. **Ecological & Cultural Data**
204
+ - Utility: JSON array of selected utilities
205
+ - Valid options: "Religious", "Timber", "Biodiversity", "Hydrological benefit", "Faunal interaction", "Food", "Medicine", "Shelter", "Cultural"
206
+
207
+ 5. **Phenology Assessment**
208
+ - Stages: JSON array of current development stages
209
+ - Valid options: "New leaves", "Old leaves", "Open flowers", "Fruiting", "Ripe fruit", "Recent fruit drop", "Other"
210
+
211
+ 6. **Documentation**
212
+ - Photographs: JSON object with categories and file paths
213
+ - Categories: "Leaf", "Bark", "Fruit", "Seed", "Flower", "Full tree"
214
+ - Storytelling Text: TEXT (max 5000 chars)
215
+ - Storytelling Audio: File path to audio recording
216
+
217
+ 7. **Field Notes**
218
+ - Notes: TEXT (max 2000 chars) for additional observations
219
+
220
+ ### System Fields
221
+ - ID: Auto-increment primary key
222
+ - Timestamp: Auto-generated creation time
223
+ - Created_by: Default 'system'
224
+ - Updated_at: Auto-updated modification time
225
+
226
+ ## SECURITY ARCHITECTURE
227
+
228
+ ### Multi-Layer Security
229
+ - **Input Validation**: Pydantic models with custom validators
230
+ - **SQL Injection Prevention**: Parameterized queries only
231
+ - **XSS Protection**: Content Security Policy headers
232
+ - **CORS**: Configured for specific origins
233
+ - **File Security**: Secure path validation, type checking
234
+ - **Rate Limiting**: Configurable request limits
235
+ - **Error Handling**: Comprehensive exception management
236
+
237
+ ### Production Security Settings
238
+ - Secret key validation (min 32 chars)
239
+ - Debug mode disabled
240
+ - Secure headers (X-Frame-Options, X-Content-Type-Options, etc.)
241
+ - Trusted host middleware available
242
+
243
+ ## CACHE MANAGEMENT SYSTEM
244
+
245
+ Deployment cache resolution (HF Spaces):
246
+ - Always bump the SW VERSION constant in static/sw.js after any frontend changes. This forces a new cache (treetrack-v{VERSION}) and invalidates old assets.
247
+ - Bump script query params if present (e.g., /static/js/tree-track-app.js?v=...).
248
+ - Dev/Spaces mode bypass: SW bypasses caching for /static/ when hostname includes localhost, 127.0.0.1, or hf.space.
249
+ - Manual steps: Unregister SW in DevTools 3e Application 3e Service Workers, then hard reload. For persistent issues, try incognito.
250
+ - API references: GET /api/version to view build; optional POST /api/version/update can be implemented for remote SW update signaling.
251
+
252
+ ### Current Issue: Aggressive Service Worker Caching
253
+ The app uses a Service Worker (`sw.js`) for PWA capabilities and offline support, but this causes caching issues during development.
254
+
255
+ ### Service Worker Configuration
256
+ - **Cache Name**: `treetrack-v{timestamp}` (dynamic versioning implemented)
257
+ - **Cached Resources**: HTML, JS, CSS, external fonts/libraries
258
+ - **Cache Strategy**: Cache-first for production, network-first for development
259
+ - **Development Mode Detection**: `isDevelopment = self.location.hostname === 'localhost' || '127.0.0.1'`
260
+
261
+ ### Cache Busting Solutions Implemented
262
+
263
+ #### 1. Dynamic Service Worker Versioning
264
+ ```javascript
265
+ const VERSION = new Date().getTime(); // Dynamic versioning
266
+ const CACHE_NAME = `treetrack-v${VERSION}`;
267
+ ```
268
+
269
+ #### 2. Development Mode Cache Bypass
270
+ ```javascript
271
+ if (isDevelopment && event.request.url.includes('/static/')) {
272
+ event.respondWith(
273
+ fetch(event.request, { cache: 'no-cache' })
274
+ );
275
+ }
276
+ ```
277
+
278
+ #### 3. Version Management API
279
+ - **GET /api/version**: Returns current version info
280
+ - **POST /api/version/update**: Forces version update and cache clear
281
+
282
+ #### 4. HTML Cache Busting
283
+ ```html
284
+ <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
285
+ <meta http-equiv="Pragma" content="no-cache">
286
+ <meta http-equiv="Expires" content="0">
287
+ <script src="/static/app.js?v=3.{timestamp}&t={timestamp}">
288
+ ```
289
+
290
+ #### 5. FastAPI Middleware
291
+ ```python
292
+ @app.middleware("http")
293
+ async def add_cache_headers(request: Request, call_next):
294
+ if request.url.path.startswith("/static/"):
295
+ response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
296
+ ```
297
+
298
+ ## FILE STRUCTURE (Current)
299
+
300
+ ```
301
+ TreeTrack/
302
+ ├── README.md # HF Spaces config + documentation
303
+ ├── Dockerfile # HF Spaces Docker configuration
304
+ ├── requirements.txt # Python dependencies
305
+ ├── llm.txt # LLM knowledge base (this file)
306
+ ├── app.py # Main FastAPI application
307
+ ├── config.py # Comprehensive configuration system
308
+ ├── constants.py # Application constants
309
+ ├── auth.py # Authentication system
310
+ ├── supabase_client.py # Supabase connection client
311
+ ├── supabase_database.py # Database operations
312
+ ├── supabase_storage.py # File storage operations
313
+ ├── master_tree_database.py # Tree species autocomplete
314
+ ├── .env.example # Environment variables template
315
+ ├── .gitattributes # Git configuration
316
+ ├── .gitignore # Git ignore patterns
317
+ ├── data/
318
+ │ └── master_trees.db # Local SQLite for tree species
319
+ └── static/
320
+ ├── css/
321
+ │ └── design-system.css # Professional design system
322
+ ├── index.html # Main application interface
323
+ ├── login.html # Login page
324
+ ├── map.html # Interactive map interface
325
+ ├── map.js # Map functionality
326
+ ├── sw.js # Service Worker for PWA
327
+ └── js/
328
+ ├── modules/
329
+ │ ├── auth-manager.js # Authentication module
330
+ │ ├── api-client.js # API communication module
331
+ │ ├── ui-manager.js # UI management module
332
+ │ ├── form-manager.js # Form handling module
333
+ │ ├── autocomplete-manager.js # Smart suggestions module
334
+ │ └── media-manager.js # Media handling module
335
+ └── tree-track-app.js # Main orchestrator
336
+ ```
337
+
338
+ ## API ENDPOINTS
339
+
340
+ ### Core Tree Management
341
+ - `GET /api/trees` - List trees with filtering/pagination
342
+ - `POST /api/trees` - Create new tree record
343
+ - `GET /api/trees/{id}` - Get specific tree
344
+ - `PUT /api/trees/{id}` - Update tree record
345
+ - `DELETE /api/trees/{id}` - Delete tree record
346
+
347
+ ### File Upload
348
+ - `POST /api/upload/image` - Upload categorized photos
349
+ - `POST /api/upload/audio` - Upload storytelling audio
350
+ - `GET /api/files/{type}/{filename}` - Serve uploaded files
351
+
352
+ ### Form Data Helpers
353
+ - `GET /api/utilities` - Valid utility options
354
+ - `GET /api/phenology-stages` - Valid phenology stages
355
+ - `GET /api/photo-categories` - Valid photo categories
356
+
357
+ ### System Management
358
+ - `GET /health` - Health check
359
+ - `GET /api/stats` - Comprehensive statistics
360
+ - `GET /api/version` - Current version info
361
+ - `POST /api/version/update` - Force cache clear
362
+ - `GET /api/persistence/status` - Database backup status
363
+ - `POST /api/persistence/backup` - Force database backup
364
+
365
+ ### Frontend Routes
366
+ - `GET /` - Main application (index.html)
367
+ - `GET /map` - Interactive map interface
368
+ - `GET /docs` - FastAPI auto-generated API documentation
369
+
370
+ ## CONFIGURATION SYSTEM
371
+
372
+ ### Environment-Based Settings (config.py)
373
+ - **DatabaseConfig**: SQLite settings, backup configuration
374
+ - **SecurityConfig**: Authentication, CORS, CSP, rate limiting
375
+ - **ServerConfig**: Host, port, workers, timeout settings
376
+ - **LoggingConfig**: File logging, rotation, access logs
377
+ - **CacheConfig**: TTL settings, cache sizes
378
+ - **MonitoringConfig**: Metrics, health checks, alerting
379
+ - **ApplicationConfig**: Feature flags, validation rules
380
+
381
+ ### Configuration Hierarchy
382
+ 1. Environment variables
383
+ 2. `.env` file
384
+ 3. Default values in config classes
385
+
386
+ ## COMMON ISSUES & SOLUTIONS
387
+
388
+ ### Cache Issues (PRIMARY ISSUE)
389
+ **Problem**: Service Worker aggressively caches static files
390
+ **Solutions**:
391
+ 1. Run `python clear_cache.py` to update all version files
392
+ 2. Manually clear Service Worker in DevTools > Application > Service Workers
393
+ 3. Use `Ctrl+Shift+R` for hard refresh
394
+ 4. Open in incognito/private mode for testing
395
+ 5. Use version API endpoints to force cache updates
396
+
397
+ ### Deployment to HF Spaces
398
+ **Remember**: This app runs on Hugging Face Spaces, not localhost
399
+ - Port must be 7860
400
+ - Use Docker deployment
401
+ - Non-root user for security
402
+ - Static files served through FastAPI
403
+
404
+ ### Development vs Production
405
+ - Development: Cache bypassing enabled
406
+ - Production: Full caching for performance
407
+ - Environment detection via hostname
408
+
409
+ ## CACHE BUSTING WORKFLOW
410
+
411
+ ### For Hugging Face Spaces Deployment (PRIMARY)
412
+ ```bash
413
+ # Run HF Spaces optimized cache manager
414
+ python hf_cache_manager.py
415
+ ```
416
+
417
+ ### For Local Development
418
+ ```bash
419
+ # Run comprehensive cache buster
420
+ python clear_cache.py
421
+
422
+ # Or use batch file on Windows
423
+ clear_cache.bat
424
+ ```
425
+
426
+ ### Manual Steps
427
+ 1. Update service worker version: `const VERSION = {timestamp}`
428
+ 2. Update HTML cache busting parameters
429
+ 3. Update version.json file
430
+ 4. Clear browser service worker
431
+ 5. Hard refresh browser
432
+ 6. Test in incognito mode
433
+
434
+ ### API-Based Solution
435
+ ```bash
436
+ # Update version via API (when server running)
437
+ curl -X POST http://localhost:7860/api/version/update
438
+
439
+ # Check current version
440
+ curl http://localhost:7860/api/version
441
+ ```
442
+
443
+ ## DEVELOPMENT GUIDELINES
444
+
445
+ ### Adding New Features
446
+ 1. Update Pydantic models in app.py
447
+ 2. Add API endpoints with proper validation
448
+ 3. Update frontend JavaScript
449
+ 4. Add appropriate tests
450
+ 5. Update cache version if static files change
451
+
452
+ ### Database Schema Changes
453
+ - Use SQLite migrations carefully
454
+ - Backup database before schema changes
455
+ - Update Pydantic models to match
456
+ - Test with existing data
457
+
458
+ ### Security Considerations
459
+ - Always validate input with Pydantic
460
+ - Use parameterized queries
461
+ - Implement rate limiting for public endpoints
462
+ - Regular security header updates
463
+ - Monitor for suspicious activity
464
+
465
+ ## CACHE VERSION HISTORY
466
+ - v3.0: Initial version with basic cache busting
467
+ - v3.{timestamp}: Dynamic versioning system
468
+ - Current: Automated cache management with API endpoints
469
+
470
+ ## TROUBLESHOOTING CHECKLIST
471
+
472
+ ### UI Not Updating
473
+ 1. Check if service worker is registered (DevTools > Application)
474
+ 2. Unregister service worker if present
475
+ 3. Hard refresh browser (Ctrl+Shift+R)
476
+ 4. Check Network tab for 304 (cached) responses
477
+ 5. Try incognito/private mode
478
+ 6. Run cache buster script
479
+ 7. Verify version.json timestamp is recent
480
+
481
+ ### Deployment Issues
482
+ 1. Verify Dockerfile uses port 7860
483
+ 2. Check requirements.txt is complete
484
+ 3. Ensure non-root user setup
485
+ 4. Verify static files are copied correctly
486
+ 5. Check HF Spaces logs for errors
487
+
488
+ ## CURRENT STATUS ENDPOINTS & DATA ACCESS
489
+
490
+ ### System Status URLs
491
+ - **Health Check**: https://royaalekh-treetrack.hf.space/health
492
+ - **API Stats**: https://royaalekh-treetrack.hf.space/api/stats
493
+ - **Version Info**: https://royaalekh-treetrack.hf.space/api/version
494
+ - **Tree Data**: https://royaalekh-treetrack.hf.space/api/trees
495
+
496
+ ### Interactive API Documentation
497
+ - **Swagger UI**: https://royaalekh-treetrack.hf.space/docs
498
+ - **ReDoc**: https://royaalekh-treetrack.hf.space/redoc
499
+
500
+ ## RECENT MAJOR UPDATES (Latest Commits)
501
+
502
+ ### Repository Cleanup (Latest)
503
+ - Removed development documentation files
504
+ - Cleaned up repository structure
505
+ - Preserved all core functionality
506
+ - Maintained Supabase integration files
507
+
508
+ ### Enhanced Map Pins (Recent)
509
+ - Beautiful tree-shaped SVG pins with 3D design
510
+ - Fixed popup modal overflow and layout issues
511
+ - Improved responsive design for mobile
512
+ - Enhanced close button functionality
513
+ - Better coordinate transfer from map to form
514
+
515
+ ### Modular Architecture (Version 3.0.0)
516
+ - Complete modular design with 6 specialized modules
517
+ - Professional emoji-free interface
518
+ - Enhanced button design with improved UX
519
+ - Better performance and maintainability
520
+
521
+ ## FILE LOCATIONS FOR SPECIFIC FUNCTIONALITY
522
+
523
+ ### Authentication & Users
524
+ - **Backend**: `auth.py` (user management and permissions)
525
+ - **Frontend**: `static/js/modules/auth-manager.js`
526
+ - **Login Page**: `static/login.html`
527
+
528
+ ### Database Operations
529
+ - **Main Database**: `supabase_database.py` (all CRUD operations)
530
+ - **Supabase Client**: `supabase_client.py` (connection and config)
531
+ - **Storage**: `supabase_storage.py` (file uploads)
532
+ - **Species Data**: `master_tree_database.py` (autocomplete)
533
+
534
+ ### Interactive Mapping
535
+ - **Map Logic**: `static/map.js` (all mapping functionality)
536
+ - **Map Interface**: `static/map.html` (map page UI)
537
+ - **Pin Design**: Look for SVG definitions in map.js
538
+ - **Popup Modals**: Enhanced popup content in map.js
539
+
540
+ ### Form Handling
541
+ - **Main Form**: `static/index.html` (12-field tree form)
542
+ - **Form Logic**: `static/js/modules/form-manager.js`
543
+ - **Validation**: Both client-side and server-side in app.py
544
+ - **Autocomplete**: `static/js/modules/autocomplete-manager.js`
545
+
546
+ ### File Uploads & Media
547
+ - **Media Handling**: `static/js/modules/media-manager.js`
548
+ - **Camera Integration**: Photo capture functionality
549
+ - **Audio Recording**: Voice memo functionality
550
+ - **File Processing**: Server-side in app.py upload endpoints
551
+
552
+ ### User Interface
553
+ - **UI Updates**: `static/js/modules/ui-manager.js`
554
+ - **Messages**: Success/error message system
555
+ - **Tree List**: Dynamic tree list rendering
556
+ - **Loading States**: Progress indicators and feedback
557
+
558
+ ## USAGE INSTRUCTIONS FOR LLMs
559
+
560
+ ### To Understand Project Structure:
561
+ 1. **Main Application Logic**: Review app.py for API endpoints and business logic
562
+ 2. **Frontend Architecture**: Check static/js/modules/ for modular components
563
+ 3. **Database Schema**: Look at Pydantic models in app.py and Supabase operations
564
+ 4. **Authentication Flow**: Review auth.py and auth-manager.js
565
+ 5. **Mapping Features**: Examine map.js for interactive map functionality
566
+
567
+ ### To Debug Specific Issues:
568
+ 1. **API Problems**: Test endpoints via /docs interface
569
+ 2. **Database Issues**: Check supabase_database.py operations
570
+ 3. **UI Problems**: Review browser console and specific module files
571
+ 4. **Authentication**: Check auth.py user configuration
572
+ 5. **Map Problems**: Look at map.js event handlers and pin creation
573
+
574
+ ### To Add New Features:
575
+ 1. **Backend**: Extend app.py with new FastAPI routes
576
+ 2. **Database**: Add operations to supabase_database.py
577
+ 3. **Frontend**: Extend appropriate JavaScript module
578
+ 4. **UI Changes**: Modify HTML files in static/
579
+ 5. **New Pages**: Add route in app.py and HTML file in static/
580
+
581
+ ### To Modify Existing Features:
582
+ 1. **Tree Data Model**: Update Pydantic models in app.py
583
+ 2. **Form Fields**: Modify index.html and form-manager.js
584
+ 3. **Map Functionality**: Update map.js and map.html
585
+ 4. **Authentication**: Modify auth.py and auth-manager.js
586
+ 5. **File Handling**: Update media-manager.js and storage operations
587
+
588
+ ## DEPLOYMENT STATUS & MONITORING
589
+
590
+ ### Current Deployment Status
591
+ - **Status**: LIVE and OPERATIONAL
592
+ - **Platform**: Hugging Face Spaces Docker
593
+ - **Build Status**: Automatic deployment from main branch
594
+ - **Health Monitoring**: Real-time via /health endpoint
595
+ - **Performance**: Monitored via Supabase dashboard
596
+
597
+ ### Key Metrics to Monitor
598
+ - **Response Time**: API endpoint performance
599
+ - **Database Load**: Supabase connection usage
600
+ - **Storage Usage**: File upload storage consumption
601
+ - **User Activity**: Authentication and session metrics
602
+ - **Error Rates**: Application error frequency
603
+
604
+ This comprehensive knowledge base reflects the current state of TreeTrack as of the latest updates and serves as the definitive guide for understanding the project's architecture, implementation, and operational status.
static/sw.js CHANGED
@@ -1,5 +1,5 @@
1
  // TreeTrack Service Worker - PWA and Offline Support
2
- const VERSION = 1754659000; // Cache busting bump - force clients to fetch new static assets and header image change
3
  const CACHE_NAME = `treetrack-v${VERSION}`;
4
  const STATIC_CACHE = `static-v${VERSION}`;
5
  const API_CACHE = `api-v${VERSION}`;
 
1
  // TreeTrack Service Worker - PWA and Offline Support
2
+ const VERSION = 1754662800; // Cache busting bump - force clients to fetch new static assets and header image change
3
  const CACHE_NAME = `treetrack-v${VERSION}`;
4
  const STATIC_CACHE = `static-v${VERSION}`;
5
  const API_CACHE = `api-v${VERSION}`;