Home

Awesome

FreeCar

English | 中文

FreeCar is a cloud-native time-sharing car rental system suite based on Hertz and Kitex.

Project Architecture

Call Relationship

call_relations.png

Technology Architecture

tech_arch

Service Relations

service_relations.png

Technology Stack

FunctionImplementation
HTTP FrameworkHertz
RPC FrameworkKitex
DatabaseMongoDB, MySQL, Redis
AuthenticationPaseto
Service and Configuration CenterConsul
Metrics MonitoringPrometheus
TracingJaeger
Message QueueRabbitMQ
Service GovernanceOpenTelemetry
Current Limiting FuseSentinel
Object StorageMinIO
Image RecognitionBaidu OCR
CIGitHub Actions

Display

Mini Program

Mini program project address FreeCar-MP

display.png

Admin

Admin project address FreeCar-Admin

data-analize.png

back.png

Catalog Introduce

CatalogIntroduction
CmdProject Core
IdlIDL file for all services of the project
SharedReusable Code

Service Introduce

CatalogIntroduction
APIHertz-based gateway service
UserUser Authentication Service
BlobServices related to image and MinIO object storage
CarCar Service
ProfileHome Page and Image Recognition Service
TripItinerary Services

Quick start

Start the Dependence

make start

Consul

For the default Consul address and KV configuration, please refer to each config.yaml configuration file.

consul_service.png

consul_kv.png

For detailed configuration of KV key-value pairs, see.

Start HTTP

make api

Start RPC

make user
make blob
make car
make profile
make trip

Jaeger

Visit http://127.0.0.1:16686/ on your browser

jaeger.jpg

jaeger2.png

Prometheus

Visit http://127.0.0.1:3000/ on your browser

prometheus.jpg

MinIO

Visit http://127.0.0.1:9000/ on your browser

minio.jpg

K8s Deployment

cd deployment/freecar-k8s
make all

Pod

pod.png

PVC

pvc.png

Service

service.png

Development Guide

It is very difficult to understand this project by directly reading the source code. Here is a development guide for developers to quickly understand and get started with this project, including frameworks such as Kitex and Hertz.

Preparation

Use the commands in the quick start to quickly start the required tools and environment. If you need special customization, please modify the contents of docker-compose.yaml and Nacos configuration.

IDL

Before development, we need to define the IDL file, among which hz provides developers with many customized api annotations.

Sample code:

namespace go user

struct LoginRequest {
     1: string code
}

struct LoginResponse {
     1: i64 accountID
}

service UserService {
     LoginResponse Login(1: LoginRequest req)
}

Code Generation

Kitex

First generate kitex_gen in the shared folder, and then rely on kitex_gen in the corresponding service folder to generate. Execute under the new service directory, only need to change the service name and IDL path each time.

kitex -module github.com/CyanAsterisk/FreeCar ./../idl/rpc/user.thrift
kitex -service user -module github.com/CyanAsterisk/FreeCar -use github.com/CyanAsterisk/FreeCar/server/shared/kitex_gen ./../../idl/rpc/user.thrift

Note:

Hertz

Initialize
hz new -idl ./../../idl/api.proto -mod github.com/CyanAsterisk/FreeCar/server/cmd/api

Note:

Business Development

After the code is generated, some necessary components need to be added to the project. Since the api layer does not need to be added again, the following mainly explains about Kitex-Server section, the code is located under server/cmd.

Config

Refer to server/cmd/user/config for the configuration structure of microservices.

Initialize

Refer to server/cmd/user/initialize to provide the initialization function of the necessary components, among which config.go registry.go flag.go logger.go are required.

Pkg

Refer to server/cmd/user/pkg to provide calling functions of microservices, which are mainly used to implement the interfaces defined in handler.go.

API

When writing the business logic of the gateway layer, you only need to update the IDL and the new microservice client code each time. If you need to add new components, you can add them directly. The project is highly pluggable, and the architecture is similar to the microservice layer.

The business logic of the gateway layer is under server/cmd/api/biz, and most of the code will be automatically generated. If you need to add a new route separately, you need to go to server/cmd/api/router.go.

Regarding the use of middleware, you only need to add middleware logic in server/cmd/api/biz/router/api/middleware.go.

License

FreeCar is open source under the GNU General Public License version 3.0.