EKyc is a system that manages user kyc. It provides API based solution for face matching and OCR.
The purpose of this exercise is for you to get familiar with building HTTP API with tests on a real-world use case. This exercise will give you enough idea about building REST APIs in Golang that uses Database, Async workers and Caches, which are the most common components of any web application.
- Customer Signup.
- Upload Image.
- Face match score generation.
- OCR for extracting data from ID cards.
- Clone this repository.
git clone https://github.com/one2nc/ekyc-pratik.git
- To set up docker containers of postgres and MinIO from docker-compose file, run.
make setup
- To take down docker containers, run.
make setup-down
-
MinIO is an open-source, self-hosted object storage server compatible with Amazon S3 cloud storage service.
-
Images uploaded by customers are stored on MinIO server.
-
MinIO runs in a container using docker-compose file.
-
MinIO admin console can be accessed by opening localhost:9001 in the browser.
-
Login to the console using
MINIO_ROOT_USER
andMINIO_ROOT_PASSWORD
provided in docker-compose file. -
After logging in generate
access and secret key
, which will be used in env variablesMINIO_ACCESS_KEY, MINIO_SECRET_KEY
. -
Create a bucket for images and set the bucket name into
MINIO_IMAGE_BUCKET_NAME
env variable. -
MinIO API's can be accessed through
localhost:9000
. This has to be set in theMINIO_IMAGE_ENDPOINT
env variable.
- Refer
.env.example
file to create your own.env
file in the root of the project.
ENV_VARIABLE | Description |
---|---|
DB_HOST |
Host for database connection |
DB_USER |
Database user |
DB_PASSWORD |
Database password |
DB_PORT |
Database port |
DB_NAME |
Database name |
SERVER_PORT |
Server port |
SERVER_HOST |
Server Host |
DB_MIGRATION_FILE |
DB migration file path |
MINIO_ACCESS_KEY |
Access key for MinIO server |
MINIO_SECRET_KEY |
Secret key for MinIO server |
MINIO_IMAGE_BUCKET_NAME |
Name of image bucket |
MINIO_IMAGE_ENDPOINT |
MinIO endpoint for api |
REDIS_ADDRESS |
Redis address |
REDIS_PORT |
Redis port |
DAILY_REPORT_CRON_EXPRESSION |
Cron expression for daily reports generation |
- Migration scripts are in the
db/migrations
folder. - Migrations are run using golang-migrate package.
- Migrations run during the initialisation of server.
# command to add a migration file
migrate create -ext sql -dir <directory_path> -seq <migration_name>
- To build and start the server, run.
make run
- Postman is an API platform for building and using APIs.
- Postman collection is in
ekyc.postman_collection.json
file in the root of the project. - Open postman and import this collection. After importing you can see all the requests under
ekyc
collection. - Environment variables:
Postman ENV_VARIABLE | Description |
---|---|
baseUrl |
set by default to http://127.0.0.1:3000 using pre request script . |
access_key |
set using script by extratcting values from response of the signup api. |
secret_key |
set using script by extratcting values from response of the signup api. |
Note: First you need to create and select an environment.
POST /api/v1/auth/singup
Body Parameters | Type | Description |
---|---|---|
name |
string |
Required. |
email |
string |
Required. |
plan |
string |
Required. |
Body Parameters | Type |
---|---|
access_key |
string |
secret_key |
string |
POST /api/v1/image/upload
Headers | Description |
---|---|
Access-Key |
Required. |
Secret-Key |
Required. |
- These headers are set automatically by env variables and scripts.
Body Parameters | Type | Description |
---|---|---|
image |
file |
Required. |
image_type |
string |
Required |
- Valid image_type values are
(face or id_card)
.
Body Parameters | Type |
---|---|
image_id |
string |
POST /api/v1/image/face-match
Headers | Description |
---|---|
Access-Key |
Required. |
Secret-Key |
Required. |
- These headers are set automatically by env variables and scripts.
Body Parameters | Type | Description |
---|---|---|
image_id_1 |
string,uuid |
Required. |
image_id_2 |
string,uuid |
Required. |
- Upload images using upload image api. After uploading you will get image_id for each image in response.
- Use these image id's as image_id_1 and image_id_2 in the face match api. Note that both ids should not be same.
Body Parameters | Type |
---|---|
score |
int |
POST /api/v1/image/ocr
Headers | Description |
---|---|
Access-Key |
Required. |
Secret-Key |
Required. |
- These headers are set automatically by env variables and scripts.
Body Parameters | Type | Description |
---|---|---|
image_id |
string,uuid |
Required. |
- Upload images using upload image api. After uploading you will get image_id for each image in response.
- Use this image id in the ocr api body to get data. Note that provided image should be of type id_card.
Body Parameters | Type |
---|---|
data.name |
string |
data.dob |
string |
data.gender |
string |
data.address |
string |
data.pincode |
string |
data.idNumber |
string |
GET /api/v1/reports/
Headers | Description |
---|---|
Access-Key |
Required. |
Secret-Key |
Required. |
- These headers are set automatically by env variables and scripts.
Query Parameters | Type | Description |
---|---|---|
start_date |
string,date(yyyy-mm-dd hr:mm:ss) |
Required. |
end_date |
string,date(yyyy-mm-dd hr:mm:ss) |
Required. |
- Customer can get an aggregated report for dates between start_date and end_date
Body Parameters | Type |
---|---|
report.customer_id |
string |
report.start_date_of_report |
string |
report.end_date_of_report |
string |
report.total_base_charge |
float |
report.total_face_match_count |
int |
report.total_face_match_cost |
float |
report.total_ocr_count |
int |
report.total_ocr_cost |
float |
report.total_image_storage_size_mb |
float |
report.total_image_storage_cost |
float |
report.total_api_call_charges |
float |
report.total_invoice_amount |
float |
report.plan_name |
string |
GET /api/v1/reports/get-all-reports
Headers | Description |
---|---|
Access-Key |
Required. |
Secret-Key |
Required. |
- These headers are set automatically by env variables and scripts.
Query Parameters | Type | Description |
---|---|---|
start_date |
string,date(yyyy-mm-dd hr:mm:ss) |
Required. |
end_date |
string,date(yyyy-mm-dd hr:mm:ss) |
Required. |
- Customer can get an aggregated report for dates between start_date and end_date
Body Parameters | Type |
---|---|
reports[].customer_id |
string |
reports[].start_date_of_report |
string |
reports[].end_date_of_report |
string |
reports[].total_base_charge |
float |
reports[].total_face_match_count |
int |
reports[].total_face_match_cost |
float |
reports[].total_ocr_count |
int |
reports[].total_ocr_cost |
float |
reports[].total_image_storage_size_mb |
float |
reports[].total_image_storage_cost |
float |
reports[].total_api_call_charges |
int |
reports[].total_invoice_amount |
float |
reports[].plan_name |
string |
start_date_of_report |
string |
end_date_of_report |
string |