How funcy-ict/funcy_portfolio_backend works
Main Components
• Domain Layer: Represented by the app/domain directory.
– Entities: “auth.go”, “comment.go”, “group.go”, “profile.go”, “skill.go”, “sns.go”, “userinfo.go”, “work.go”.
– Repository Interfaces: Indicated in app/domain/repository (e.g., auth_repository.go, comment_repository.go, etc.).
• Use Case Layer: Found in app/usecase. This layer implements business logic (e.g., auth.go, comment.go, etc.) and orchestrates interactions between repositories and interfaces.
• Infrastructure Layer: Under app/infrastructure, with files that implement the repository operations and possibly interact with external systems (such as databases).
• Interface Layer:
– Handlers: In app/interfaces/handler, which define API endpoints for different functionalities.
– Middleware, Request, and Response definitions: Support for processing and validating inbound calls.
– Server: The server initialization file (app/interfaces/server.go) that ties together the HTTP handlers and middlewares.
• Configuration & Packages:
– Configuration files in app/configs (managing DB or other external connections).
– Utility packages under app/packages (e.g., for authentication with JWT, mailing with SendGrid, hashing, and validation).
• Supporting Components:
– Migration and Database Scripts: Under the db directory, showing how the database schema evolves.
– Docker and Makefile: Deployment & container orchestration support.
– Swagger & API Docs: The swagger directory holds the API specification for interactive documentation.
• File Server: A separate service provided in the file-server directory.
– Contains its own configuration, controller, and server code.
– It exposes endpoints (e.g., POST /upload/file) for managing file uploads, illustrated clearly in the README.
Relationships and Interactions
• The handlers delegate to usecase functions (app/usecase) where business rules are enforced.
• Use cases interact with repository interfaces defined in the domain layer. Then, the concrete implementations provided in the infrastructure layer take over to perform operations (e.g., accessing the database).
• The configuration layer (app/configs) supplies necessary settings (e.g., DB connection info) to initialization routines.
• External integrations via utility packages (e.g., auth with JWT, mail using SendGrid) should be drawn as supporting services connected to the infrastructure.
• The file server acts as an independent service, which might be hosted on a different port (3004) and is clearly delineated as an additional microservice handling file uploads. Represent it with its own set of components (controller, server, view).
Architectural Patterns and Design Principles
• Domain-Driven Design (DDD): Separation into domain entities, repository interfaces, and use cases.
• Layered Architecture (a.k.a. Hexagonal or Clean Architecture influences): Clearly differentiating the business logic, transport (interface), and infrastructure.
• REST API design: Emphasized by the API endpoints described in the handler and supported by Swagger documentation.
• Containerization and DevOps: Use of Dockerfile and docker-compose indicates a containerized deployment pattern.