Aquagold Resistencias App Assistant
You are an expert assistant for the Aquagold Resistencias application, a Next.js app for managing shrimp resistance tests with Firebase and Microsoft OneDrive integration.
Project Architecture
Core Technologies
**Framework:** Next.js with TypeScript**Database:** Firebase Firestore (text data only)**Storage:** Microsoft OneDrive (Excel reports and photos)**Authentication:** Azure AD via MSAL**Reports:** Excel generation via exceljsDirectory Structure
`app/` — Next.js pages and layouts - `dashboard/` — Main dashboard for active tests
- `layout.tsx`, `page.tsx` — App shell and login flow
`lib/` — Service modules - `firebase.ts` — Firebase configuration
- `firestoreService.ts` — Firestore CRUD operations
- `graphService.ts` — OneDrive/Graph API integration
- `excelExport.ts` — Excel report generation logic
- `types.ts` — Shared TypeScript type definitions
- `utils.ts` — Utility functions
`components/` — React UI components (e.g., `SearchBar.tsx`, `DailyReportModal.tsx`)`public/` — Static assetsData Flow & Storage
Critical Storage Rules
**Firestore:** Stores resistance test records in `resistance_tests` collection (TEXT DATA ONLY)**OneDrive:** Stores ALL photos and Excel reports in `Aquagold_Resistencias/` folder**Firebase Storage:** NOT USED for photos (OneDrive only)**Photo URLs:** Stored in Firestore as references to OneDrive locationsAuthentication & Security
Azure AD authentication via MSALFirestore and Storage rules require authenticated accessCheck `.env.local` for required credentialsSee README for detailed security rulesDevelopment Guidelines
Naming Conventions
**Components:** PascalCase (`ResistanceTestList`, `DailyReportModal`)**Functions:** camelCase (`handleSubmit`, `createTest`)**Constants:** UPPER_SNAKE_CASE (`APP_ROOT_FOLDER`)**Types:** PascalCase (`ResistanceTest`, `TestSample`)**Files:** kebab-case (`firestore-service.ts`, `excel-export.ts`)Code Patterns
**Data flow:** UI components → lib/services → Firestore/OneDrive**Auto-save:** Real-time data persistence to Firestore**Excel generation:** Triggered on test completion or daily report request**Error handling:** Check permissions for Firestore, Storage, and OneDrive**State management:** React hooks and component stateLocal Development
```bash
Install dependencies
npm install
Run development server
npm run dev
Access at http://localhost:3000
Environment setup
Configure .env.local with:
- Firebase credentials
- Azure AD MSAL config
- OneDrive Graph API settings
```
Common Workflows
Creating a New Test
1. User initiates test creation from dashboard
2. Create Firestore record in `resistance_tests` collection
3. Create corresponding OneDrive folder in `Aquagold_Resistencias/`
4. Initialize sample data structure
5. Return test ID for further operations
Completing a Test
1. Validate all required fields are filled
2. Mark test status as completed in Firestore
3. Generate Excel report using `excelExport.ts`
4. Upload Excel report to OneDrive
5. Remove test from active dashboard
6. Maintain historical record in Firestore
Photo Upload Flow
1. User selects photo(s) from device
2. Upload ONLY to OneDrive (never Firebase Storage)
3. Get OneDrive sharing URL
4. Store URL reference in Firestore test record
5. Display photo in UI using OneDrive URL
Daily Report Generation
1. User triggers daily report from `DailyReportModal`
2. Query Firestore for tests in date range
3. Aggregate data from multiple tests
4. Generate consolidated Excel report
5. Save to OneDrive in designated reports folder
Integration Points
Firebase Integration
Configuration: `lib/firebase.ts`CRUD operations: `lib/firestoreService.ts`Collection: `resistance_tests`Authentication required for all operationsSee README for Firestore security rulesOneDrive Integration
API calls: `lib/graphService.ts`Excel export: `lib/excelExport.ts`Root folder: `Aquagold_Resistencias/`Requires Azure AD authenticationStores photos and Excel reportsAuthentication
Provider: Azure AD via MSALLogin flow: `app/page.tsx`Configuration: `.env.local`Required for both Firebase and OneDrive accessTroubleshooting
Permission Errors
Verify Firestore security rules allow authenticated reads/writesCheck Azure AD app registration and permissionsEnsure MSAL configuration in `.env.local` is correctValidate OneDrive Graph API permissionsExcel/Report Issues
Confirm all required test fields are populatedCheck OneDrive folder structure existsVerify Excel export dependencies are installedReview `excelExport.ts` for generation errorsPhoto Upload Issues
Ensure Azure AD token has OneDrive write permissionsCheck OneDrive storage quotaVerify folder path exists in `Aquagold_Resistencias/`Never attempt to use Firebase Storage for photosReal-time Data Issues
Check Firestore connection statusVerify auto-save listeners are attachedMonitor browser console for Firestore errorsEnsure authenticated session is activeImportant Constraints
1. **NEVER** store photos in Firebase Storage — use OneDrive only
2. **ALWAYS** store text data in Firestore, binary data in OneDrive
3. **REQUIRE** authentication for all Firebase and OneDrive operations
4. **VALIDATE** all test data before generating Excel reports
5. **MAINTAIN** real-time auto-save for data entry
6. **FOLLOW** the established naming conventions strictly
7. **CHECK** README.md for environment setup and security rules
Testing & Debugging
No explicit test runner configured in projectAdd tests in `app/dashboard/tests/` if neededUse browser console for client-side debuggingCheck Firestore console for data validationMonitor OneDrive folder structure for file uploadsReview Network tab for API call failures---
**For complete setup instructions, environment variables, and security rules, refer to the project's README.md file.**