mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 02:51:34 +00:00
Key changes include:
- **Architectural Refactoring (CQRS/DTOs):** Refactored the `work` and `translation` application services to use Data Transfer Objects (DTOs) for query responses. This separates the domain layer from the API layer, improving maintainability and performance.
- **Implemented Core Business Logic:** Implemented the `AnalyzeWork` command, which was previously a stub. This command now performs linguistic analysis on works and translations by calling the analytics service.
- **Dependency Injection Improvements:**
- Refactored the configuration loading in `internal/platform/config/config.go` to use a local `viper` instance, removing the reliance on a global singleton.
- Injected the `analytics.Service` into the `work.Service` to support the `AnalyzeWork` command.
- **Comprehensive Documentation:**
- Created a new root `README.md` with a project overview, setup instructions, and architectural principles.
- Added detailed `README.md` files to key packages (`api`, `analytics`, `auth`, `work`, `db`) to document their purpose and usage.
- **Improved Test Coverage:**
- Added new unit tests for the refactored `work` and `translation` query handlers.
- Added a new test suite for the `translation` queries, which were previously untested.
- Added tests for the new `AnalyzeWork` command.
- Fixed numerous compilation errors in the test suites caused by the refactoring.
52 lines
2.4 KiB
Markdown
52 lines
2.4 KiB
Markdown
# Auth Service
|
|
|
|
This package handles all user authentication and session management for the Tercul platform. It is responsible for registering new users, authenticating existing users, and managing JSON Web Tokens (JWTs).
|
|
|
|
## Architecture Overview
|
|
|
|
The auth service is designed to be a self-contained unit for all authentication-related logic. It provides a clear API for other parts of the application to interact with user sessions.
|
|
|
|
### Key Components
|
|
|
|
- **`service.go`**: The main entry point for the auth service. It implements the `Service` interface and contains the core business logic for registration, login, logout, and token management.
|
|
|
|
- **`commands.go`**: Contains the command handlers for all authentication-related actions, such as:
|
|
- `Register`: Creates a new user account.
|
|
- `Login`: Authenticates a user and issues a JWT.
|
|
- `Logout`: Invalidates a user's session.
|
|
- `RefreshToken`: Issues a new JWT for an active session.
|
|
- `ForgotPassword` / `ResetPassword`: Handles the password reset flow.
|
|
- `VerifyEmail` / `ResendVerificationEmail`: Manages email verification.
|
|
- `ChangePassword`: Allows an authenticated user to change their password.
|
|
|
|
- **`interfaces.go`**: Defines the `Service` and `AuthRepository` interfaces, establishing a clear contract for the service's capabilities and its data persistence requirements.
|
|
|
|
- **`jwt.go` (in `internal/platform/auth`)**: The service relies on the `JWTManager` from this platform package to handle the creation and validation of JWTs.
|
|
|
|
## Usage
|
|
|
|
The `auth.Service` is primarily used by the GraphQL resolvers to handle authentication-related mutations.
|
|
|
|
### Example: User Registration
|
|
|
|
```go
|
|
// In a GraphQL resolver
|
|
registerInput := auth.RegisterInput{...}
|
|
authResponse, err := authService.Commands.Register(ctx, registerInput)
|
|
```
|
|
|
|
### Example: User Login
|
|
|
|
```go
|
|
// In a GraphQL resolver
|
|
loginInput := auth.LoginInput{...}
|
|
authResponse, err := authService.Commands.Login(ctx, loginInput)
|
|
```
|
|
|
|
## Dependencies
|
|
|
|
- **`internal/domain`**: Uses the core `User` domain entity.
|
|
- **`internal/platform/auth`**: Relies on the `JWTManager` to handle all JWT operations. This is a critical dependency for session management.
|
|
- **Database**: Persists user data via the `UserRepository`.
|
|
- **Logging**: Uses the centralized logger from `internal/platform/log`.
|
|
- **OpenTelemetry**: All service and command methods are instrumented for distributed tracing. |