A modern, full-stack web application for tracking daily sugar intake, discovering healthier alternatives, and building healthier habits through community challenges and achievements.
- User Authentication: Secure signup/login with JWT tokens
- Sugar Tracking: Log food items with barcode scanning capability
- Onboarding Quiz: Personalized setup based on health goals
- Dashboard: Real-time sugar intake tracking with progress visualization
- Barcode Scanner: Scan product barcodes to quickly log items
- Smart Swaps: Discover healthier alternatives to high-sugar foods
- Community Challenges: Join challenges and compete with other users
- Achievement Badges: Earn badges for reaching milestones
- Community Feed: See other users' progress and celebrate together
- Frontend: Next.js 16 (App Router), React 19, TypeScript
- Styling: Tailwind CSS v4, shadcn/ui components
- Backend: Next.js API Routes
- Database: PostgreSQL (Neon)
- Authentication: JWT-based auth with localStorage persistence
- Deployment: Vercel
- Node.js 18+
- npm or yarn
- Neon PostgreSQL database
- Vercel account (for deployment)
-
Clone the repository: ```bash git clone cd sweetfree ```
-
Install dependencies: ```bash npm install ```
-
Set up environment variables in your Vercel project:
DATABASE_URL- Your Neon PostgreSQL connection stringJWT_SECRET- Secret key for JWT signing (use a strong random string)
-
Run database migration to set up tables: ```bash npm run db:migrate ```
-
Start development server: ```bash npm run dev ```
The database schema includes tables for:
users- User accounts and authenticationentries- Daily food logs with sugar contentplans- User preferences and targetschallenges- Community challengeschallenge_members- User participation in challengesbadges- Achievement badgesuser_badges- User's earned badges
Run the migration script to initialize: ```bash npm run db:migrate ```
``` ├── app/ │ ├── api/ # API routes │ │ ├── auth/ # Authentication endpoints │ │ ├── entries/ # Food entry endpoints │ │ ├── swaps/ # Sugar swaps endpoints │ │ ├── challenges/ # Challenge endpoints │ │ └── user-badges/ # Badge endpoints │ ├── (pages)/ # Application pages │ │ ├── page.tsx # Landing page │ │ ├── signup/ # Sign up │ │ ├── login/ # Sign in │ │ ├── onboarding/ # Onboarding quiz │ │ ├── dashboard/ # Main dashboard │ │ ├── profile/ # User profile │ │ └── swaps/ # Swaps & challenges │ └── layout.tsx # Root layout ├── components/ │ ├── ui/ # shadcn/ui components │ ├── auth-provider.tsx # Auth context provider │ ├── protected-route.tsx # Route protection wrapper │ └── ... # Feature components ├── lib/ │ ├── auth-context.ts # Auth context definition │ ├── jwt.ts # JWT utilities │ ├── password.ts # Password hashing │ └── utils.ts # Utility functions ├── scripts/ │ ├── 01-init-schema.sql # Database schema │ ├── 02-seed-data.sql # Initial seed data │ └── ... # Migration scripts └── public/ # Static assets ```
POST /api/auth/signup- Create new user accountPOST /api/auth/login- User loginPOST /api/auth/verify- Verify JWT token
POST /api/entries/create- Log a food entryGET /api/entries/list- Get user's entriesGET /api/entries/daily-summary- Get daily stats
GET /api/swaps/list- Get available sugar swapsGET /api/challenges/list- Get active challengesPOST /api/challenges/join- Join a challenge
GET /api/user-badges/list- Get user's earned badgesGET /api/community-feed- Get community activity
-
Push your code to GitHub: ```bash git push origin main ```
-
Import project in Vercel dashboard
-
Add environment variables:
DATABASE_URLJWT_SECRET
-
Deploy
The app will be live at https://your-project.vercel.app
```bash
npm run db:migrate
npm run db:seed
npm run dev
npm run build
npm start ```
- Create API routes in
app/api/ - Add components in
components/ - Create pages in
app/ - Protect routes using
ProtectedRoutecomponent
- User signs up with email/password
- Password is hashed with SHA-256
- JWT token generated and stored in localStorage
- Token included in Authorization header for API requests
- Token verified server-side using JWT_SECRET
- Auto-redirect to login if token invalid/expired
- React Compiler enabled for automatic memoization
- Next.js Image Optimization
- CSS-in-JS with Tailwind CSS v4
- Component-level caching
- Efficient database queries with indexes
- Token-based stateless authentication
- JWT-based authentication with 7-day expiration
- Password hashing with SHA-256
- CORS headers for API protection
- SQL parameterized queries to prevent injection
- Environment variables for secrets
- HttpOnly cookies recommended for production
- Chrome/Edge 90+
- Firefox 88+
- Safari 14+
- Mobile browsers (iOS Safari, Chrome Mobile)
MIT License - see LICENSE file for details
For issues or questions:
- Check the GitHub issues
- Review API documentation
- Check deployment logs on Vercel
Pull requests welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
- OAuth integration (Google, Apple)
- Mobile app (React Native)
- Advanced analytics dashboard
- Nutrition tracking beyond sugar
- Integration with fitness apps
- AI-powered meal recommendations
- Recipe generation
- Export data features ```
```json file="" isHidden