How vsrecorder/core-apiserver works
Main Components Identification
• Core API Server: This is the entrypoint (located in the cmd/core-apiserver directory with main.go) where the application boots up, loads configuration, and sets up routing.
• Controller Layer: Under internal/controller, this layer handles incoming HTTP requests (for various resources like “deck”, “match”, “official_event”, “record”, “tonamel_event”, “user” as well as authentication/authorization). This component is responsible for dealing with input DTOs and validating requests.
• Use Case (Application) Layer: Found under internal/usecase. This layer implements business logic for each domain (deck, game, match, etc.) and orchestrates interactions between controllers and domain logic.
• Domain Layer: Under internal/domain (further subdivided into entity and repository directories), this layer defines business entities (e.g., deck, game, match, etc.) and repository interface contracts.
• Infrastructure Layer: Under internal/infrastructure, this layer provides concrete implementations for the repository interfaces. It includes integrations with external services like Postgres (internal/infrastructure/postgres) and Firebase (internal/infrastructure/firebase), as well as model definitions.
• External Components:
• Database: The project has a “db” folder containing schema.sql, and there are Docker configurations indicating that a database (likely PostgreSQL) is part of the deployment.
• Third-Party Services: The Firebase client in internal/infrastructure/firebase shows integration with Firebase.
• Testing & Mocks: The internal directory also contains mock implementations (internal/mock) for repository and usecase, demonstrating a layered test strategy.
Relationships and Data Flow
• At runtime, the Core API Server (main.go) initializes the server and configures routes mapped to various controllers.
• The Controller layer receives HTTP requests, performs necessary request validations (including parsing and authorization) and then calls the appropriate Use Case functions.
• Use Cases encapsulate the business rules and interact with Domain Entities. They delegate data access operations to repository interfaces.
• The Infrastructure layer provides concrete implementations of these repository interfaces by connecting to PostgreSQL (or Firebase) to persist or retrieve data.
• Data (entities) flows from the Infrastructure (data persistence) back up to the Domain, then processed by Use Cases, and finally formatted by Controllers to respond to the API client.
Architectural Patterns and Design Principles
• Clean Architecture / Hexagonal Architecture: The separation into controllers, use cases, domain, and infrastructure shows a clear separation of concerns and dependency inversion – the core business logic is isolated from peripheral concerns.
• Repository Pattern: Domain repositories are defined in the domain layer and then implemented in the infrastructure layer to interact with data sources.
• Testing Strategy: Presence of mocks indicates that the project is designed with testability in mind.
Important Inclusions
• Clearly separate each of the following elements:
• Core API Server (cmd/core-apiserver)
• Controller Layer (internal/controller & its sub-components such as auth, deck, match, etc.)
• DTOs and Presenters (for input/output transformation)
• Use Case Layer (internal/usecase)
• Domain Layer (internal/domain/entities and repositories)
• Infrastructure Layer (internal/infrastructure including postgres and Firebase modules)
• Testing/Mock components (can be mentioned in notes as they show the design’s emphasis on testability)
• External Dependencies (Database schema from db/schema.sql and third-party integrations like Firebase)
• Containerization/Deployment Components (Dockerfile, docker-compose, and GitHub workflows)
Final Recommendations
• That every component is clearly labeled with its directory name or function.
• Clean architecture by grouping dependent components in clusters; for example, group all controllers together.