Cerebro is a Golang project focused on developing an API gateway, connected to microservices using gRPC connections. It acts as a central entry point for client requests, providing functionalities such as routing, authentication, and load balancing to the underlying microservices.
- API routing and forwarding
- Authentication and authorization
- Load balancing and service discovery
- Logging and monitoring
cerebro/
βββ api/
β βββ core/
β β βββ controllers/
β β βββ grpc/
β βββ routes/
βββ cmd/
β βββ main.go
βββ internal/
β βββ config/
β βββ log/
β βββ model/
βββ pkg/
β βββ utils/
βββ scripts/
βββ .dockerignore
βββ config.json
βββ go.mod
βββ go.sum
βββ README.md
βββ Dockerfile
-
api/
This directory contains the API-related code.- core/: Core functionality of the API.
- controllers/: Controllers for handling HTTP requests.
- grpc/: gRPC related code.
- routes/: API routes definition.
- core/: Core functionality of the API.
-
cmd/
Main application entry point. -
internal/
: Internal package containing application-specific code.- config/: Configuration related code.
- log/: Logging functionality.
- model/: Data models used by the application.
-
pkg/
: Package directory containing reusable code.- utils/: Utility functions and libraries.
-
scripts/
: Directory containing scripts for building, testing, and running the application. -
Dockerfile
: File used to build a Docker image for the project. -
.dockerignore
: File specifying paths to exclude when building Docker images. -
config.json
: Configuration file for the application. -
go.mod
,go.sum
: Go module files specifying dependencies for the project. -
README.md: Markdown file containing project information and instructions.
This structure organizes the project into separate directories for different components, making it easier to manage and maintain the codebase.
The project relies on the following frameworks and libraries:
- Fiber v3 v3.0.0-beta.2
- Logrus v1.9.3
- Viper v1.18.2
- gRPC v1.63.2
- Protocol Buffers v1.33.0
To build the Docker images for Cerebro, follow these steps:
-
Clone the Cerebro repository:
git clone https://github.com/HouseCham/cerebro.git
-
Navigate to the project directory:
cd cerebro
-
Build the docker image using the provided Dockerfile:
docker build -t cerebro:[version] .
Once you have built the Docker image, you can run containers for Cerebro using the following commands (remove the -it
tag in case you do not want the container to be interactive) :
sudo docker run -d \
--name cerebro-api-gateway \
-p 3000:3000 \
-it \
--restart unless-stopped \
cerebro-service:0
Replace 3000:3000
with the desired port mapping if needed. Remember to change that configuration within the config.json file
{
"app": {
"port": 3000,
"host": "localhost"
}
}
INFO[2024-04-30T21:57:32Z] Setting up config file
INFO[2024-04-30T21:57:32Z] Setting up Fiber instance with CORS middleware and routes
INFO[2024-04-30T21:57:32Z] Setting up gRPC connections
INFO[2024-04-30T21:57:32Z] Server is running on http://localhost:3000
_______ __
/ ____(_) /_ ___ _____
/ /_ / / __ \/ _ \/ ___/
/ __/ / / /_/ / __/ /
/_/ /_/_.___/\___/_/ v3.0.0-beta.2
--------------------------------------------------
INFO Server started on: http://127.0.0.1:3000 (bound on host 0.0.0.0 and port 3000)
INFO Total handlers count: 3
INFO Prefork: Disabled
INFO PID: 1
INFO Total process count: 1