Project Phoenix V2 is a comprehensive solution designed to streamline operations and enhance functionality for modern web applications. With a focus on scalability and performance, this project aims to provide a robust framework for building and deploying services efficiently.
The V1 of this project was developed using Node.js, focusing on providing a solid foundation for web applications. In this new iteration, Project Phoenix V2, I've transitioned to using Go. This move aims to offer better stability and a significant increase in performance, addressing the evolving needs of modern web services and applications.
- API Gateway Integration: Simplifies interaction between client applications and backend services through a unified entry point.
- Scalable Architecture: Designed to support scaling operations, ensuring high availability and resilience.
- Customizable Modules: Includes a set of modules that can be tailored to meet specific requirements, enhancing flexibility and efficiency.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
This document provides an overview of the LocationService component within Project Phoenix V2, including setup instructions, service architecture, and usage.
The LocationService is designed to manage geolocation tracking within Project Phoenix. It subscribes to specific topics through a message broker (RabbitMQ) to handle start and stop tracking events.
The service is built on the Go-Micro framework, leveraging the power of microservices for scalable, distributed applications. RabbitMQ is used as the message broker for event-driven communication between services.
The API Gateway Service acts as the entry point for all client requests to the backend services. It routes requests to the appropriate service, handles sessions, and provides an additional layer of security through middleware.
Configure and run the API Gateway Service to manage incoming requests and route them to the correct backend services.
Ensure RabbitMQ is running and accessible. Configure the .env file with the correct RabbitMQ connection parameters:
RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=user
RABBITMQ_PASSWORD=pass
Navigate to the project directory and execute:
go run main.go --service-name api-gateway --port 8981
The API Gateway Service uses the Gorilla Mux router to define HTTP routes. Middleware can be applied to routes for session management, authentication, and logging.
api.router.HandleFunc("/api/path", handlerFunction).Methods("GET")
Middleware is applied to routes to handle cross-cutting concerns:
api.router.Use(authMiddleware)
The API Gateway communicates with backend services through RabbitMQ for message-based communication, facilitating asynchronous processing and decoupling of services.
To containerize the API Gateway Service, use the provided Docker commands to build images, run containers, and view logs.
docker build -t api-gateway .
docker run -d -p 8981:8981 api-gateway
- Unified entry point for backend services, simplifying client interactions.
- Session management capabilities to maintain user state across requests.
- Modular middleware integration for authentication, logging, and request validation.
- Flexible routing to support various backend services dynamically.
- Go (1.x or later)
- Docker (for RabbitMQ container)
- RabbitMQ (standalone or via Docker)
Follow these steps to get the LocationService running:
- Clone the Project Phoenix repository:
git clone https://github.com/wahajnintyeight/project-phoenix-v2.git
- Navigate to the project directory:
cd project-phoenix-v2
- Build and run the service:
go run main.go --service-name location-service --port 8982
The LocationService subscribes to 'start-tracking' and 'stop-tracking' topics. It processes incoming messages to manage tracking operations for users or devices.
To generate the protocol buffer code for gRPC services, follow these steps:
- Protocol Buffer Compiler (
protoc
) - Go protocol buffers plugin (
protoc-gen-go
) - Go gRPC plugin (
protoc-gen-go-grpc
)
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Navigate to your proto file directory and run:
protoc --go_out=./src/go/ \
--go_opt=paths=source_relative \
--go-grpc_out=./src/go/ \
--go-grpc_opt=paths=source_relative \
your-proto-file.proto
For example, to generate code for the capture-screen-request.proto:
protoc --go_out=./src/go/ \
--go_opt=paths=source_relative \
--go-grpc_out=./src/go/ \
--go-grpc_opt=paths=source_relative \
capture-screen-request.proto
What things you need to install the software and how to install them:
- Go (version 1.x or later)
A step-by-step series of examples that tell you how to get a development environment running:
- Clone the Repository
git clone https://github.com/wahajnintyeight/project-phoenix-v2.git
- Navigate to the Project Directory
cd project-phoenix-v2
- Run the Application
go run main.go --service-name api-gateway --port 8981
Below are some useful Docker commands for managing the containers associated with Project Phoenix V2.
To build the Docker images and run the containers in detached mode, use the following command:
docker compose up --build -d
To stop all running containers:
sudo docker stop $(sudo docker ps -a -q)
To remove all containers, ensuring you can rebuild and start fresh, use:
sudo docker rm $(sudo docker ps -a -q)
To follow the logs of a specific container, which is useful for debugging and monitoring the application's output:
sudo docker logs --follow containername
- List All Containers:
docker ps -a
- List Running Containers:
docker ps
- Access Container Shell:
docker exec -it containername /bin/sh
- Build Docker Images:
docker build -t imagename .
- Removing Docker Images:
docker rmi imagename
- Viewing Docker Images:
docker images
Explain how to run the automated tests for this system:
go test ./...