Civil Servant
Overview
Civil Servant is a modular API gateway built with Spring Boot and Spring Cloud Gateway. It is designed to dynamically discover, register, and proxy services, enabling seamless integration of new services while providing a central access point.
Features
- Dynamic Service Discovery: Automatically discovers services with
service-config.json
files in a designated directory. - Service Registration: Registers services dynamically and proxies requests to them.
- Route Management: Automatically configures routes based on service descriptors.
- Modular Architecture: Easily extend functionality by adding new services or enhancing the gateway logic.
- Environment Variable and Configuration Support: Services can include their own configuration and setup scripts.
Application Information
- Name: Civil Servant
- Version: 1.0.0
- Author: @ilgigante77
- Website: https://github.com/tanadelgigante/civil-servant
Getting Started
Prerequisites
- Java 17+
- Maven 3.8+
- Docker (optional for containerized deployment)
- Python 3.9+ for services like Calibre API
Installation
-
Clone the repository:
git clone https://github.com/yourusername/civil-servant.git cd civil-servant
-
Build the application:
mvn clean install
-
Create the services directory:
Create aservices/
directory in the project root. Each service should have its own subdirectory with aservice-config.json
file and optionalsetup.sh
script.
Configuration
-
Define Routes and Services:
Ensure each service directory contains aservice-config.json
with the following structure:{ "name": "sample-api", "language": "python", "route": "/sample-api", "startCommand": "your_startuè_command_here" }
-
Service Setup:
Each service directory can include asetup.sh
script to prepare its environment (e.g., install dependencies). -
Application Configuration:
Updateapplication.yml
as needed to customize gateway routes or application settings:server: port: 8187 logging: level: root: INFO com.tanadelgigante: DEBUG spring: cloud: gateway: routes: - id: sample-api uri: http://127.0.0.1:8000 predicates: - Path=/sample-api/** filters: - StripPrefix=1
Running the Application
-
Run Locally:
mvn spring-boot:run
-
Using Docker:
Create aDockerfile
for the gateway:FROM eclipse-temurin:21-jdk as build WORKDIR /app COPY .mvn/ .mvn/ COPY mvnw . COPY pom.xml . COPY src ./src RUN ./mvnw package -DskipTests RUN ls -l /app/target FROM eclipse-temurin:21-jre WORKDIR /app COPY --from=build /app/target/civilservant*.jar app.jar VOLUME /config ENTRYPOINT ["java", "-jar", "app.jar", "--spring.config.location=/config/application.yml"]
Build and run the Docker container:
docker build -t civil-servant . docker run -p 8187:8187 civil-servant
-
Service Execution:
- Ensure services have valid configurations and scripts.
- The gateway will automatically discover and start services using their
startCommand
.
Usage
API Endpoints
-
Health Check:
curl http://localhost:8187/test
Response:
{ "message": "Civil Servant Gateway is working!" }
-
Proxy Requests:
- Example: Access the Calibre API:
curl -X GET http://localhost:8187/sample-api/endpoint?api_token=your_32_char_token
- Example: Access the Calibre API:
Debugging
- Use the application logs to monitor service registration and route configuration. Look for
[INFO]
and[DEBUG]
messages in the console output. - To debug individual services, check their logs during startup.
Contributing
Contributions are welcome! Fork the repository and submit pull requests for enhancements or bug fixes.
License
This project is licensed under the GPL 3.0 License. See the LICENSE file for details.
Disclaimer
This project is released "as-is" and the author is not responsible for damage, errors, or misuse.
Contact
For more information, visit https://github.com/tanadelgigante/civil-servant.