No description
  • PHP 51.2%
  • Blade 46.8%
  • CSS 0.7%
  • Dockerfile 0.7%
  • Shell 0.3%
  • Other 0.3%
Find a file
2024-03-19 22:00:14 +04:00
.fly feat: add fly.io 2024-03-15 15:57:47 +04:00
.github/workflows feat: add fly.io 2024-03-15 15:57:47 +04:00
app fix: fix search 2024-03-19 18:07:23 +04:00
bootstrap fix: remove telescope 2024-03-19 17:20:07 +04:00
config feat: add crud with livewire 2024-03-19 15:41:17 +04:00
database fix: fix permissions 2024-03-19 17:01:56 +04:00
public Set up a fresh Laravel app 2024-03-13 11:08:54 +04:00
resources fix: resize logo 2024-03-19 18:24:08 +04:00
routes fix: fix permissions 2024-03-19 17:01:56 +04:00
storage Set up a fresh Laravel app 2024-03-13 11:08:54 +04:00
tests feat: add crud with livewire 2024-03-19 15:41:17 +04:00
.dockerignore feat: add crud with livewire 2024-03-19 15:41:17 +04:00
.editorconfig Set up a fresh Laravel app 2024-03-13 11:08:54 +04:00
.env.example feat: add example 2024-03-17 20:11:46 +04:00
.gitattributes Set up a fresh Laravel app 2024-03-13 11:08:54 +04:00
.gitignore feat: add crud with livewire 2024-03-19 15:41:17 +04:00
artisan Set up a fresh Laravel app 2024-03-13 11:08:54 +04:00
composer.json fix: disable telescope 2024-03-19 17:12:50 +04:00
composer.lock feat: add table with search 2024-03-15 22:33:17 +04:00
docker-compose.yaml feat: add docker environment 2024-03-17 20:12:41 +04:00
Dockerfile feat: add docker environment 2024-03-17 20:12:41 +04:00
fly.toml feat: add gotenberg url to fly.io 2024-03-17 20:13:56 +04:00
Makefile feat: add docker environment 2024-03-17 20:12:41 +04:00
package-lock.json Install Jetstream 2024-03-13 11:12:22 +04:00
package.json Install Jetstream 2024-03-13 11:12:22 +04:00
phpstan.neon feat: add dev tools 2024-03-13 12:07:18 +04:00
phpunit.xml feat: add model creation with tests 2024-03-13 15:38:46 +04:00
postcss.config.js Install Jetstream 2024-03-13 11:12:22 +04:00
README.md docs: update API docs 2024-03-19 22:00:14 +04:00
tailwind.config.js style: make container center 2024-03-15 20:35:17 +04:00
vite.config.js Install Jetstream 2024-03-13 11:12:22 +04:00

Car4Sure

Features

  • CI/CD to Fly.io
  • Uses SQLite as Database in Production
  • Login and Sign Up
  • Full Text Search
  • CRUD a Policy with its drivers, policy holder, vehicles and its coverages
  • Download a Policy in PDF
  • Roles & Permissions
  • Scopes - where Customers only sees policies assigned to them
  • API endpoints (Using OAuth2 for Third Party Connection)
    • /api/v1/policies/

How it works

  • This project is an internal tool to allow insurance Car4Sure to manage policies.
  • A customer can sign up or sign in to the website and have an account.
  • A policy manager can create any policies, and assign it to to any customer.
  • A customer can only view their policies (a policy can be assigned to multiple users)
  • A policy manager can change any policy.
  • API endpoints uses OAuth2 with Client Credentials/Password Grant.
    • Client Credentials allows machine to machine interactions Ex. A third Party - A business partner.
    • Password Grant allows any users to retrieve database based on their priviledge and perform actions too.

Roles

We have 3 types of users

  • Customers, they are allowed to view only their policies and download them.
  • Policy Makers/Managers are allowed to create update and delete policies.
  • Admins are allowed to do everything + They can create Client Credentials And Password Grants. (No UI done will need to do it via CLI)

Why it works like this ?

