Table of Contents
This is a system that allows users to manage IP addresses by adding and updating labels. It provides an easy-to-use interface for tracking IP addresses and their associated labels. Additionally, the system features an audit log service that records all user actions, providing accountability and traceability for all changes made to the IP address database.
This project is build with these technologies.
- A token based login feature to the system.
- User should be able to add, view new IP address with a label to the database.
- IP addresses must be validated
- Only authenticated user are able add/changes the record of database.
- User should be able to modify only the IP address label.
- System should have an audit log where all the changes will stored.
- The audit trail should be maintained for every login and changes.
- The application should be designed and built following best practices and design patterns.
- The application should be well-documented and testable.
- Write a few test cases to ensure that the API is functioning as expected.
Before you can run this Laravel project, you'll need to install the following software:
- PHP v8.1 or later
- Composer v2.5.4 or later
- Laravel v10.0 or later
- MySQL
- npm v8.5.1 or later
You will also need to set up a MySQL database and configure Laravel to use it. Here's how:
- Create a new MySQL database foryour project.
- Update the DB_DATABASE, DB_USERNAME, and DB_PASSWORD values in the .env file to match your MySQL database credentials.
Please check the official laravel installation guide for server requirements before you start. Official Documentation
-
Clone the repo
git clone [email protected]:mhmohon/ip-management.git
-
Switch to the repo folder
cd ip-management
-
Install all the dependencies using composer
composer install
-
Copy the example env file and make the required configuration changes in the .env file
cp .env.example .env
-
Generate a new application key
php artisan key:generate
-
Run the database migrations (Set the database connection in .env before migrating)
php artisan migrate --seed
-
Start the local development server
php artisan serve
You can now access the server at http://localhost:8000
Now you have to setup the front application. Create another terminal in same directory and run following command.
-
Install NPM packages
npm install
-
Start the local frontend server
npm run dev
TL;DR command list
git clone [email protected]:mhmohon/ip-management.git
cd ip-management
composer install
cp .env.example .env
php artisan key:generate
Make sure you set the correct database connection information before running the migrations
php artisan migrate --seed
php artisan serve
TL;DR command list for local frontend server
npm install
npm run dev
I have chosen to use the Service Layer design patterns in my implementation of this application also used the service interface layer so that the code will be more abstract and increased testability, which make the application more modular, maintainable, and scalable.
For creating audit log service I have used Model-Observer Pattern, to make the code more simplifies code and provide separation of concerns.
To create audit log for each time user login, I have used this pattern to make the code more scalable.
For storing an IP address in the database I have used the BINARY(16) field type to store both IPv4 and IPv6 addresses. This requires more storage space but allows for faster indexing and searching of IP addresses. Used the inet_pton function to convert the IP address to its binary representation and stored it. Used the inet_ntop function to convert the binary IP address to its human-readable form.
You can run Unit test by using this command
./vendor/bin/pest
Result
You can run PHPStan test by using this command
./vendor/bin/phpstan analyse
Result
Mosharrf Hossain - @Linkedin - [email protected]
Project Link: https://github.com/mhmohon/ip-management