Project 7 - Rest API built with Symfony Framework.
Mandatory :
PHP >= 8.0
Symfony CLI
openssl
(needed to generate keys for JWT authentication)
Optional :
Make
to use the Makefile and custom commandsDocker
andDocker-compose
for MySQL database and PhpMyAdmin containers
Unit Tests :
PHPUnit
-
To get this project on your local machine, simply clone this repository :
git clone [email protected]:OlivierFL/FlochOlivier_7_24042021.git
-
Install the dependencies :
composer install
-
Environment configuration :
To configure local dev environment, create a
.env.local
file at the root of the project.To configure database connection, override the
DATABASE_URL
env variable with your database credentials and database name, for example :DATABASE_URL="mysql://root:[email protected]:3306/bilemo?serverVersion=5.7"
If you're using the MySQL Docker container, the config is :
DATABASE_URL="mysql://root:[email protected]:3306/bilemo"
In the
.env
file, 2 variables are available, to configure the default number of products and users for pagination, and the directory for images uploads (default directory is/public/uploads
at the root of the project) :LIMIT=10 UPLOADS_DIRECTORY=/public/uploads
-
After configuring the database connection, run
bin/console doctrine:database:create
to create the database, thenbin/console doctrine:schema:create
to create database tables. -
Then run
bin/console doctrine:fixtures:load
to load the example data into the database. If you're using Docker, PhpMyAdmin is available onlocalhost:8080
(user :root
, password :admin
). -
Generate the SSL keys needed to handle the JWT authentication :
bin/console lexik:jwt:generate-keypair
. -
Start the Symfony server with
symfony server:start
.
The base url for the API is : localhost:8000/api
.
List of useful commands to use the project :
symfony server:start
to start the Symfony serversymfony server:stop
to stop the Symfony server
Commands to use with Docker and Make (commands are available in Makefile at the root of the project) :
make up
to start Docker stack (MySQL and PhpMyAdmin) and Symfony servermake install
to run installation process automatically (manual environment configuration is needed before running this command)make tests
to run PHPUnit testsmake down
to stop Docker stack (MySQL and PhpMyAdmin) and Symfony server
In order to have a fully functional API, the fixtures contains :
-
2 Company that can access the API :
-
a Company with Company username, and Company1234 password.
-
another Company with Company Test username, and 1234Company password.
-
-
A default list of Products (50 items). Each Product is related to a Brand (10 items).
-
A default list of Users (10 items). Each User is related to one of the two Company.
The documentation for the API is accessible at : localhost:8000/api/doc
.
The UML diagrams are available in /doc/uml
directory at the root of the project.
Packages and bundles used in this project :
- LexikJWTAuthenticationBundle to handle JWT authentication
- BazingaHateoasBundle to implement HATEOAS representations
- NelmioApiDocBundle to generate API documentation
- RollerWorks PasswordStrengthBundle
- KnpPaginatorBundle
This project uses Docker for MySQL database and PhpMyAdmin.
The stack is composed of 2 containers :
- mysql
- phpMyAdmin
The configuration is available in the docker-compose.yaml.
PhpUnit is used to run the tests.
In a terminal, at the root of the project, run vendor/bin/phpunit
or make tests
.
Links to code quality tools used for this project:
Codeclimate : https://codeclimate.com/github/OlivierFL/FlochOlivier_7_24042021
SonarCloud : https://sonarcloud.io/dashboard?id=OlivierFL_FlochOlivier_7_24042021