An open API service indexing awesome lists of open source software.

https://github.com/victormarlor/hyperfocus

Typed, test-driven FastAPI backend using SQLModel and SQLite to analyze user focus, interruptions, and time-based productivity metrics.
https://github.com/victormarlor/hyperfocus

analytics api-design async-python backend clean-architecture deep-work developer-tools docker fastapi focus-tracking productivity pydantic pytest python rest-api sqlite sqlmodel time-tracking

Last synced: 29 days ago
JSON representation

Typed, test-driven FastAPI backend using SQLModel and SQLite to analyze user focus, interruptions, and time-based productivity metrics.

Awesome Lists containing this project

README

          

![Tests](https://github.com/victormarlor/HyperFocus/actions/workflows/ci.yml/badge.svg)

# ๐Ÿง  HyperFocus
### Master Your Deep Work. Track Your Interruptions.

**HyperFocus** is not just another time tracker. It is a **Full-Stack Analytics Platform** designed for remote workers, developers, and students who want to understand the *science* behind their productivity.

We all feel busy, but are we **productive**? HyperFocus helps you answer that question by tracking your "Deep Work" sessions and analyzing exactly what breaks your flowโ€”whether it's a phone call, a family member, or your own wandering mind.

---

## ๐Ÿš€ Live Demo

Try the application live here: **[https://hyper-focus-six.vercel.app/](https://hyper-focus-six.vercel.app/)**

> [!WARNING]
> **Free Tier Limitations**:
> * **Cold Starts**: The backend is hosted on Render's free tier. If the API hasn't been used for a while, the first request may take **50+ seconds** to wake up. Please be patient! โณ
> * **Performance**: The database and server run on minimal resources (shared CPU/RAM). Heavy usage might cause slowness.
> * **Data Persistence**: While data is saved, this is a demo environment. Do not use for critical production data.

---

## โœจ Key Features

### ๐Ÿ›ก๏ธ Enterprise-Grade Security
* **Secure Authentication**: Built with **OAuth2** and **JWT** (JSON Web Tokens).
* **Data Protection**: Passwords hashed with **Argon2**, the winner of the Password Hashing Competition.
* **Role-Based Access**: Granular permissions for Users and Admins.

### โฑ๏ธ Seamless Focus Tracking
* **Focus Timer (Pomodoro)**: Built-in timer with presets (25m, 50m) and visual progress ring.
* **One-Click Sessions**: Start a "Deep Work" session instantly.
* **Frictionless Interruption Logging**: Log distractions in seconds without losing your context.

### ๐Ÿ“Š Professional Analytics Dashboard
* **AI Insights ๐Ÿง **: Local intelligence engine that analyzes your patterns to give personalized productivity tips.

* **Productivity Score**: A proprietary algorithm that scores your focus quality (0-100).
* **Interruption Breakdown**: Visual Pie Charts identifying your top distractors.
* **Peak Performance Hours**: Heatmaps showing *when* you are most productive.

### ๐ŸŽจ Premium User Experience
* **Modern UI**: Built with **React** and **Vite** for blazing fast performance.
* **Dark Mode Native**: Designed for late-night coding sessions with a custom-tuned dark palette.
* **Fully Responsive**: Works perfectly on your Desktop, Tablet, and Mobile.

---

## ๐Ÿ—๏ธ Tech Stack

This project was built using industry-standard best practices and modern technologies.

### Backend (The Brain)
* **Language**: Python 3.11+
* **Framework**: [FastAPI](https://fastapi.tiangolo.com/) (High performance, easy to learn)
* **Database**: SQLite (Dev) / PostgreSQL (Prod ready)
* **ORM**: [SQLModel](https://sqlmodel.tiangolo.com/) (The power of SQLAlchemy + Pydantic)
* **Testing**: Pytest, Factory Boy

### Frontend (The Face)
* **Framework**: [React](https://react.dev/) 18
* **Build Tool**: [Vite](https://vitejs.dev/)
* **State Management**: [Zustand](https://github.com/pmndrs/zustand) (Simple, scalable state)
* **Routing**: React Router v6
* **Visualization**: Recharts
* **Styling**: Modern CSS Variables & Responsive Design

### DevOps (The Engine)
* **Containerization**: Docker & Docker Compose
* **CI/CD**: GitHub Actions (Automated Testing & Linting)
* **Deployment**: Ready for Railway (Backend) & Vercel (Frontend)

---

## ๐Ÿš€ Replication Guide (How to Run This Project)

Want to run HyperFocus on your own machine? Follow these steps.

### Prerequisites
* **Docker** (Recommended) OR **Python 3.11+** & **Node.js 18+**
* **Git**

### Option A: The "I want it running NOW" Method (Docker) ๐Ÿณ

This will spin up the Backend, Frontend, and Database in isolated containers.

1. **Clone the Repository**
```bash
git clone https://github.com/victormarlor/HyperFocus.git
cd HyperFocus
```

2. **Launch with Docker Compose**
```bash
docker-compose up --build
```

3. **That's it!**
* **Frontend**: Open [http://localhost](http://localhost)
* **Backend API**: [http://localhost:8000](http://localhost:8000)
* **API Documentation**: [http://localhost:8000/docs](http://localhost:8000/docs)

---

### Option B: The "Hacker" Method (Manual Setup) ๐Ÿ’ป

If you want to develop or modify the code, run the services locally.

#### 1. Backend Setup

```bash
# Navigate to the project root
cd HyperFocus

# Create a virtual environment
python -m venv venv

# Activate it
# Windows:
.\venv\Scripts\Activate
# Mac/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the server
uvicorn app.main:app --reload
```
*The API is now running at `http://localhost:8000`*

#### 2. Frontend Setup

Open a new terminal window.

```bash
# Navigate to the frontend directory
cd frontend

# Install Node dependencies
npm install

# Start the development server
npm run dev
```
*The App is now running at `http://localhost:5173`*

---

## ๐Ÿงช Quality Assurance

We maintain high code quality standards. You can run our test suites to verify everything is working.

**Backend Tests:**
```bash
pytest
```

**Frontend Tests:**
```bash
cd frontend
npm test
```

---

## ๐Ÿ“‚ Project Structure

A detailed look at the architecture:

```
HyperFocus/
โ”œโ”€โ”€ .github/
โ”‚ โ””โ”€โ”€ workflows/
โ”‚ โ””โ”€โ”€ ci.yml # CI/CD Pipeline configuration
โ”œโ”€โ”€ app/ # FastAPI Backend Source
โ”‚ โ”œโ”€โ”€ core/
โ”‚ โ”‚ โ”œโ”€โ”€ config.py # Environment configuration
โ”‚ โ”‚ โ”œโ”€โ”€ deps.py # Dependency Injection
โ”‚ โ”‚ โ”œโ”€โ”€ logging_config.py # Logger setup
โ”‚ โ”‚ โ”œโ”€โ”€ security.py # JWT & Password hashing
โ”‚ โ”‚ โ””โ”€โ”€ stats_logic.py # Analytics business logic
โ”‚ โ”œโ”€โ”€ routers/
โ”‚ โ”‚ โ”œโ”€โ”€ auth.py # Authentication endpoints
โ”‚ โ”‚ โ”œโ”€โ”€ interruptions.py # Interruption management
โ”‚ โ”‚ โ”œโ”€โ”€ sessions.py # Session management
โ”‚ โ”‚ โ”œโ”€โ”€ stats.py # Statistics endpoints

โ”‚ โ”‚ โ””โ”€โ”€ users.py # User management
โ”‚ โ”œโ”€โ”€ db.py # Database connection
โ”‚ โ”œโ”€โ”€ main.py # App entry point
โ”‚ โ”œโ”€โ”€ models.py # SQLModel Database Models
โ”‚ โ””โ”€โ”€ schemas.py # Pydantic Data Schemas
โ”œโ”€โ”€ frontend/ # React Frontend Source
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ”œโ”€โ”€ api/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ axios.js # Axios instance with interceptors
โ”‚ โ”‚ โ”œโ”€โ”€ components/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ features/ # Feature Widgets (Timer, Insights)
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ layout/ # Layout & Sidebar components
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ ui/ # Reusable UI (Buttons, Inputs, Cards)
โ”‚ โ”‚ โ”œโ”€โ”€ pages/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ DashboardPage.jsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ LoginPage.jsx
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ RegisterPage.jsx
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ SessionsPage.jsx
โ”‚ โ”‚ โ”œโ”€โ”€ store/
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ authStore.js # Zustand Auth Store
โ”‚ โ”‚ โ”œโ”€โ”€ styles/
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ layout.css # Responsive Layout Styles
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ theme.css # CSS Variables & Dark Mode
โ”‚ โ”‚ โ”œโ”€โ”€ App.jsx # Main App Component & Routing
โ”‚ โ”‚ โ””โ”€โ”€ main.jsx # React Entry Point
โ”‚ โ”œโ”€โ”€ Dockerfile # Frontend Dockerfile (Nginx)
โ”‚ โ”œโ”€โ”€ package.json # Frontend Dependencies
โ”‚ โ””โ”€โ”€ vite.config.js # Vite Configuration
โ”œโ”€โ”€ tests/ # Backend Integration Tests
โ”‚ โ”œโ”€โ”€ conftest.py # Test Fixtures
โ”‚ โ”œโ”€โ”€ test_auth.py # Auth Tests
โ”‚ โ”œโ”€โ”€ test_interruptions_api.py
โ”‚ โ””โ”€โ”€ test_stats_logic.py
โ”œโ”€โ”€ .dockerignore # Docker exclusion list
โ”œโ”€โ”€ .gitignore # Git exclusion list
โ”œโ”€โ”€ docker-compose.yml # Docker Orchestration
โ”œโ”€โ”€ Dockerfile # Backend Dockerfile
โ”œโ”€โ”€ railway.toml # Railway Deployment Config
โ”œโ”€โ”€ requirements.txt # Backend Dependencies
โ””โ”€โ”€ README.md # Project Documentation
```

---

## ๐Ÿ”ฎ Future Roadmap

* [x] **Focus Timer**: Pomodoro integration directly in the session view.

* [x] **AI Insights**: Local heuristics engine to improve your workflow.
* [ ] **Mobile App**: Native React Native application.

---

## ๐Ÿ“„ License

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

---

*Built with โค๏ธ by Victormarlor*