This web application helps users track and manage their sleep patterns. Users can record their sleep times, wake times, and monitor their sleep quality over time. The application provides insights into sleep habits and helps maintain a healthy sleep schedule.
- User registration and authentication
- Record sleep and wake times
- Track sleep duration
- View sleep history
- Basic sleep statistics
- PHP 8.1 or higher
- MySQL 5.7 or higher
- Composer
- Git
- Clone the repository
git clone [your-repository-url]
cd [project-directory]
- Install dependencies
composer install
- Configure your database
- Copy
config/.env.example
toconfig/.env
(If .env.example doesn't exist, create a new file named.env
in the config directory) - Update the database configuration in
config/.env
:
export DATABASE_HOST="localhost"
export DATABASE_USER="your_username"
export DATABASE_PASS="your_password"
export DATABASE_NAME="sleep_tracker"
- Set up the database
- Create a new MySQL database named 'sleep_tracker'
- Import the database structure from
config/schema/sleep_tracker.sql
(This file contains the initial database structure with the following tables:- users (id, email, password, firstname, lastname, created)
- sleep_records (id, user_id, sleep_time, wake_time, quality, notes, created))
- Start the development server
bin/cake server
The application should now be running at http://localhost:8765
- SleepRecordsController.php:
- Located in src/Controller/
- Handles CRUD operations for sleep records
- Manages sleep record validation
- Processes sleep statistics
- SleepRecord.php:
- Located in src/Model/Table/
- Defines relationships and validation rules
- Contains methods for calculating sleep metrics
- templates/SleepRecords/:
- index.php: Displays list of sleep records
- add.php: Form for adding new sleep records
- edit.php: Form for modifying existing records
- view.php: Detailed view of a single record
The application uses two main tables:
-
users
- id: Primary key
- email: User's email address
- password: Hashed password
- firstname: User's first name
- lastname: User's last name
- created: Account creation timestamp
-
sleep_records
- id: Primary key
- user_id: Foreign key to users table
- sleep_time: When the user went to sleep
- wake_time: When the user woke up
- quality: Sleep quality rating
- notes: Additional comments
- created: Record creation timestamp
- Log in to your account
- Click "Add Sleep Record" button
- Enter your sleep time and wake time
- Optionally add quality rating and notes
- Submit the form
- Navigate to the dashboard
- View your sleep patterns in the graphs
- Check weekly and monthly averages
- Export data if needed
- Verify database credentials in your
.env
file - Make sure your
.env
file is properly loaded (check if debug messages show DATABASE_* variables are set) - Ensure MySQL service is running
- Check if the database exists and is accessible
For Linux:
chmod -R 777 tmp/
chmod -R 777 logs/
For Windows:
- Right-click on the tmp/ and logs/ folders
- Properties -> Security -> Edit
- Give full control to the user running the web server
- Apply and OK
- Clear cache after configuration changes:
bin/cake cache clear_all
- If composer shows errors, try:
composer update --no-scripts
composer dump-autoload
-
"Database connection failed"
- Check credentials in .env file
- Verify MySQL is running
- Ensure database exists
-
"Permission denied"
- Check file permissions
- Verify web server user permissions
-
"Class not found"
- Run composer dump-autoload
- Clear CakePHP cache
- Follow PSR-12 coding standards
- Use CakePHP coding conventions
- Document all methods and classes
- Write unit tests for new features
- Create feature branch from main
- Make changes and test
- Submit pull request
- Wait for review and approval
Run tests using:
vendor/bin/phpunit
- Fork the repository
- Create your feature branch (git checkout -b feature/AmazingFeature)
- Commit your changes (git commit -m 'Add some AmazingFeature')
- Push to the branch (git push origin feature/AmazingFeature)
- Open a Pull Request
- All passwords are hashed using bcrypt
- SQL injection prevention through ORM
- XSS protection via form helper
- CSRF protection enabled
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please:
- Check the documentation
- Search existing issues
- Create a new issue if needed
- Contact the maintainers
- Built with CakePHP framework
- Uses Bootstrap for frontend
- Charts powered by Chart.js