This is a project that demonstrate how to use Symfony to create a user login system
- Everything have been dockerized, no additional environment setting required
- Demonstrate how reverse proxy work using traefik
- Demonstrate how to use web interface to manage docker container using portainer
- Demonstrate how to use web interface to manage database using adminer
- Demonstrate how Symfony Guard component works
- Demonstrate how Doctrine custom annotation works
- Demonstrate how to use Redis to store session data
- Demonstrate how event listener handle the login event and redirect to correct landing page
- git clone to your local
- Make sure you have docker instead in your local machine
- I have
.envprovided in the repo - It's a bad practice but I guess it'll be alright for demo app. - Install composer packages by running command
docker-compose exec php composer install - Run the command to bring up docker containers using
docker-compose up, please keep this process running, or you can usedocker-compose up -dto run all the docker containers in detached mode- This will bring up several docker containers
- Reverse proxy container
- This container is using traefik as the reverse proxy to redirect traffic to correct docker container
- Web server container
- This container is using nginx as web server which could handle traffic to php-fpm
- PHP container
- This container is using php-fpm to execute the php code and give response to web server container
- Redis contrainer
- This container running redis service with alpine. you might want to use ElasticCache in production.
- Database container
- This is a container that runs MySQL database so Symfony can use it
- Database Management container
- This container is just simply an adminer that allow user to manage MySQL DB in web interface. Or you can choose your flavour of app to do it, usually I use DataGrip and Sequel Pro.
- For testing this project, you can use
db.mysqlas host androot/rootas credentials.
- Docker Management container
- This container uses portainer as the docker management web interface, you can use this web interface to see all the docker clusters/images/containers, and also see system resource usage, logs, etc.
- Reverse proxy container
- There is some handy urls that you can use
- Symfony App -
user-login.docker.localhost - Docker Management App -
portainer.docker.localhost - Database Management App -
adminer.docker.localhost
- Symfony App -
- If you are experiencing port conflicts, please shutdown your local service temporary.
- This will bring up several docker containers
- To run the database migration and apply user fixtures:
- make sure you are in the project root directory and have all the docker service running.
- run command
docker-compose exec php bin/console doctrine:migrations:migrateto apply the database migrations - run command
docker-compose exec php bin/console doctrine:fixture:loadto apply the user fixtures.
- To check the redis you can run the command
docker-compose exec cache.redis redis-cliorredis-commanderif you prefer web gui. You can usecache.redisas host.
| Username | Password | User type |
|---|---|---|
iamemployee |
superSecurePassword |
employee |
iamcontractor |
yetAnotherSecurePassword |
contractor |
- tests, a lot more tests needed to get decent tests coverage.
- firewall, currently employee will be redirect to
/employeepage, however they can still manually go to/contractpage by manually type url. This bit can be restricted given proper role and modifyseciruty.yml
- I'm using the
GuardAuthenticationListenerprovided by Symfony Guard component. - Annotation check is in the
UserServiceclass. .envfile includes credentials, i know it's bad practice but this project is purely for demo purpose so I just leave it there :)- I would use a lot more design patterns if it invloves complex business logic.
- I didn't demonstrate
gitby creating new branch/merge, etc. However I am confident for usinggit.