MARLO is a robust foundation for a modern, scalable, and portable backend, built with Spring Boot, Maven, hexagonal and clean architecture. It includes MySQL integration, unit testing, Swagger documentation, and is ready for local execution, Docker, and AWS Lambda deployment.
MARLO follows a Hexagonal (Ports & Adapters) and Clean Architecture approach:
- Domain (domain/model): Contains pure business models and logic, independent of frameworks or external technologies.
- Application (application/service): Holds business use cases and orchestrates domain logic.
- Adapters (adapter/rest): Entry and exit points, such as REST controllers, repositories, or external integrations.
- Infrastructure (config, resources): Technical details like database configuration, Swagger, and logging.
This separation ensures maintainability, testability, and flexibility, making it easy to evolve the system, swap technologies, and deploy in different environments (local, Docker, Lambda).
- Spring Boot + Maven
- Hexagonal and clean architecture
- MySQL integration
- Example REST service
- Swagger configuration
- Ready for local, Docker, and Lambda
- Configure your MySQL database and update
application-local.properties
or use environment variables (.env
). - Run:
mvn spring-boot:run
- Build the image:
docker build -t marlo-backend .
- Run the container:
docker run -p 8080:8080 --env-file .env marlo-backend
- You can use AWS Serverless Java Container to package the app.
- See the official AWS documentation for instructions.
- Access the documentation at:
http://localhost:8080/swagger-ui.html
orhttp://localhost:8080/swagger-ui/index.html
Best Practices:
- Use environment variables for credentials and sensitive data (can be sourced from AWS Secrets Manager).
- Keep business logic in the domain and application layers, and technological details in the adapters.
- Ensure minimum test coverage (see JaCoCo configuration in the pom.xml).
- Document and version your API with Swagger/OpenAPI.
- For Lambda, package using AWS Serverless Java Container.
MARLO uses Spring Boot's built-in logging (SLF4J with Logback). You can log messages in your code using:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger(YourClass.class);
logger.info("This is an info log message");
logger.error("This is an error log message");
You can configure log levels and output in src/main/resources/application.yml
or by providing environment variables.
- Construye el artefacto:
mvn clean package
(generatarget/marlo-0.0.1-SNAPSHOT.jar
). - Crea la imagen para Lambda:
docker build -f Dockerfile.lambda -t marlo-lambda .
. - (Opcional) Prueba la imagen local con el Runtime Interface Emulator de AWS:
docker run -p 9000:8080 marlo-lambda
y realiza una invocación HTTP ahttp://localhost:9000/2015-03-31/functions/function/invocations
con el payload de API Gateway. - Publica la imagen en ECR y úsala en tu función Lambda.
La aplicación sigue ejecutándose de forma tradicional con mvn spring-boot:run
o java -jar target/marlo-0.0.1-SNAPSHOT.jar
.
- Construye el artefacto: mvn clean package (genera arget/marlo-0.0.1-SNAPSHOT.jar).
- Crea la imagen para Lambda: docker build -f Dockerfile.lambda -t marlo-lambda ..
- (Opcional) Prueba la imagen local con el Runtime Interface Emulator de AWS: docker run -p 9000:8080 marlo-lambda y realiza una invocación HTTP a http://localhost:9000/2015-03-31/functions/function/invocations con el payload de API Gateway.
- Publica la imagen en ECR y úsala en tu función Lambda.
La aplicación sigue ejecutándose de forma tradicional con mvn spring-boot:run o java -jar target/marlo-0.0.1-SNAPSHOT.jar.
- La aplicación espera el prefijo del stage (/dev, /prod, etc.) en la variable de entorno BASE_PATH. Localmente puedes omitirla (queda vacía).
- En Lambda: BASE_PATH=/dev (o el stage correspondiente) junto con el resto de variables que utilices (SPRING_PROFILES_ACTIVE, MYSQL_URL, etc.).
- El swagger queda accesible en ${BASE_PATH}/swagger-ui/index.html, y los docs en ${BASE_PATH}/v3/api-docs.
- Cualquier despliegue nuevo: reconstruye el JAR, crea la imagen, súbela a ECR, actualiza la función y despliega el API Gateway.
- Define la variable de entorno BASE_PATH con el prefijo de tu stage (/dev, /prod, etc.). En local puedes dejarla vacía.
- Mantén el resto de variables (por ejemplo SPRING_PROFILES_ACTIVE, MYSQL_URL, MYSQL_USER, MYSQL_PASSWORD).
- Swagger queda disponible en ${BASE_PATH}/swagger-ui/index.html y los docs en ${BASE_PATH}/v3/api-docs.
- Para despliegues: mvn clean package, docker build -f Dockerfile.lambda ..., push a ECR, �ws lambda update-function-code ... con la nueva imagen y �ws lambda update-function-configuration ... --environment "Variables={BASE_PATH=/dev,...}. Luego Deploy API en API Gateway.
Localmente, sin BASE_PATH, la UI sigue en http://localhost:8080/swagger-ui/index.html.