# Goal Setting App — Prototype Design Specification

## 1. Purpose

Build a multi-user PHP and MySQL web application that helps people create, organize, break down, and complete:

- Personal life goals
- Startup goals
- Side-hustle business goals

The application should provide useful guidance without forcing users into a complicated goal-setting system.

This document is intended to contain enough detail for an AI developer to create a working prototype.

---

## 2. Technology

Use:

- PHP 8 or newer
- MySQL
- PDO with prepared statements
- HTML
- Basic CSS
- Plain JavaScript
- PHP sessions
- `password_hash()` and `password_verify()`

Do not use a large framework for the initial prototype.

---

## 3. Core Concepts

### Goals

A goal is something the user wants to accomplish.

Goals may be:

- Long-term
- Medium-term
- Short-term

These terms describe the expected time horizon, but the user may choose whichever term best represents the goal.

### Subgoals

A goal may have smaller goals underneath it.

Example:

```text
Build a profitable side business
├── Choose a business idea
├── Validate the idea
├── Create the first product
│   ├── Define the first version
│   ├── Build a prototype
│   └── Test the prototype
└── Make the first sale
```

Each goal may have:

- One parent goal
- Any number of subgoals
- Any number of action steps

### Action Steps

Action steps are smaller, practical activities that help complete a goal.

Examples:

- Call three potential customers
- Register a domain name
- Write the first product description
- Walk for 20 minutes
- Review the monthly budget

---

## 4. Goal Information

Each goal should support:

- Title
- Description
- Reason or motivation
- Long-, medium-, or short-term designation
- Parent goal
- User-defined category
- Target date
- Priority
- Status
- Progress percentage
- Completion description
- Notes
- Creation date
- Last updated date
- Completion date

Only the title should be required.

---

## 5. Goal Categories

Users may create and use any categories they want.

The application may suggest categories such as:

- Personal
- Health
- Family
- Financial
- Spiritual
- Education
- Career
- Startup
- Side hustle
- Business

These are suggestions only.

Users may:

- Ignore the suggestions
- Create their own categories
- Rename their categories
- Delete unused categories
- Use no category

A goal may have one category in the prototype.

---

## 6. Goal Status

Supported statuses:

- Not started
- In progress
- Paused
- Completed
- Cancelled

New goals default to `Not started`.

When a goal is completed:

- Set progress to 100%
- Record the completion date
- Keep the goal visible in history

---

## 7. Priority

Supported priorities:

- Low
- Normal
- High

New goals default to `Normal`.

---

## 8. Progress

Users may manually set progress from 0% to 100%.

The system may also calculate suggested progress based on completed subgoals.

Example:

- Four subgoals
- Two completed
- Suggested progress: 50%

The user remains able to override the suggested percentage.

Do not automatically change the user's saved progress without confirmation.

---

## 9. SMART Goal Guidance

The app should support SMART goals without creating separate required fields for:

- Specific
- Measurable
- Achievable
- Relevant
- Time-bound

The user enters the goal naturally.

The prototype should display simple suggestions based on the entered information.

Examples:

- If the description is empty:
  “Consider describing what you want to accomplish.”

- If there is no completion description:
  “How will you know this goal is complete?”

- If there is no target date:
  “Consider adding a target date.”

- If the goal has no subgoals:
  “Would breaking this goal into smaller goals make it easier?”

- If the title is vague, such as “Get healthier”:
  “Consider making the goal more specific or measurable.”

Users may ignore all suggestions.

The first prototype may use simple PHP rules. It does not require an AI service.

---

## 10. Guided Goal Setup

Provide a guided setup form containing these questions:

1. What do you want to accomplish?
2. Why is this important to you?
3. Is this a long-, medium-, or short-term goal?
4. How will you know when it is complete?
5. Do you have a target date?
6. What category would you use?
7. What smaller goals could help you complete it?
8. What is the next action you could take?

Only the first question is required.

The user should be able to:

- Skip optional questions
- Save at any point
- Edit the goal later
- Add subgoals after saving

---

## 11. Main Screens

### 11.1 Registration

Fields:

- Name
- Email
- Password
- Confirm password

Requirements:

- Email must be unique
- Password must be hashed
- Log the user in after successful registration

### 11.2 Login

Fields:

- Email
- Password

Include:

- Validation message for incorrect login
- Logout function

### 11.3 Dashboard

Display:

- Active goals
- High-priority goals
- Goals due soon
- Overdue goals
- Next actions
- Recently completed goals
- Button to create a goal
- Link to the full goal tree

### 11.4 Goal Tree

Display goals in a collapsible hierarchy.

Each goal should show:

- Title
- Term
- Status
- Progress
- Target date
- Priority

Provide controls to:

- Open the goal
- Add a subgoal
- Edit the goal
- Mark it completed

### 11.5 Goal Details

Display:

