# OTIS Life System - System Documentation

## 1. System Structure
OTIS is a custom PHP MVC framework structured hierarchically by modules.

### Directories:
- `/app/Modules/`: Contains isolated features. Each module has `Controllers`, `Models`, and `Views`.
- `/core/`: Base engine classes (`Router.php`, `Controller.php`, `Model.php`, `Database.php`).
- `/config/`: Configuration files (e.g., `database.php`).
- `/helpers/`: Global helper functions (`functions.php`, `security.php`).
- `/assets/`: Public static files (CSS, JS).
- `/system_docs/`: System documentation (auto-updated).

## 2. Modules Overview
- **CoreModule**: Handles the routing to the home dashboard.
- **Auth**: Manages user authentication, sessions, and secure login workflows.
- **Health**: Tracks vitals, water, fasting, generic labs, and blood sugar measurements in a deeply interconnected tracker.
- **Finance**: Financial tracking including incomes, expenses, installments, and investments.
- **Calendar**: A centralized calendar that pulls global events and upcoming tracking events.
- **Todo**: Advanced Task Management (To-Do) system featuring Priority, Daily Focus, and drag-drop logic.
- **Education (Edu & Skills)**: Tracks Academic degrees, completed courses, and levels-up technical user Skills using XP.
- **Advisor**: An AI-driven inference engine integrated into the Education module to analyze user progress and recommend next steps.
- **System**: Handles logs, application-wide user notifications, and user system settings/profile.

## 3. Database Architecture
The application uses MySQL (managed via PDO) with strict normalization, Foreign Keys, and cascading logic.
*Key Tables:* `users`, `health_profile`, `health_blood_sugar`, `health_fasts`, `finance_expenses`, `todo_tasks`, `edu_skills`, `edu_courses`.

## 4. Special Logic & Integrations
- **Auth Middleware**: All modules enforce active user sessions (except Auth login/register routes).
- **Skill Leveling via XP**: Completing Courses or Todo Tasks directly affects the user's Skill Level in the Edu module.
- **Soft Deletion**: All data deletion relies on timestamps (`deleted_at`) to preserve global integrity.
- **CSRF & Security**: Forms are strictly protected against Cross-Site Request Forgery via tokens. Input paths are sanitized.

*(This file is automatically updated via the Agent upon systemic modifications)*
