Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RaminMammadzada/cf049ce864bb63628778332b6319588a to your computer and use it in GitHub Desktop.
Save RaminMammadzada/cf049ce864bb63628778332b6319588a to your computer and use it in GitHub Desktop.
Sample Project: Secure Online Bookstore with Jenkins CI/CD

Sure, let's create a take-home assignment that builds on the previous project, incorporating Continuous Integration/Deployment with Jenkins, and providing more detailed instructions.

Project: Secure Online Bookstore with Jenkins CI/CD

Objective: Implement a secure RESTful API for an Online Bookstore using Java, Spring Boot, Apache Kafka. The bookstore should allow users to view, add, update, and delete books, and place orders that are processed asynchronously through a message queue. Use Jenkins for Continuous Integration and Deployment.

Requirements and Instructions:

  1. Initialize a Spring Boot project: Use Spring Initializr to create a new Spring Boot project. For dependencies, select: Web, JPA, H2, Cache, Spring for Apache Kafka, Spring Security, Spring AOP, and Lombok.

  2. Set up your project structure: Organize your project into packages based on its components. This can improve readability and maintainability.

  3. Implement the domain model: Create Book, Order, and User classes in your model package. Make sure to use proper annotations for your JPA entities (@Entity, @Id, @GeneratedValue, etc.).

  4. Create the repositories: Implement the BookRepository, OrderRepository, and UserRepository interfaces in your repository package, each extending JpaRepository.

  5. Develop the service layer: Create BookService, OrderService, and UserService classes in your service package. These should contain your main business logic. Use Spring's @Autowired annotation to inject the repositories into the services.

  6. Implement the REST API controllers: In your controller package, create BookController, OrderController, and UserController classes. These should handle HTTP requests and call the appropriate service methods. Again, use @Autowired to inject the services into the controllers.

  7. Develop DTOs for the API: In the dto package, create BookDTO, OrderDTO, and UserDTO classes. These will help with data transfer between the different layers of your application.

  8. Handle exceptions: In your exception package, create custom exception classes as needed. Implement a global exception handler using @ControllerAdvice to handle these exceptions and return appropriate HTTP response status codes.

  9. Configure an H2 database: In your application.properties file, configure an H2 in-memory database for your application. This will be used for testing and development.

  10. Set up caching: Configure Spring's caching mechanism to cache book information. This can help reduce the load on your database.

  11. Set up Kafka: In your OrderService, set up a Kafka producer and consumer. The producer should send orders to a Kafka topic when they are placed, and the consumer should process these orders asynchronously.

  12. Implement AOP: Use Aspect-Oriented Programming to separate cross-cutting concerns, such as logging or security, from the main business logic of your application.

  13. Set up Spring Security: Configure Spring Security to handle authentication. Only authenticated users should be able to place orders.

  14. Write tests: Use JUnit and Mockito to write unit tests for your service classes. This will help ensure that your code is working as expected.

  15. Set up Jenkins: Install Jenkins on your local machine or a server. Create a new Jenkins job for your project, and configure it to pull from your Git repository and build your project whenever changes are pushed.

  16. Automate testing and deployment: Configure your Jenkins job to run your unit tests and deploy your application if the tests pass. You can use the Jenkins Pipeline syntax to script these steps

.

  1. Document your API: Optionally, use a tool like Swagger or OpenAPI to document your API.

Deliverables:

  • The complete source code for your application, including tests.
  • A README.md file with:
    • Instructions on how to build and run your application.
    • A brief explanation of your design choices.
    • A description of how to use your API (you can also provide a Swagger/OpenAPI specification for this).
  • A screenshot or text output showing a successful Jenkins build and deployment.

Remember to commit often and write clear, informative commit messages. This will make it easier for the reviewers to understand your development process. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment