Skip to content

VI7V/FocusLayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 FocusLayer – Context-Aware Productivity & Behavior System

A cross-platform, gamified productivity system that tracks application usage, enforces adaptive restrictions, and helps users build lasting focus habits through behavioral intelligence.


πŸ“Œ Problem Statement

Modern knowledge workers lose 2.5+ hours daily to context switching, distraction loops, and unstructured app usage. Existing tools either spy too aggressively or nudge too gently. There is no system that:

  • Tracks what you do (not what you type)
  • Escalates restrictions intelligently based on behavior
  • Helps you understand why you get distracted
  • Gamifies discipline without being annoying

πŸ’‘ Proposed Solution

FocusLayer is a cross-device productivity OS layer that:

  1. Passively monitors app usage metadata (no content, no keystrokes)
  2. Detects distraction loops and context drift in real time
  3. Applies a 5-stage escalating restriction engine
  4. Provides a gamified habit + streak system
  5. Shows beautiful analytics to build self-awareness
  6. Optionally enables ethical employee monitoring (opt-in only)

✨ Features

Feature Description
πŸ” Activity Tracking Track app usage, idle time, switch frequency
🚫 Focus Mode Whitelist/blacklist apps with 5-stage escalation
πŸŒ€ Context Drift Detection Real-time distraction loop identification
πŸ† Habit System Create habits linked to actual usage data
πŸ“Š Analytics Dashboard Focus score, heatmaps, weekly reports
πŸ”„ Cross-Device Sync Real-time WebSocket sync between desktop + mobile
πŸ‘” Employee Mode Opt-in ethical monitoring with productivity scores
πŸ”” Smart Notifications Behavior-aware warning messages
πŸ”’ Privacy Controls Consent screen, data transparency, pause tracking

πŸ›  Tech Stack

Layer Technology
Frontend React 18 + TypeScript + Tailwind CSS
Desktop App Electron.js
Mobile App React Native (Android)
Backend Node.js + Express
Database PostgreSQL
Real-time Socket.io (WebSockets)
Auth JWT + bcrypt
ORM Prisma

πŸ“ Project Structure

focuslayer/
β”œβ”€β”€ docker-compose.yml     ← Run everything with one command
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── src/               # React + TypeScript web dashboard
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ Dockerfile
β”‚   β”œβ”€β”€ prisma/schema.prisma
β”‚   └── src/               # Node.js + Express API server
β”œβ”€β”€ electron/
β”‚   └── src/               # Desktop app wrapper + native tracking
β”œβ”€β”€ mobile/
β”‚   └── src/               # React Native Android app
└── docs/
    └── ARCHITECTURE.md    # Full system design documentation

🐳 Quickstart with Docker (Recommended)

This is the easiest way to run the full stack. You only need Docker Desktop installed β€” no Node.js, no PostgreSQL setup required.

Step 1 β€” Install Docker Desktop

Download from https://www.docker.com/products/docker-desktop and install it. Make sure it is running before continuing.

Step 2 β€” Unzip the project

unzip focuslayer-complete.zip
cd focuslayer

Step 3 β€” Start everything

docker compose up --build

That's it. Docker will automatically:

  • Pull and start a PostgreSQL database
  • Build and start the backend API (runs DB migrations automatically)
  • Build and start the frontend (served via nginx)

Step 4 β€” Open the app

Service URL
Web Dashboard http://localhost:5173
Backend API http://localhost:4000
API Health Check http://localhost:4000/health

Stopping the app

docker compose down

To also wipe the database and start completely fresh:

docker compose down -v

βš™οΈ Manual Installation (Without Docker)

Use this if you want to run each service individually for active development.

Prerequisites

  • Node.js >= 18
  • PostgreSQL >= 14 running locally, or a free cloud instance from https://neon.tech
  • Android Studio (for mobile only)

1. Unzip and enter the project

unzip focuslayer-complete.zip
cd focuslayer

2. Backend Setup

cd backend
npm install
cp .env.example .env

Open .env and fill in your values:

DATABASE_URL="postgresql://your_user:your_password@localhost:5432/focuslayer"
JWT_SECRET="any-long-random-string-you-choose"
PORT=4000
CLIENT_URL="http://localhost:5173"

Run migrations and start the server:

npx prisma migrate dev
npm run dev

API is now running at http://localhost:4000

3. Frontend Setup

cd ../frontend
npm install
cp .env.example .env
npm run dev

Dashboard is now at http://localhost:5173

4. Desktop App β€” Electron (optional)

cd ../electron
npm install
npm run dev

This opens the desktop window and begins tracking your active app windows in the background.

5. Mobile App β€” Android (optional)

cd ../mobile
npm install
npx react-native run-android

Requires Android Studio with an emulator running, or a physical Android device connected via USB with USB debugging enabled.


πŸš€ How to Use the App

  1. Sign Up β€” Create an account and read through the consent screen
  2. Enable Tracking β€” Toggle tracking on from the Privacy tab
  3. Set Focus Goals β€” Define a session length and add habits in the Habits tab
  4. Start a Session β€” Click "Start Session" in the Focus tab; FocusLayer monitors app usage in the background
  5. Get Nudged β€” Receive stage-based alerts when you drift from focused work
  6. Review Dashboard β€” See your focus score, hourly heatmap, and streaks
  7. Improve β€” Act on weekly insights and AI-generated habit suggestions

πŸ— System Architecture

See /docs/ARCHITECTURE.md for the full documentation including:

  • High-Level Architecture diagram
  • Low-Level Design (LLD)
  • ER Diagram
  • Data Flow Diagram (DFD)
  • Sequence Diagrams
  • Full REST API documentation
  • WebSocket event reference
  • Module-by-module explanations

πŸ”§ Common Issues

"Cannot connect to database" β†’ Make sure PostgreSQL is running. With Docker, just run docker compose up again.

"Port 4000 already in use" β†’ Set PORT=4001 in backend/.env and update VITE_API_URL=http://localhost:4001/api in frontend/.env.

"Prisma migration failed" β†’ Double-check that DATABASE_URL in .env points to an existing PostgreSQL server with the correct username and password.

Electron shows a blank screen β†’ Make sure the frontend dev server is running first (npm run dev inside /frontend), then launch Electron.

Android build fails β†’ Make sure ANDROID_HOME is set and an emulator is running. Run npx react-native doctor to diagnose issues.


πŸ“„ License

MIT License β€” Free for personal and educational use.

About

A context-aware productivity and behavior system that tracks app usage, detects distraction patterns, enforces adaptive restrictions, and helps build focus habits through gamified analytics.

Topics

Resources

Stars

Watchers

Forks

Contributors