# Findagram Development Notes ## Overview Findagram (findagram.co) is a consumer-facing cannabis product discovery app. Users can search products across dispensaries, set price alerts, and save favorites. ## Architecture - **Frontend**: React (Create React App) at `findagram/frontend/` - **Backend**: Shared CannaiQ Express API at `backend/` - **Auth**: JWT-based consumer auth via `/api/consumer/auth/*` - **Domain**: `findagram.co` (passed in all auth requests) ## Key Files | File | Purpose | |------|---------| | `src/context/AuthContext.js` | Global auth state, login/register, token management | | `src/components/findagram/AuthModal.jsx` | Login/signup modal popup | | `src/api/client.js` | API client for products, dispensaries, categories, brands | | `src/api/consumer.js` | API client for favorites, alerts, saved searches (auth required) | ## Backend Consumer API Endpoints All require JWT token in `Authorization: Bearer ` header. ### Auth (`/api/consumer/auth/*`) - `POST /register` - Create account (requires `domain: 'findagram.co'`) - `POST /login` - Login (requires `domain: 'findagram.co'`) - `GET /me` - Get current user - `PUT /me` - Update profile ### Favorites (`/api/consumer/favorites/*`) - `GET /` - Get user's favorites - `POST /` - Add favorite (`{ productId, dispensaryId? }`) - `DELETE /:id` - Remove by favorite ID - `DELETE /product/:productId` - Remove by product ID - `GET /check/product/:id` - Check if product is favorited ### Alerts (`/api/consumer/alerts/*`) - `GET /` - Get user's alerts - `POST /` - Create alert (`{ alertType, productId, targetPrice }`) - Alert types: `price_drop`, `back_in_stock`, `product_on_special` - `PUT /:id` - Update alert - `DELETE /:id` - Delete alert - `POST /:id/toggle` - Toggle active status ### Saved Searches (`/api/consumer/saved-searches/*`) - `GET /` - Get user's saved searches - `POST /` - Create saved search - `PUT /:id` - Update - `DELETE /:id` - Delete - `POST /:id/run` - Get search params for execution ## Database Tables (Consumer) | Table | Purpose | |-------|---------| | `users` | User accounts (shared across domains via `domain` column) | | `findagram_users` | Findagram-specific user profile data | | `findagram_favorites` | Product favorites | | `findagram_alerts` | Price/stock alerts | | `findagram_saved_searches` | Saved search filters | ## Auth Flow 1. User clicks favorite/alert on a product 2. If not logged in → AuthModal opens 3. User logs in or creates account 4. JWT token stored in localStorage (`findagram_auth`) 5. Pending action (favorite/alert) executes automatically after auth 6. All subsequent API calls include `Authorization: Bearer ` ## Environment Variables ```bash # Frontend (.env) REACT_APP_API_URL=http://localhost:3010 # Local REACT_APP_API_URL=https://cannaiq.co # Production ``` ## Future: Migration to cannabrands.app Currently uses CannaiQ backend. Later will migrate auth to cannabrands.app: - Update `API_BASE_URL` for auth endpoints - Keep product/dispensary API pointing to CannaiQ - May need to sync user accounts between systems ## Important Notes 1. **Domain is critical** - All auth requests must include `domain: 'findagram.co'` 2. **Favorites are product-based** (unlike findadispo which is dispensary-based) 3. **Price alerts** require `targetPrice` for `price_drop` type 4. **Mock data** in `src/mockData.js` is no longer imported - can be safely deleted 5. **Token expiry** is 30 days (`JWT_EXPIRES_IN` in backend) ## Pages Using Real API All pages are now wired to the real CannaiQ API: | Page | API Endpoint | Notes | |------|--------------|-------| | Home | `/api/products`, `/api/dispensaries` | Featured products, deals | | Products | `/api/products` | Search, filters, pagination | | ProductDetail | `/api/products/:id` | Single product with dispensaries | | Deals | `/api/products?hasSpecial=true` | Products on sale | | Brands | `/api/brands` | Brand listing | | BrandDetail | `/api/brands/:name` | Brand products | | Categories | `/api/categories` | Category listing | | CategoryDetail | `/api/products?category=...` | Category products | | Dashboard | `/api/consumer/favorites`, alerts, searches | User dashboard (auth) | | Favorites | `/api/consumer/favorites` | User favorites (auth) | | Alerts | `/api/consumer/alerts` | Price alerts (auth) | | SavedSearches | `/api/consumer/saved-searches` | Saved searches (auth) |