A React web application that tracks screen time on social media and entertainment apps, charges users based on usage, and automatically invests the money. Users can compete on a leaderboard and compare their progress with others.
- Screen Time Tracking: Monitor time spent on selected apps (Instagram, TikTok, YouTube, etc.)
- Automatic Charging: Β£2 per hour on tracked apps
- Auto-Investment: Money is automatically invested based on risk preference
- Leaderboard: Compete and compare with other users
- Investment Dashboard: Track portfolio performance and holdings
- Auth0 Integration: Secure Google OAuth authentication
- Frontend: React 18, Tailwind CSS, Recharts
- Backend: Python Flask, SQLAlchemy
- Database: PostgreSQL
- Authentication: Auth0
- Deployment: Docker, Docker Compose
- Node.js 18+ and npm
- Python 3.11+
- PostgreSQL 15+
- Docker and Docker Compose (for containerized deployment)
- Auth0 account (for authentication)
-
Clone the repository
git clone <repository-url> cd FYH-2025
-
Set up environment variables
cp env.example .env
Edit
.envand fill in your Auth0 credentials and database settings. -
Start with Docker Compose
docker-compose up -d
-
Initialize database
docker-compose exec backend python init_db.py -
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:5000
-
Navigate to backend directory
cd backend -
Create virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables Create a
.envfile in thebackenddirectory:DATABASE_URL=postgresql://postgres:postgres@localhost:5432/screen_time_db AUTH0_DOMAIN=your-auth0-domain.auth0.com AUTH0_CLIENT_ID=your-auth0-client-id AUTH0_CLIENT_SECRET=your-auth0-client-secret JWT_SECRET=your-secret-key FLASK_ENV=development
-
Initialize database
python init_db.py
-
Run the server
python app.py
-
Navigate to frontend directory
cd frontend -
Install dependencies
npm install
-
Set up environment variables Create a
.envfile in thefrontenddirectory:REACT_APP_API_URL=http://localhost:5000 REACT_APP_AUTH0_DOMAIN=your-auth0-domain.auth0.com REACT_APP_AUTH0_CLIENT_ID=your-auth0-client-id
-
Start development server
npm start
FYH-2025/
βββ backend/
β βββ app.py # Flask application
β βββ init_db.py # Database initialization and seeding
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend Docker image
β βββ migrations/ # Database migrations
βββ frontend/
β βββ src/
β β βββ pages/ # Page components
β β βββ components/ # Reusable components
β β βββ services/ # API services
β β βββ App.js # Main app component
β βββ public/
β βββ package.json
β βββ Dockerfile # Frontend Docker image
βββ docker-compose.yml # Docker Compose configuration
βββ .env.example # Environment variables template
βββ README.md
-
Create an Auth0 account at https://auth0.com
-
Create an Application
- Go to Applications β Create Application
- Choose "Single Page Web Application"
- Add
http://localhost:3000to Allowed Callback URLs - Add
http://localhost:3000to Allowed Logout URLs
-
Get your credentials
- Domain:
your-tenant.auth0.com - Client ID: Found in Application settings
- Client Secret: Not needed for SPA (but needed for backend if using API)
- Domain:
-
Update
.envfiles with your Auth0 credentials
user_id(Primary Key)name,email,pfptargeted_apps_time_weekly,amount_charged_weekly,total_investedleaderboard_position,investment_risk_leveltracked_apps(JSON array)created_at
history_id(Primary Key)user_id(Foreign Key)date,app_nametime_spent_hours,amount_charged
investment_id(Primary Key)user_id(Foreign Key)date,portfolio_value
The application comes pre-seeded with 3 dummy accounts:
- Sarah Chen - Medium risk, 28 hours/week
- Marcus Johnson - High risk, 42 hours/week (Leader)
- Emma Williams - Low risk, 21 hours/week
To re-seed the database:
docker-compose exec backend python init_db.py
# Or locally:
cd backend && python init_db.pyPOST /auth/login- Handle Auth0 callback
GET /user/profile- Get user profileGET /user/apps- Get tracked appsPUT /user/apps- Update tracked appsGET /user/apptime- Get app time historyPOST /user/apptime- Update app time data
GET /leaderboard- Get all leaderboard data
GET /investments/portfolio- Get portfolio dataPOST /investments/setup- Set risk levelGET /investments/history- Get investment history
GET /health- Health check endpoint
-
Install Vercel CLI
npm i -g vercel
-
Deploy
cd frontend vercel -
Set environment variables in Vercel dashboard
- Connect repository to Railway
- Set environment variables in Railway dashboard
- Deploy - Railway will auto-detect and deploy
- Use
render.yamlconfiguration - Connect repository to Render
- Set environment variables
- Deploy
-
Build Docker images
docker build -t screen-time-backend ./backend docker build -t screen-time-frontend ./frontend
-
Push to ECR (or use Docker Hub)
-
Deploy using ECS or run on EC2 with docker-compose
-
Install Heroku CLI
-
Create apps
heroku create screen-time-backend heroku create screen-time-frontend
-
Set environment variables
heroku config:set DATABASE_URL=... -a screen-time-backend
-
Deploy
git push heroku main
DATABASE_URL- PostgreSQL connection stringAUTH0_DOMAIN- Auth0 domainAUTH0_CLIENT_ID- Auth0 client IDAUTH0_CLIENT_SECRET- Auth0 client secretJWT_SECRET- Secret key for JWT tokensFLASK_ENV- Flask environment (development/production)PORT- Server port (default: 5000)
REACT_APP_API_URL- Backend API URLREACT_APP_AUTH0_DOMAIN- Auth0 domainREACT_APP_AUTH0_CLIENT_ID- Auth0 client ID
cd backend
pytest tests/cd frontend
npm test# Using Alembic
cd backend
flask db upgrade- Create feature branch
- Make changes
- Test locally
- Submit pull request
- Ensure PostgreSQL is running
- Check
DATABASE_URLin.env - Verify database exists:
createdb screen_time_db
- Verify callback URLs in Auth0 dashboard
- Check environment variables match Auth0 settings
- Ensure CORS is configured correctly
- Check logs:
docker-compose logs - Rebuild images:
docker-compose build --no-cache - Reset volumes:
docker-compose down -v
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
For issues and questions, please open an issue on GitHub.
Built with β€οΈ for FYH 2025