How ljgago/educabot-challenge works
Project Type and Purpose
• This is a backend service developed in Go.
• Its purpose is to handle HTTP requests (via handlers), process business logic (services), access and manipulate data (repositories and providers), and model domain entities (models). There is also a testing/mocking layer (mockImpls) for ensuring functionality.
• The README specifically instructs implementing an HTTP client to fetch books from an external service (https://6781684b85151f714b0aa5db.mockapi.io/api/v1/books).
Main Components
a. Entry Point:
• main.go: This file is the bootstrapper that wires the custom components together.
b. Presentation Layer:
• Handlers (handlers/metrics_handlers.go and its test counterpart) which currently house both presentation and some business logic. The refactoring is focused on separating out the business logic.
c. Business Logic:
• Services (services/metrics_service.go) that manage core operations, including handling metrics.
d. Data Access / External Integration:
• Providers (providers/books_provider.go) — responsible for the HTTP client fetching external data.
• Repositories (repositories/books_repository.go) — abstract data storage/retrieval logic and probably convert or interface with models.
e. Domain Models:
• Models (models/books_model.go) for defining the structure of book-related entities.
f. Testing and Mocks:
• Mock Implementations (mockImpls directory) providing stubs for books and error cases used in testing.
Architectural Relationships and Interactions
• main.go: Acts as the starting point. It initializes the HTTP server and assembles routes, connecting handlers with the underlying services.
• Handlers: Receive HTTP requests, extract the necessary context (ensuring correct context usage) and forward calls to the services.
• Services: Contain business logic, coordinate with repositories for data persistence/retrieval, and possibly call out to providers for external data.
• Providers: Specifically implement the integration to fetch book data from an external API. This should include managing HTTP calls and error handling per the challenge.
• Repositories: Act as a clean abstraction layer between business logic and the actual data models, ensuring separation of responsibilities.
• Domain Models: Shared definitions used across the layers to represent book data.
• Mocks: Facilitate testing by simulating external service responses or error conditions.