Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e558f42
Initial commit
boubli Dec 9, 2025
ed90766
Fix line endings
boubli Dec 9, 2025
1959c6e
Update project files
boubli Dec 9, 2025
27cd7f3
Update admin and user components
boubli Dec 9, 2025
3baed09
Update project configuration and actions
boubli Dec 9, 2025
f34b918
feat: Remove USDA integration, implement secure API key system, clean…
boubli Dec 9, 2025
f64b2be
feat: Add VIP cinematic onboarding, fix firestore permissions, and im…
boubli Dec 9, 2025
95dbe7e
feat: content update
boubli Dec 9, 2025
8cac333
feat: Integrate reCAPTCHA v3 and persistent Special Welcome
boubli Dec 9, 2025
6032abc
feat: Add PWA support, dynamic icons, and copyright
boubli Dec 9, 2025
4dd7fd4
fix: Enhance PWA prompt for iOS and secure manifest configuration
boubli Dec 9, 2025
6340659
fix: Resolve build errors, enhance PWA persistence, and secure Firest…
boubli Dec 9, 2025
190e2e5
feat: Update PWA branding, Admin Chat names, and Notifications
boubli Dec 9, 2025
0ce8052
feat: Hide PWA prompt permanently after installation
boubli Dec 9, 2025
f2a8a00
fix: explicit iOS PWA install instructions
boubli Dec 9, 2025
e2b2cf3
fix: Robust iOS PWA support in manifest
boubli Dec 9, 2025
407222f
feat: Add Visual PWA Install Guide for iOS
boubli Dec 9, 2025
e9d0cce
chore: Update favicon, deploy rules, final polish
boubli Dec 9, 2025
fe24ddb
fix: Wrap adjacent JSX elements in Fragment
boubli Dec 9, 2025
3e1ddb0
fix: Resolve manifest TS error for icon purpose
boubli Dec 9, 2025
43f5d27
feat: Final PWA Push Notification Implementation
boubli Dec 9, 2025
ae1f22c
fix: Barcode scanner redirects to search results instead of broken pr…
boubli Dec 9, 2025
4f60704
feat: Final Scanner Polish (FooDB + Redirects)
boubli Dec 9, 2025
11dbea9
feat: Realtime User Presence & Chat Names Integration
boubli Dec 9, 2025
cab8afd
fix: Special Welcome Reliability (Delayed Mark-as-Seen)
boubli Dec 9, 2025
0ecfa21
fix(support): Robust Chat Deletion (Batching) & Admin Trash Button
boubli Dec 9, 2025
a05162f
fix(auth): Enforce strict admin redirection with replace
boubli Dec 9, 2025
98cf7cf
fix(admin): Use Server Action for Secure Admin Recovery
boubli Dec 9, 2025
0c76f50
fix(admin): Allow legacy recovery tokens (Emergency Bypass)
boubli Dec 9, 2025
7e02f48
feat: add active users graph to admin dashboard
boubli Dec 9, 2025
566a050
feat: implement web push notification system structure
boubli Dec 9, 2025
fc84bce
feat: integrate admin push notifications and frontend setup
boubli Dec 9, 2025
713313e
fix: ensure correct user tier fetching and saving in admin panel
boubli Dec 9, 2025
c8a96ff
feat: implement multi-lingual system with persistence and darija support
boubli Dec 9, 2025
f91bf3c
feat: comprehensive global translation support (ar_MA, fr, es, pt) - …
boubli Dec 9, 2025
bab0b98
fix: resolve build error in ChatWindow (timestamp -> createdAt)
boubli Dec 9, 2025
2ac5320
feat: deep localization updates and verified ar_MA translations
boubli Dec 9, 2025
eccb272
fix: added missing AiPreferenceOnboardingProps interface
boubli Dec 9, 2025
9834769
feat: localize scan page
boubli Dec 9, 2025
c734a84
refactor(i18n): remove Darija (ar_MA) support
boubli Dec 10, 2025
beccea0
Add Vercel Web Analytics to Next.js
vercel[bot] Dec 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 33 additions & 26 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
# Dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
.pnp.js

