Skip to content

Latest commit

ย 

History

History
328 lines (253 loc) ยท 9.59 KB

File metadata and controls

328 lines (253 loc) ยท 9.59 KB

Gone - Year Progress Tracker

A minimal web app that tracks the current year's progress and sends push notifications when each percent is completed. Built with React PWA frontend and Azure Functions serverless backend.

๐Ÿ“ฑ Installation

Install as a Progressive Web App (PWA) for the best experience:

Android (Brave/Chrome)

  1. Visit https://puneetk.dev in Brave or Chrome
  2. Tap the menu (โ‹ฎ) โ†’ "Add to Home screen" or "Install app"
  3. Tap "Install" or "Add"
  4. Open the app from your home screen
  5. Enable notifications when prompted

iOS (Safari)

  1. Visit https://puneetk.dev in Safari
  2. Tap the Share button (โ–กโ†‘)
  3. Scroll down and tap "Add to Home Screen"
  4. Tap "Add"
  5. Open the app from your home screen
  6. Enable notifications when prompted

Note: On iOS, notifications only work when the app is installed to the home screen (PWA mode), not in regular Safari.


๐ŸŽฏ Core Concept

Time passes irreversibly. This app tracks how much of the current year is already gone and notifies you only when another 1% is completed. No gamification, no social featuresโ€”just cold, factual awareness.

โœจ Features

  • Real-time Progress: View current year completion percentage
  • Smart Notifications: Get notified only when crossing whole percent thresholds
  • Timezone-Aware: Accurate calculations based on your timezone
  • Minimal Design: Black, white, greyโ€”nothing more
  • PWA: Works offline, installable on any device
  • Privacy-First: No tracking, no unnecessary data collection

๐Ÿ—๏ธ Architecture

Frontend

  • React + Vite: Fast, modern build tooling
  • Tailwind CSS: Minimal, utility-first styling
  • PWA: Service worker, offline support, installable
  • Web Push API: Native browser notifications

Backend

  • Azure Functions: Serverless, pay-per-execution
  • MongoDB Atlas: Free tier database (M0 cluster)
  • Web Push (VAPID): Push notification delivery
  • Node.js: Runtime environment

Functions

  1. Timer Trigger (checkYearProgress): Runs hourly, checks all users, sends notifications
  2. GET /api/progress: Returns current year progress for any timezone
  3. POST /api/subscribe: Registers push subscription
  4. PUT /api/settings: Updates user preferences (timezone, notifications)

๐Ÿ“ฆ Project Structure

gone/
โ”œโ”€โ”€ frontend/                # React PWA
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/      # React components
โ”‚   โ”‚   โ”œโ”€โ”€ services/        # API & push notification services
โ”‚   โ”‚   โ”œโ”€โ”€ utils/           # Helper functions
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx          # Main app component
โ”‚   โ”‚   โ””โ”€โ”€ main.jsx         # Entry point
โ”‚   โ”œโ”€โ”€ public/
โ”‚   โ”‚   โ””โ”€โ”€ icons/           # PWA icons
โ”‚   โ”œโ”€โ”€ vite.config.js       # Vite + PWA config
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ”œโ”€โ”€ backend/                 # Azure Functions
โ”‚   โ”œโ”€โ”€ checkYearProgress/   # Timer trigger function
โ”‚   โ”œโ”€โ”€ getCurrentProgress/  # HTTP: GET progress
โ”‚   โ”œโ”€โ”€ registerPushSubscription/  # HTTP: POST subscribe
โ”‚   โ”œโ”€โ”€ updateSettings/      # HTTP: PUT settings
โ”‚   โ”œโ”€โ”€ shared/              # Shared utilities
โ”‚   โ”‚   โ”œโ”€โ”€ database.js      # MongoDB connection
โ”‚   โ”‚   โ”œโ”€โ”€ yearProgress.js  # Progress calculations
โ”‚   โ”‚   โ””โ”€โ”€ pushService.js   # Push notifications
โ”‚   โ”œโ”€โ”€ host.json
โ”‚   โ””โ”€โ”€ package.json
โ”‚
โ””โ”€โ”€ .github/workflows/       # CI/CD
    โ””โ”€โ”€ deploy.yml

๐Ÿš€ Local Development

Prerequisites

  • Node.js 18+
  • Azure Functions Core Tools (v4)
  • MongoDB Atlas account (free tier)
  • VAPID keys for push notifications

1. Generate VAPID Keys

npx web-push generate-vapid-keys

Save the outputโ€”you'll need both public and private keys.

2. Setup MongoDB Atlas

  1. Create free M0 cluster at mongodb.com/cloud/atlas
  2. Create database user with read/write permissions
  3. Whitelist your IP address (or 0.0.0.0/0 for development)
  4. Get connection string (replace <password> with your password)

3. Backend Setup

cd backend
npm install

Create local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "node",
    "MONGODB_URI": "mongodb+srv://user:pass@cluster.mongodb.net/gone",
    "VAPID_PUBLIC_KEY": "YOUR_PUBLIC_KEY",
    "VAPID_PRIVATE_KEY": "YOUR_PRIVATE_KEY",
    "VAPID_SUBJECT": "mailto:your-email@example.com"
  }
}

