samuelgfeller/slim-starter

Slim 4 starter with frontend and API endpoint

Fund package maintenance!
Ko Fi

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:project

1.0.0 2024-04-24 13:12 UTC

This package is auto-updated.

Last update: 2024-05-02 09:00:43 UTC


README

322212807-8e39b63f-adbf-443c-8ed9-dc5924fd4e0c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTQ2NDA3NDIsIm5iZiI6MTcxNDY0MDQ0MiwicGF0aCI6Ii8zMTc5NzIwNC8zMjIyMTI4MDctOGUzOWI2M2YtYWRiZi00NDNjLThlZDktZGM1OTI0ZmQ0ZTBjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA1MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNTAyVDA5MDA0MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWExYzAzNWJiZWNmZDQ3ZDE0MDI4NGE4ODUzMjY5MTJhZTExY2MwZjZhOGY5YTI1MjZlOGM5MmEzNThlYzFkN2UmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Uxy0skN6zSuEN_uKQAIKP21JMW0DSxUP3QEtDvDeZDk

Slim Starter

Latest Version on Packagist Code Coverage Build Status Quality Score Software License

Slim 4 full stack starter template to quickly get started with a scalable PHP web application following 2024 best practices and SOLID principles.

An extensive documentation explains the architecture, components, design choices (i.e. SRP) and features.
Libraries are kept to a minimum and to allow for most flexibility and long-term viability.

Features

The base for this project was the official Slim-Skeleton and Odan's slim4-skeleton but with a lot of additional opinionated features and examples such as:

  • Pages rendered by a template renderer with layout and versioned assets
  • The loading of elements from the database (users) via Ajax
  • The creation, modification, and deletion of users with validation
  • Extensive integration testing
  • An API endpoint
  • Dark / light theme switch

This skeleton template is a stripped-down version of the slim-example-project which contains a lot more features and examples.

Technologies

Requirements

  • PHP 8.2+
  • Composer
  • MariaDB or MySQL database

Installation

1. Create project

Navigate to the directory you want to create the project in and run the following command, replacing project-name with the desired name for your project.

composer create-project samuelgfeller/slim-starter project-name

This will create a new directory with the specified name and install all necessary dependencies.

2. Set up the database

Open the project in your IDE and rename the file config/env/env.example.php to config/env/env.php and add the local database credentials.

Then, create the database for the project and add the name to the config/env/env.dev.php file, like this:

$settings['db']['database'] = 'my_dev_database_name';

After that, create a separate database for testing and add the name to the config/env/env.test.php file.
The database name must contain the word "test" as a safety measure to prevent accidentally truncating the development database while testing.

$settings['db']['database'] = 'my_dev_database_name_test';

The Configuration documentation details the different configuration files and how they are used and loaded.

3. Run migrations

Open the terminal in the project's root directory and run the following command to create the demo table user:

composer migrate

4. Insert demo data

Four demo users can be inserted into the database to test the application and API response by running the following command:

composer seed

5. Update GitHub workflows

To run the project's tests automatically when pushing, update the .github/workflows/build.yml file.
Replace the matrix value "test-database" with the name of your test database as specified in config/env/env.test.php.

If you don't plan on using Scrutinizer, remove the .scrutinizer file at the root of the project, otherwise you can follow this guide on how to set it up.

Done!

That's it! Your project should now be fully set up and ready to use.
If you are using XAMPP and installed the project in the htdocs folder, you can access it in the browser at http://localhost/project-name.
Or you can serve it locally by running php -S localhost:8080 -t public/ in the project's root directory.

Support

Please read the Support❤️ page if you value this project and its documentation and want to support it.

License

This project is licensed under the MIT License — see the LICENSE file for details.