This is a web app that uses docker with custom php framework api, mysql, redis and nginx. For front-end it uses angular.
Run the following commands to build.
docker compose build
docker compose up
Make PHP api work :
docker compose exec api composer install
Api will be served at : http://localhost:9000/subscribers
To make angular app work
cd app
npm install
npm start
It will be served at http://localhost:4200
Database should already be synced on docker build. However, if needed, the SQL file is inside :
docker/mysql/db.sql
GET : http://localhost:9000/subscribers
GET : http://localhost:9000/subscribers/{emailId}
POST : http://localhost:9000/subscribers
BODY :
{
"firstName": "hello",
"lastName": "world",
"email": "hello@example.com",
"status": 1
}
This task is divided into 3 folders.
**api** - Contains PHP code
**app** - Contains angular code.
**docker** - Contains docker configurations.
This is a simple implementation for the task. It follows PSR-2 coding standards. I have also made sure that it is setup with PHPCS (https://github.com/squizlabs/PHP_CodeSniffer).
docker compose exec api sniff
docker compose exec api fix
To test the application :
docker compose exec api composer test
You can also seed users :
docker compose exec api composer seed
It implements Redis as primary database. Data is always fetched from Redis, if it is not found, it is queried to MySQL and saved to Redis.
Configuration :
REDIS_PORT: 6379
Can be connected using 127.0.0.1:6379
Read Operations :
=> Does data exist in Redis ?
=> Yes ? Return data from Redis
=> No ? Fetch from MySql, Save into Redis, Return Data
=> Next time, deliver from redis
For write operations:
=> Write into Redis
=> Send Response To User
=> Write to MYSQL in the background
It implements MySQL as a secondary database. Can be accessed externally by :
Host : 127.0.0.1
Port : 3307
username: root
password: root
And that is it.