Care4sure is an insurance company, it should not allow any users to modify their data. Maybe an implementation is to make a policy commentable, and versionable, so that when a customer comments on a policy, both users and policy makers are able to view history of a specific policy and history of comments. So, this allows transparency and protection against unwanted change.

Why PolicyHolder is not a User Model why is it its own model ?

Not sure if the policy holder should be part of the system. Example; Let's say a user never connects to the app. Should that user has a "ghost account" since it is created behind the scene by a policy maker. Same thing for drivers. They are their own models. More flexiblity (as a developer).

Duplicate data ? Possible, but storage is cheap. We can always connect the dots with the users'name or their national id number.

Live version

Login at: https://iplatform.fly.dev

Users available (same as Local):

iamthenight@gmail.com (super admin - same as policy maker, didn't add more features for this user.) ilovecakes@gmail.com (policy maker) anybody@gmail.com (customer) anybody2@gmail.com (customer) anybody3@gmail.com (customer)

All has password as password. You can also register at:

https://iplatform.fly.dev/register if you want to but you will have no data.

To interact with API:

Client ID: 1 Client Secret: LuntU1QxcYuBk4Ru110pUTGhfErctEfWxRyuTGYU

curl --request POST \
  --url https://iplatform.fly.dev/oauth/token \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data client_id=1 \
  --data client_secret=fQjVPxrQTSUmwfExFZK7tU1WmxE1IlRreJjrPmAD

Use Bearer Token:

  GET    api/v1/policies 
  POST   api/v1/policies
  GET    api/v1/policies/{policy}
  PUT    api/v1/policies/{policy}
  DELETE api/v1/policies/{policy}
  GET    api/v1/policies/{policy}/drivers
  POST   api/v1/policies/{policy}/drivers
  GET    api/v1/policies/{policy}/drivers/{driver}
  PUT    api/v1/policies/{policy}/drivers/{driver}
  DELETE api/v1/policies/{policy}/drivers/{driver}
  GET    api/v1/policies/{policy}/policy-holder
  POST   api/v1/policies/{policy}/policy-holder
  GET    api/v1/policies/{policy}/policy-holder/{policy_holder}
  PUT    api/v1/policies/{policy}/policy-holder/{policy_holder}
  DELETE api/v1/policies/{policy}/policy-holder/{policy_holder}
  GET    api/v1/policies/{policy}/vehicles
  POST   api/v1/policies/{policy}/vehicles
  GET    api/v1/policies/{policy}/vehicles/{vehicle}
  PUT    api/v1/policies/{policy}/vehicles/{vehicle}
  DELETE api/v1/policies/{policy}/vehicles/{vehicle}
  GET    api/v1/vehicles/{vehicle}/coverages
  POST   api/v1/vehicles/{vehicle}/coverages
  GET    api/v1/vehicles/{vehicle}/coverages/{coverage}
  PUT    api/v1/vehicles/{vehicle}/coverages/{coverage}
  DELETE api/v1/vehicles/{vehicle}/coverages/{coverage}

Local Testing

Use Laravel Herd or Laravel Valet or Use the docker-compose.

  • php artisan passport:keys # This generate pub and private keys for API.

if you want to generate a keypair manually:

openssl genpkey -algorithm RSA -out oauth-private.key -pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in oauth-private.key -out oauth-public.key
  • php artisan passport:client # This generate Client ID and Client Secret Used for Authentication

API Usage:

  • To generate Bearer token
curl --request POST \
  --url http://iplatform.test/oauth/token \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data client_id=$CLIENT_ID \
  --data client_secret=$CLIENT_SECRET
  # You can copy paste this into any API Client (Postman/Insomnia or HTTPie it will generate the format for you!)
  # iplatform.test be your localhost:8000 or anything I use Laravel Herd which is very useful.

where $CLIENT_ID and $CLIENT_SECRET comes from php artisan passport:client

Afterwards, head to the commandline, and run:

php artisan route:list | grep api/v1

You will get a list of API endpoints to call. In case there is no data.

Reset Database

php artisan migrate:fresh --seed

This will create some fake data. It will also create 2 testing users for login purposes.