- Goal title
- Description
- Motivation
- Term
- Category
- Status
- Priority
- Progress
- Target date
- Completion description
- Parent goal
- Subgoals
- Action steps
- Notes
- SMART suggestions

Provide controls to:

- Edit the goal
- Add a subgoal
- Add an action
- Update progress
- Complete the goal
- Delete the goal

### 11.6 Create and Edit Goal

Fields:

- Title
- Description
- Motivation
- Term
- Parent goal
- Category
- Target date
- Priority
- Status
- Progress percentage
- Completion description

Allow creation of a new category directly from the form.

### 11.7 Weekly Review

Display:

- Goals completed during the last seven days
- Goals with progress changes
- Overdue goals
- Goals with no recent activity
- High-priority active goals
- Open action steps

Allow the user to update:

- Status
- Progress
- Priority
- Target date
- Next action

---

## 12. Business Goal Support

Goals may optionally be associated with a business or project.

A business project may contain:

- Project name
- Description
- Business stage
- Revenue target
- Customer target
- Launch date

Suggested business stages:

- Idea
- Research
- Validation
- Planning
- Building
- Launching
- Operating
- Growing

These stages are suggestions. The user may create their own stage name.

Business support should remain lightweight and should not turn the application into full project-management software.

---

## 13. Database Design

### users

```sql
CREATE TABLE users (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(150) NOT NULL,
    email VARCHAR(255) NOT NULL UNIQUE,
    password_hash VARCHAR(255) NOT NULL,
    status ENUM('active', 'disabled') NOT NULL DEFAULT 'active',
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    last_login_at DATETIME NULL
);
```

### categories

```sql
CREATE TABLE categories (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id BIGINT UNSIGNED NOT NULL,
    name VARCHAR(100) NOT NULL,
    sort_order INT NOT NULL DEFAULT 0,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY unique_user_category (user_id, name),
    CONSTRAINT fk_categories_user
        FOREIGN KEY (user_id) REFERENCES users(id)
        ON DELETE CASCADE
);
```

Suggested categories should be displayed by the application but should not be inserted into a user's category table until the user selects or creates one.

### business_projects

```sql
CREATE TABLE business_projects (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id BIGINT UNSIGNED NOT NULL,
    name VARCHAR(200) NOT NULL,
    description TEXT NULL,
    stage VARCHAR(100) NULL,
    revenue_target DECIMAL(12,2) NULL,
    customer_target INT NULL,
    launch_date DATE NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_business_projects_user
        FOREIGN KEY (user_id) REFERENCES users(id)
        ON DELETE CASCADE
);
```

### goals

```sql
CREATE TABLE goals (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id BIGINT UNSIGNED NOT NULL,
    parent_goal_id BIGINT UNSIGNED NULL,
    category_id BIGINT UNSIGNED NULL,
    business_project_id BIGINT UNSIGNED NULL,

    title VARCHAR(255) NOT NULL,
    description TEXT NULL,
    motivation TEXT NULL,
    completion_description TEXT NULL,

    goal_term ENUM('long', 'medium', 'short') NULL,
    priority ENUM('low', 'normal', 'high')
        NOT NULL DEFAULT 'normal',
    status ENUM(
        'not_started',
        'in_progress',
        'paused',
        'completed',
        'cancelled'
    ) NOT NULL DEFAULT 'not_started',

    progress_percent TINYINT UNSIGNED NOT NULL DEFAULT 0,
    target_date DATE NULL,
    completed_at DATETIME NULL,
    sort_order INT NOT NULL DEFAULT 0,

    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,

    CONSTRAINT fk_goals_user
        FOREIGN KEY (user_id) REFERENCES users(id)
        ON DELETE CASCADE,

    CONSTRAINT fk_goals_parent
        FOREIGN KEY (parent_goal_id) REFERENCES goals(id)
        ON DELETE SET NULL,

    CONSTRAINT fk_goals_category
        FOREIGN KEY (category_id) REFERENCES categories(id)
        ON DELETE SET NULL,

    CONSTRAINT fk_goals_business_project
        FOREIGN KEY (business_project_id)
        REFERENCES business_projects(id)
        ON DELETE SET NULL
);
```

Application validation must ensure `progress_percent` is between 0 and 100.

### goal_actions

```sql
CREATE TABLE goal_actions (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    goal_id BIGINT UNSIGNED NOT NULL,
    description VARCHAR(500) NOT NULL,
    status ENUM('open', 'completed', 'cancelled')
        NOT NULL DEFAULT 'open',
    due_date DATE NULL,
    sort_order INT NOT NULL DEFAULT 0,
    completed_at DATETIME NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_goal_actions_goal
        FOREIGN KEY (goal_id) REFERENCES goals(id)
        ON DELETE CASCADE
);
```

### goal_notes