# Testing
/coverage

# next.js
# Next.js
/.next/
/out/

# production
# Production
/build

# misc
# Environment Variables
.env
.env.local
.env.production
.env.development
.env.test
.env*.local

# Firebase
.firebase/
firebase-debug.log
firebase-debug.log*

# Vercel
.vercel/

# System & Editor
.DS_Store
.vscode/
.idea/
*.pem

# debug
# TypeScript
*.tsbuildinfo

# Debug Logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*
pnpm-debug.log*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
# Local Security/Keys (Preserved from previous configuration)
certificates/
serviceAccountKey.json
48 changes: 48 additions & 0 deletions README-PUSH-NOTIFICATIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Web Push Implementation Guide

## 1. Generate VAPID Keys
To secure your push notifications, you need VAPID keys. Run this command in your terminal:

```bash
npx web-push generate-vapid-keys
```

This will output a **Public Key** and a **Private Key**.

## 2. Environment Variables
Add the following to your `.env.local` file (create it if it doesn't exist):

```properties
NEXT_PUBLIC_VAPID_PUBLIC_KEY="<your-generated-public-key>"
VAPID_PRIVATE_KEY="<your-generated-private-key>"
VAPID_SUBJECT="mailto:support@yourdomain.com"
```

## 3. Database Integration (Completed)
- **`app/api/notifications/subscribe/route.ts`**: Handles saving subscriptions to Firestore (`users/{userId}`).
- **`app/api/notifications/send-chat-push/route.ts`**: Handles retrieving subscriptions from Firestore.

## 4. Frontend Integration
You must add the `<PushNotificationSetup />` component to your **User Chat Page** or **Layout** so users can enable notifications.

Example (`app/chat/layout.tsx` or `app/chat/page.tsx`):
```tsx
import PushNotificationSetup from '@/components/PushNotificationSetup';
// ... inside your component
<PushNotificationSetup userId={currentUser.uid} />
```

## 4. Testing
1. Reload your application.
2. Click the new **"Enable Chat Notifications"** button (add `<PushNotificationSetup userId="current-user-id" />` to your chat page).
3. Check the console for "Subscribed!"
4. Test the push API manually (e.g., with Postman):

**POST** `http://localhost:3000/api/notifications/send-chat-push`
```json
{
"userId": "current-user-id",
"messageText": "Hello from the server!",
"senderName": "Test Bot"
}
```
82 changes: 59 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,72 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
# TruthLens 🔍🥗

## Getting Started
**TruthLens** is an advanced AI-powered nutrition assistant that helps you "see the truth" behind the food you eat.

First, run the development server:
Built as a modern Progressive Web App (PWA), it combines the power of **Google Gemini** and **Groq (Llama 3)** to instantly analyze food products, decode complex ingredient lists, and provide personalized health insights based on your specific dietary needs.

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
## 🌟 Key Features

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
### 🥗 Smart Food Analysis
* **Instant Grading**: Our proprietary **Smart Grade** algorithm evaluates products on a scale from **A (Excellent)** to **E (Avoid)** based on ingredients, processing levels, and nutritional value.
* **Ingredient Decoder**: Instantly identifies harmful additives, allergens, and hidden sugars in any product.
* **Barcode Scanning**: Quick access to millions of products via camera scan.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
### 🤖 Advanced AI Integration
* **Dual-AI Engine**: Leverages **Groq** for lightning-fast responses and **Gemini 1.5** for deep analytical reasoning.
* **Context-Aware Chat**: specialized `/ai-chat` for real-time nutrition advice and meal planning.
* **Dynamic Greetings**: A smart home screen that greets you with context-aware, witty messages depending on the time of day (e.g., "Scanning snacks at 3AM?").

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
### 💎 Flexible & Lifetime Access
* **Fair Pricing**: We offer both Monthly subscriptions and a unique **Lifetime Deal** for permanent access.
* **Tiered Features**:
* **Explorer (Free)**: Basic scanning and manual entry.
* **Pro**: Unlimited scans, detailed AI analysis, and Priority Support.
* **Ultimate**: All Pro features + Exclusive "Global Search" and Beta access.

## Learn More
### 🛠️ Powerful Admin Dashboard
* **Full Control**: A dedicated Admin Interface to manage Users, Subscription Tiers, and App Configurations in real-time.
* **Dynamic Logic**: Toggle features, enable maintenance mode, or adjust pricing instantly without redeploying.

To learn more about Next.js, take a look at the following resources:
## 🚀 Technical Stack

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
Built with cutting-edge web technologies for performance and scale:

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
* **Frontend**: Next.js 14 (App Router), TypeScript, Material UI (MUI).
* **Backend & Auth**: Firebase (Firestore, Authentication, Security Rules).
* **AI Services**: Groq SDK, Google Generative AI SDK (Gemini).
* **State Management**: React Context + Hooks.
* **Animations**: Framer Motion for buttery smooth UI transitions.
* **Styling**: Responsive Design supporting dark/light modes and mobile-first layouts.

## Deploy on Vercel
## 🛠️ Getting Started

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
1. **Clone the Repo**:
```bash
git clone https://github.com/yourusername/truthlens.git
cd truthlens
```

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
2. **Install Dependencies**:
```bash
npm install
```

3. **Environment Setup**:
Create a `.env.local` file with your keys:
```env
NEXT_PUBLIC_FIREBASE_API_KEY=...
NEXT_PUBLIC_GEMINI_API_KEY=...
NEXT_PUBLIC_GROQ_API_KEY=...
```

4. **Run Development Server**:
```bash
npm run dev
```

## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---
*Empowering healthier choices, one scan at a time.*
65 changes: 65 additions & 0 deletions actions/ai-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
'use server';

import { adminDb } from '@/lib/firebaseAdmin';
import Groq from 'groq-sdk';
import { GoogleGenerativeAI } from '@google/generative-ai';

// Helper to fetch keys securely from Firestore (Admin-only collection)
async function getSecureKeys() {
try {
if (!adminDb) {
console.warn('Admin SDK not initialized. Using env fallback.');
return {
groq: process.env.GROQ_API_KEY,
gemini: process.env.GEMINI_API_KEY
};
}

const doc = await adminDb.collection('_system_secrets').doc('ai_config').get();
if (!doc.exists) {
console.warn('System secrets not found. Using fallback env vars.');
return {
groq: process.env.GROQ_API_KEY,
gemini: process.env.GEMINI_API_KEY
};
}
const data = doc.data();
return {
groq: data?.groq || process.env.GROQ_API_KEY,
gemini: data?.gemini || process.env.GEMINI_API_KEY
};
} catch (error) {
console.error('Failed to fetch secure keys:', error);
return { groq: process.env.GROQ_API_KEY, gemini: process.env.GEMINI_API_KEY };
}
}

export async function generateAIResponse(prompt: string, provider: 'groq' | 'gemini' = 'groq') {
const keys = await getSecureKeys();

try {
if (provider === 'groq') {
if (!keys.groq) throw new Error('Groq API Key missing in _system_secrets');
const groq = new Groq({ apiKey: keys.groq });

const completion = await groq.chat.completions.create({
messages: [{ role: 'user', content: prompt }],
model: 'llama-3.3-70b-versatile',
temperature: 0.7,
});
return completion.choices[0]?.message?.content || 'No response';
}
else if (provider === 'gemini') {
if (!keys.gemini) throw new Error('Gemini API Key missing in _system_secrets');
const genAI = new GoogleGenerativeAI(keys.gemini);
const model = genAI.getGenerativeModel({ model: 'gemini-1.5-flash' });

const result = await model.generateContent(prompt);
return result.response.text();
}
} catch (error: any) {
console.error('AI Generation Error:', error);
return `Error: ${error.message}`;
}
return '';
}
Loading