How ltphat2204/goauth works
Main Components
• HTTP/API Layer (Transport): Represent the HTTP request handlers (in the users/transport directory) handling endpoints like /token, /verify, and CRUD operations on users.
• Middlewares: Indicate components that handle tasks such as admin validation and authentication (in the middlewares directory).
• Business (Service) Layer: Show the business logic for user operations (users/business), such as creating users, deleting users, token retrieval, password update, etc.
• Data Access (Storage) Layer: Represent components that interact with the MySQL database (users/storage and common/mysql.go). This includes functions to create, retrieve, update, and delete user data.
• Domain/Entity Layer: Include the definitions for the domain models (in users/entity) which outline the structure of User, UserAccess, UserStatus, etc.
• Common Utilities: Illustrate supporting modules available in the common directory (for tokens, unified error/success responses, MySQL model enhancement).
• External Dependencies & Infrastructure: Include MySQL (highlighted in docker-compose.yml) as well as Docker containerization elements (Dockerfile, docker-compose.yml) that deploy and run the service.
Relationships & Data Flow
• The client (external user, admin, or any system) sends requests to the service endpoints.
• Requests first pass through the Middlewares which handle authentication (auth.go) and admin validation (admin.go).
• Once validated, the requests are routed to specific HTTP handlers (transport) that process the API calls.
• HTTP handlers then call the Business (Service) layer functions which contain the core business rules.
• The Business layer interacts with the Storage layer for operations like CRUD, token issuance, and so on, which in turn communicate with the MySQL database.
• Responses (success or error) are standardized using common response functions and then sent back to the client.
• Additionally, JWT token generation and validation occur through functions defined in the common directory to ensure secure authorization.
Architectural Patterns and Design Principles
• Clean Architecture: This is evident by how the project separates concerns into transport, business logic, and storage while keeping the domain (entity) pure.
• Layered Design: The strict separation helps manage dependencies – for example, UI (HTTP handlers) never access the database directly, and business logic doesn’t handle HTTP details.
• Dependency Injection (Implicitly): The architecture implies that you could swap out the MySQL implementation (by modifying common/mysql.go and users/storage) without affecting the business logic.
• Containerization: Use of Docker (Dockerfile, docker-compose.yml) shows that the service and its dependencies (MySQL) run in separate containers, illustrating modern deployment practices.
• Component has a clear label and that the dependencies (such as JWT in the common module and MySQL connectivity) are represented.