How s21platform/avatar-service works
Main Components
• Service Entrypoint: The “cmd/service/main.go” file indicates where the service is started.
• Configuration Module: The “internal/config” folder (with files like config.go and keys.go) is responsible for initializing application settings.
• Business Logic: Found in “internal/service” (service.go and contract.go), this layer contains the core logic for avatar operations.
• Data Models: The “internal/model” directory defines core data structures (e.g., avatar_info.go).
• Infrastructure and Utilities: The “internal/infra” folder contains modules for logging, authentication, and metrics.
• Persistence / Repositories:
• PostgreSQL: “internal/repository/postgres” handles database operations (e.g., storing the avatar metadata, user UUIDs, timestamps).
• S3: “internal/repository/s3” deals with uploading images and managing links via Yandex S3.
• Migrations: The “migrations” directory contains SQL scripts and docker-related files for managing database schema changes.
• External Services: As described in the README, these include:
• Yandex S3 for physical image storage.
• PostgreSQL for metadata and audit purposes.
• Kafka for sending messages upon avatar updates.
• Webp conversion library for image processing.
Determining Relationships and Interactions
• Entry Point Flow: The service starts in cmd/service/main.go, which initializes configuration and then starts the core service.
• The Business Logic (internal/service) acts as the orchestrator—it handles avatar changes, calls upon the repository layers, and triggers side effects.
• The Repository Layers interact with external systems:
• The PostgreSQL repository handles read/write operations to the database.
• The S3 repository interacts with Yandex S3 for storing avatar images.
• The service layer may trigger the Webp conversion process (via the go-webp library) before uploading images.
• After critical operations (like an avatar change), a Kafka producer sends a message to an external USER-SERVICE (using the segmentio/kafka-go library).
• The infrastructure components (auth, logger, and metrics) are used across modules for enhanced monitoring, security, and logging.
Architectural Patterns and Design Principles
• Layered Architecture: The project is structured into distinct layers (configuration, business logic, repository, and infrastructure), which facilitates separation of concerns.
• Dependency Injection & Abstraction: By separating repository implementations and service contracts, testing and further extensions are simplified.
• External Service Integration: Clearly defined integration points with external systems, such as S3, PostgreSQL, Kafka, and image processing tools.
Final Recommendations
• Be very detailed–capture every critical component and the interactions between them.