```sql
CREATE TABLE goal_notes (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    goal_id BIGINT UNSIGNED NOT NULL,
    note TEXT NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    CONSTRAINT fk_goal_notes_goal
        FOREIGN KEY (goal_id) REFERENCES goals(id)
        ON DELETE CASCADE
);
```

### goal_history

```sql
CREATE TABLE goal_history (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    goal_id BIGINT UNSIGNED NOT NULL,
    user_id BIGINT UNSIGNED NOT NULL,
    change_type VARCHAR(100) NOT NULL,
    old_value TEXT NULL,
    new_value TEXT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT fk_goal_history_goal
        FOREIGN KEY (goal_id) REFERENCES goals(id)
        ON DELETE CASCADE,
    CONSTRAINT fk_goal_history_user
        FOREIGN KEY (user_id) REFERENCES users(id)
        ON DELETE CASCADE
);
```

---

## 14. Security and Ownership Rules

Every query involving user data must include the logged-in user's ID.

A user must never be able to:

- View another user's goals
- Edit another user's goals
- Delete another user's goals
- Assign another user's goal as a parent
- Use another user's category
- Use another user's business project

Use:

- PDO prepared statements
- Escaped HTML output
- CSRF tokens on forms
- Secure session cookies
- Server-side validation
- Ownership checks before all updates and deletes

---

## 15. Suggested PHP Structure

```text
/app
    /controllers
        AuthController.php
        DashboardController.php
        GoalController.php
        CategoryController.php
        ActionController.php
        ReviewController.php
        BusinessProjectController.php

    /models
        User.php
        Goal.php
        Category.php
        GoalAction.php
        GoalNote.php
        GoalHistory.php
        BusinessProject.php

    /services
        AuthService.php
        GoalTreeService.php
        SmartGoalService.php
        ProgressService.php

    /views
        /auth
        /dashboard
        /goals
        /categories
        /review
        /business

    /helpers
        auth.php
        csrf.php
        validation.php
        view.php

/config
    database.php
    app.php

/database
    schema.sql
    seed.sql

/public
    index.php
    /css
        app.css
    /js
        app.js

/storage
    /logs
```

---

## 16. Prototype Routing

The prototype may use a simple front controller.

Example routes:

```text
GET  /                         Dashboard
GET  /register                 Registration form
POST /register                 Create account
GET  /login                    Login form
POST /login                    Authenticate
POST /logout                   Logout

GET  /goals                    Goal tree
GET  /goals/create             Guided goal form
POST /goals/create             Save goal
GET  /goals/view?id=123        Goal details
GET  /goals/edit?id=123        Edit form
POST /goals/edit               Save changes
POST /goals/delete             Delete goal
POST /goals/complete           Complete goal

POST /categories/create        Create category

POST /actions/create           Add action
POST /actions/update           Update action
POST /actions/delete           Delete action

GET  /review                   Weekly review
```

---

## 17. Seed Data

After registration, show suggested categories but do not automatically save them.

Suggested category list:

```php
[
    'Personal',
    'Health',
    'Family',
    'Financial',
    'Spiritual',
    'Education',
    'Career',
    'Startup',
    'Side Hustle',
    'Business'
]
```

The prototype may also provide an optional sample goal:

```text
Goal:
Launch a small side business

Subgoals:
- Choose a business idea
- Talk to five potential customers
- Define the first product
- Create a prototype
- Make the first sale
```

---

## 18. Prototype Acceptance Criteria

The prototype is complete when a user can:

1. Register and log in.
2. Create a long-, medium-, or short-term goal.
3. Create a goal with only a title.
4. Add optional details later.
5. Create their own category.
6. Select a suggested category and save it as their own category.
7. Create subgoals under another goal.
8. View goals as a hierarchy.
9. Add action steps to a goal.
10. Change status, priority, dates, and progress.
11. Mark goals and actions completed.
12. View basic SMART suggestions.
13. View a dashboard of active goals and next actions.
14. Complete a weekly review.
15. Create an optional startup or side-hustle project.
16. Access only their own data.

---

## 19. AI Prototype-Building Instructions

Create a working prototype based on this specification.

Requirements:

- Generate all PHP, SQL, HTML, CSS, and JavaScript files.
- Use PHP 8+, MySQL, PDO, and prepared statements.
- Do not use Laravel, React, Vue, Node.js, or a build system.
- Keep the interface simple, clean, and functional.
- Use server-rendered pages.
- Use JavaScript only where it improves usability.
- Include a complete `schema.sql`.
- Include configuration instructions.
- Include sample data.
- Include registration, login, logout, and session handling.
- Enforce user ownership on every data operation.
- Support nested goals.
- Prevent a goal from becoming its own parent or descendant.
- Include basic CSRF protection.
- Escape all displayed user content.
- Add clear comments where prototype shortcuts are used.
- Create a README explaining installation and use.
- Make reasonable assumptions where this specification is incomplete.