Start backend:

npm start
# Backend runs on http://localhost:7071

4. Frontend Setup

cd frontend
npm install

Create .env:

VITE_API_BASE_URL=http://localhost:7071/api
VITE_VAPID_PUBLIC_KEY=YOUR_PUBLIC_KEY

Start frontend:

npm run dev
# Frontend runs on http://localhost:3000

๐ŸŒ Azure Deployment

1. Create Azure Resources

# Login to Azure
az login

# Create resource group
az group create --name gone-rg --location eastus

# Create Function App (Consumption plan)
az functionapp create \
  --resource-group gone-rg \
  --consumption-plan-location eastus \
  --runtime node \
  --runtime-version 18 \
  --functions-version 4 \
  --name gone-functions \
  --storage-account gonefunctionsstorage

# Create Static Web App
az staticwebapp create \
  --name gone-app \
  --resource-group gone-rg \
  --location eastus \
  --source https://github.com/YOUR_USERNAME/gone \
  --branch main \
  --app-location "/frontend" \
  --output-location "dist"

2. Configure Function App Environment Variables

az functionapp config appsettings set \
  --name gone-functions \
  --resource-group gone-rg \
  --settings \
    MONGODB_URI="your_mongodb_connection_string" \
    VAPID_PUBLIC_KEY="your_public_key" \
    VAPID_PRIVATE_KEY="your_private_key" \
    VAPID_SUBJECT="mailto:your-email@example.com"

3. Setup GitHub Secrets

Add these secrets to your GitHub repository (Settings > Secrets and variables > Actions):

  • AZURE_STATIC_WEB_APPS_API_TOKEN: From Static Web App deployment token
  • AZURE_FUNCTIONAPP_NAME: gone-functions
  • AZURE_FUNCTIONAPP_PUBLISH_PROFILE: Download from Azure Portal
  • VITE_API_BASE_URL: https://gone-functions.azurewebsites.net/api
  • VITE_VAPID_PUBLIC_KEY: Your VAPID public key

4. Deploy

Push to main branchโ€”GitHub Actions will automatically deploy both frontend and backend.

๐Ÿงช Testing

Test Year Progress Calculation

cd backend
node -e "
const { getYearProgressData } = require('./shared/yearProgress.js');
console.log(getYearProgressData('Asia/Kolkata', 2026));
"

Test Push Notification (Local)

Use a tool like Pushpad or curl to test the /api/subscribe endpoint.

Manual Testing Checklist

  • Landing page loads with correct copy
  • "Enable Notifications" requests permission
  • Permission granted โ†’ redirects to dashboard
  • Dashboard shows correct progress percentage
  • Progress bar fills to correct width
  • All metrics display correctly (days passed/remaining, next notification %)
  • Settings panel opens and closes
  • Timezone can be updated
  • Notifications can be toggled
  • PWA can be installed
  • App works offline
  • Notification arrives when threshold crossed (wait or test with modified backend)

๐Ÿ’ฐ Cost Estimation

Azure Functions (Consumption Plan)

  • ~3.65 million executions/year (1 user, hourly checks)
  • First 1M executions free
  • Cost: $0/month for <100 users

Azure Static Web Apps

  • Free tier: 100GB bandwidth, custom domains
  • Cost: $0/month

MongoDB Atlas

  • M0 cluster: 512MB storage, shared CPU
  • Cost: $0/month

Total: ~$0/month for MVP (scales affordably)

๐Ÿ” Security

  • CORS restricted to frontend domain only
  • Rate limiting recommended (Azure API Management)
  • VAPID keys stored in Azure Key Vault (production)
  • MongoDB connection uses TLS encryption
  • No PII collected beyond timezone and push subscription

๐Ÿ“Š Monitoring

  • Application Insights for Azure Functions (included)
  • Monitor notification delivery success rates
  • Track expired subscriptions cleanup
  • Alert on function failures

๐Ÿ› Troubleshooting

Notifications not working locally

  • Ensure HTTPS (use localhost or ngrok)
  • Check browser console for service worker errors
  • Verify VAPID keys match in frontend and backend
  • Test with browser's push notification tester

Timer trigger not firing

  • Check checkYearProgress/function.json cron expression
  • Verify function app is running (not stopped)
  • Check Application Insights for errors
  • Ensure MongoDB connection is valid

Progress calculation wrong

  • Verify timezone is valid IANA format
  • Check leap year logic (2024, 2028, etc.)
  • Test with known dates and timezones

๐Ÿค Contributing

This is a minimal, focused app. Contributions welcome for:

  • Bug fixes
  • Performance improvements
  • Security enhancements

Not accepting:

  • Gamification features
  • Social features
  • Motivational copy changes
  • Unnecessary complexity

๐Ÿ’ก Why This Exists

Got a random idea one day and decided to build it. Thought others might find it useful too.

๐Ÿ“„ License

MIT

Security update complete - Sat Mar 21 02:25:15 AM IST 2026

Trigger rebuild with GitHub secrets - Sat Mar 21 02:38:55 AM IST 2026