How nvh0610/polyglothub-be works
This project is a backend service written in Go that appears to serve as an API for handling user authentication, vocabulary management, flashcard scheduling, and related functionalities. The file tree showcases a clear layered or modular architecture with directories for controllers, repositories, entities, configuration, middleware, and platform-specific database connectors. Although the README has no content, we can deduce the system’s purpose by reading into the components and file names.
Main Components
• API Gateway/Router: Represented by the internal/router directory—the entry point that directs incoming HTTP requests to the appropriate controller endpoints.
• Controllers: Found in internal/controller, which handles various domains (auth, category, flashcard_daily, user, vocabulary, etc.). These implement business logic and request handling.
• Repository Layer: Housed in internal/repository for data access. Each domain (e.g., category, user, vocabulary) has its own repository, often with interfaces to allow abstraction.
• Entities: Found in internal/entity, representing the data models for business objects.
• Shared/Common Utilities: Directories like pkg (configuration, JWT, middleware, logging, utility functions) provide cross-cutting concerns and shared tools.
• Platform-Specific Integrations: In the platform directory, which includes database connection modules (MySQL, Redis) and an OTP sending service.
• Jobs and Migrations: The job directory (for scheduling tasks) and the migration directory (for database schema management) provide additional support functions.
• Supporting Infrastructure: Files like Dockerfile, Makefile, and GitHub workflows indicate continuous deployment/integration aspects.
Relationships and Interactions
• Incoming requests flow from external clients to the API Gateway (router). The router then routes requests to the appropriate controller based on the URL mapping or API endpoint.
• Controllers process the inputs, use payload/request/response definitions (under internal/router/payload) for validation and formatting, and call underlying repository methods.
• The Repository layer interacts with the physical data storage, such as MySQL (via platform/mysqldb) and caching/data-store like Redis (via platform/redisdb).
• The code also handles authentication via JWTs (in pkg/jwt) and validation/middleware (in pkg/middleware and pkg/utils).
• The layered structure of controllers calling repositories (which then use platform connectors) reflects principles like separation of concerns and dependency inversion.
Architectural Patterns and Design Principles
• Modular Design: Separation of controllers, repositories, entities, and shared packages.
• Layered Architecture / Hexagonal Architecture: Clear boundaries between the presentation (controllers), business logic (services within controllers), and data access layers (repositories).
• Dependency Inversion: Interfaces in controllers and repositories allow for easier testing and replacement of underlying implementations.
• Use of Infrastructure as Code: Docker and CI/CD (GitHub workflows) illustrate modern devops practices.
• Scheduled Jobs: The job/schedule module indicates that background tasks or batch jobs are part of the system.
Visualizing Details
• Use clear labels for each component:
– “Router (internal/router)”
– “Auth Controller, User Controller, etc.”
– “Category Repository,” “User Repository,” etc.
– “Business Entities”
– “MySQL Database (platform/mysqldb)”
– “Redis Cache (platform/redisdb)”
– “JWT Service (pkg/jwt)” and so on.
– From External Clients to the API Gateway.
– From the Router to various Controllers.
– From Controllers to their respective Repository layers.
– From Repositories to external databases (MySQL, Redis) and services (OTP via email).
– A different style for business or service layers (repositories, entities).
– Another distinct representation for external services (databases, email, third-party integrations).
Detail and Granularity
• Architectural elements are captured explicitly. Include supporting modules (configuration, JWT, logging, middleware), as they are crucial to how the system operates.
• Be meticulous in labeling each module, showing data flows and interactions clearly. The goal is to provide a comprehensive view of all layers – from client request to persistent storage.