Skip to content

🧠 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. πŸš€

Notifications You must be signed in to change notification settings

HouseCham/cerebro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cerebro: API Gateway for Microservices

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.

Features

  • API routing and forwarding
  • Authentication and authorization
  • Load balancing and service discovery
  • Logging and monitoring

Frameworks & Libraries

The project relies on the following frameworks and libraries:

Usage

Building Docker Images

To build both Cerebro and CustomerService for test there already is a docker compose yaml file.

1️⃣ Clone the Cerebro repository:

git clone https://github.com/HouseCham/cerebro.git

2️⃣ Navigate to the project directory: bash cd cerebro

3️⃣ Be sure to create a .env file at the root of the repo:

# πŸ“Œ Cerebro (API Gateway)
CEREBRO_NAME=cerebro
CEREBRO_PORT=3000
CEREBRO_HOST=localhost
JWT_SECRET=my-random-secret

# πŸ“Œ Customer Service
CUSTOMER_SERVICE_NAME=customer-service
CUSTOMER_SERVICE_HOST=localhost
CUSTOMER_SERVICE_PORT=3001

# πŸ“Œ Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=my-db-password
DB_NAME=cerebroDB

4️⃣ Run the Services with Docker Compose

docker compose up -d
  • The -d flag runs the containers in the background.
  • To see logs in real-time, remove -d:
    docker compose up

πŸ›  Testing the gRPC Web API

Once the services are running, you can use Postman, cURL, or any API testing tool to interact with the system.

πŸ“Œ Create a New Customer

  • Endpoint: POST http://localhost:3000/api/v1/customer
  • Request Body:
    {
        "id": 0,
        "first_name": "John",
        "second_name": "",
        "last_name_p": "Doe",
        "last_name_m": "Doe2",
        "phone_number": "0000000000",
        "email": "john.doe@example.com",
        "password": "password123"
    }
  • Response:
    {
        "data": 1,
        "hasError": false,
        "errorMessage": "",
        "statusCode": 200
    }
    • The data field represents the newly created customer's ID in the database.

πŸ“Œ Fetch Customer Information

  • Endpoint: GET http://localhost:3000/api/v1/customer/{userId}
  • Example Response:
    {
        "data": {
            "id": 1,
            "firstName": "John",
            "secondName": "",
            "lastNameP": "Doe",
            "lastNameM": "Doe2",
            "phoneNumber": "0000000000",
            "email": "john.doe@example.com",
            "passwordHash": "",
            "HashedPassword": ""
        },
        "hasError": false,
        "errorMessage": "",
        "statusCode": 200
    }

πŸ›‘ Stopping and Cleaning Up

To stop the services, run:

docker compose down

To remove all containers, networks, and volumes:

docker compose down -v

About

🧠 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. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published