- Description
- Installation
- Services
- Entity Relation Diagram
- High Level Architecture Diagram
- Features
- API Scopes
- Contact
Welcome to Work-From-Office Request and Confirmation App!
This application is designed to facilitate work-from-office (WFO) requests and confirmations for companies operating under new normal Covid-19 safety protocols. It was developed to help employees stay connected with their colleagues and maintain a sense of community while adhering to new safety guidelines.
This repository was created as a learning resource for building backend applications using microservice architecture and containerized REST and gRPC services written in Go. During the development of this application, a number of challenges were encountered, such as implementing queries that join data across multiple databases and enforcing Role-Based Access Control (RBAC) in distributed services. These challenges were addressed through careful design and development, and the resulting application serves as an excellent example of how to implement a robust and scalable backend architecture.
Clone the repository
git clone https://github.com/szczynk/grpc-micro-safety.git
You should have Docker installed beforehand.
.env.example
is included on every services and main folder if you want to change env.
For default env, you just need to execute docker-compose
command in the Makefile
To create and start required containers
docker-compose -f docker-compose.local.yml up -d
Then start every services
cd grpc-gateway && make run
cd auth && make run
cd user && make run
cd mail && make run
cd safety && make run
Open the following url in the browser for API documentation (development env)
http://localhost:5000/swagger-ui/
if you done then stop every services and remove containers by using
docker-compose -f docker-compose.local.yml down
and ctrl-c
To create and start required containers
docker-compose up -d
That's great. Now we can use the backend at
http://localhost:5000
Open the following url in the browser for API documentation (development env)
http://localhost:5000/swagger-ui/
if you done then stop and remove containers by using
docker-compose down
Username: [email protected]
Password: admin123
Assuming in development env. Below are list of services:
-
auth, check this link for healthcheck
-
user, check this link for healthcheck
-
mail
-
safety, check this link for healthcheck
-
Username: [email protected] Password: admin
-
Username: minio Password: minio-secret
-
Username: admin Password: admin
-
Username: admin Password: admin
-
Username: admin Password: admin
-
Username: admin Password: admin
-
Username: admin Password: admin
- SQL database using PostgreSQL With GORM as ORM
- Distributed Server Side Caching using Redis
- Distributed Messaging Broker using Kafka
- S3 Bucket using Minio
- SMTP Testing for sending and receiving email using MailHog
- Distributed Tracing using Jaeger and grpc_opentracing
- Monitoring, Alert, and Analytics using Prometheus, grpc_prometheus, and Grafana
- gRPC Services using gRPC and grpc-go
- gRPC to RESTful HTTP API using grpc-gateway and
protoc-gen-grpc-gateway
- gRPC Middleware using go-grpc-middleware
- API Documentation using Swagger UI, and
protoc-gen-openapiv2
- Message Validators using grpc_validator and protoc-gen-validate
- Authentication using PASETO v2
- Authorization and RBAC using Casbin as a Service (CaaS)
- Logging using Zap and grpc_zap
- Error and Panic Handling in
pkg/grpc-errors
and grpc_recovery - IP based Rate Limiter using limiter
- CORS enabled in gateway service using cors
- Containerized App using Docker
- Multi-Container Deployment using Docker Compose
- Version Control using Git and Github
Entity Relation Diagram for this app shown in the picture below
High Level Architecture Diagram for this app shown in the picture below
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
POST | /auth/register | - | - | username, email, password | No | user | Register a new user |
POST | /auth/login | - | - | email, password | No | user, admin | login user and get access token & refresh token |
GET | /auth/verify-email/ | code | - | - | No | user, admin | Verify user's email by email |
POST | /auth/forgot-password | - | - | No | user, admin | Send reset password token by email | |
POST | /auth/reset-password | resetToken | - | password | No | user, admin | Reset Password using reset token |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /auth/me | - | - | - | Yes | user, admin | Get user's profile data that is currently logged in |
PATCH | /auth/me | - | - | username, avatar | Yes | user, admin | update user's profile data |
POST | /auth/change-email | - | - | Yes | user, admin | change user's email | |
POST | /auth/refresh-token | - | - | refreshToken | Yes | user, admin | Renew access token |
POST | /auth/logout | - | - | refreshToken | Yes | user, admin | Logout and delete refresh token |
GET | /users | - | username, email, role, verified, page, limit, sort | - | Yes | admin | Find lisf of users |
POST | /users | - | - | username, email, password, role, avatar, verified | Yes | admin | Create a new user by admin |
GET | /users/ | id | - | - | Yes | admin | Find user by user's id |
PATCH | /users/ | id | - | username, email, password, role, avatar, verified | Yes | admin | Edit user's data by user's id |
DELETE | /users/ | id | - | - | Yes | admin | Delete a user by user's id |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /offices | - | name, detail, page, limit, sort | - | Yes | user, admin | Find list of offices |
POST | /offices | - | - | name, detail | Yes | admin | Create a new office by admin |
GET | /offices/ | id | - | - | Yes | user, admin | Find office by office's id |
PATCH | /offices/ | id | - | name, detail | Yes | admin | Edit office's data by office's id |
DELETE | /offices/ | id | - | - | Yes | admin | Delete a office by office's id |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /workspaces | - | username, email, role, verified, page, limit, sort | - | Yes | admin | Find list of users in the office |
POST | /workspaces | - | - | officeId, userId | Yes | admin | Insert a user into the office |
DELETE | /workspaces/ | userId | - | - | Yes | admin | Delete a user in the office by user's id |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /schedules | - | officeId, month, year, page, limit, sort | - | Yes | user, admin | Find list of schedules for WFO |
POST | /schedules | - | - | officeId, totalCapacity, month, year | Yes | admin | Create a new schedule for a month by admin |
GET | /schedules/ | id | - | - | Yes | user, admin | Find schedule by schedule's id |
PATCH | /schedules/ | id | - | totalCapacity | Yes | admin | Edit schedule's total capacity by schedule's id |
DELETE | /schedules/ | id | - | - | Yes | admin | Delete a schedule by schedule's id |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /certificates | - | userId, status, page, limit, sort | - | Yes | user, admin | Find list of user's vaccine certificates |
POST | /certificates | - | - | userId, dose, description, imageUrl | Yes | user, admin | Insert a vaccince certificate by user |
GET | /certificates/ | id | - | - | Yes | user, admin | Find certificate by certificate's id |
PATCH | /certificates/ | id | - | description, imageUrl, adminUsername, status, statusInfo | Yes | user, admin | Edit certificate's data by certificate's id |
DELETE | /certificates/ | id | - | - | Yes | admin | Delete a certificate by certificate's id |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /attendances | - | userId, scheduleId, adminUsername, status, page, limit, sort | - | Yes | user, admin | Find list of attendances |
POST | /attendances | - | - | userId, scheduleId, description, imageUrl | Yes | user, admin | Create a new WFO request by user |
GET | /attendances/ | id | - | - | Yes | user, admin | Find attendance by attendance's id |
PATCH | /attendances/ | id | - | scheduleId, adminUsername, status, statusInfo | Yes | admin | Edit attendance's status by attendance's id |
DELETE | /attendances/ | id | - | - | Yes | admin | Delete a attendance by attendance's id |
Method | Endpoint | Path Param | Query Param | Request Body | JWT Token | Role | Fungsi |
---|---|---|---|---|---|---|---|
GET | /checks | - | userId, scheduleId, page, limit, sort | - | Yes | user, admin | Find list of checks |
GET | /checks/ | attendanceId | - | - | Yes | user, admin | Find check by attendance's id |
PATCH | /check-in | attendanceId | - | temperature | Yes | user, admin | check-in on scheduled WFO request |
PATCH | /checks-out | - | - | - | Yes | user, admin | check-out after scheduled WFO request |
©️ 2023 | Szczynk