# funcy-ict/funcy_portfolio_backend architecture

> Architecture diagram of the GitHub repository funcy-ict/funcy_portfolio_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/funcy-ict/funcy_portfolio_backend
- Repository: https://github.com/funcy-ict/funcy_portfolio_backend

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Clients
    Client["Client (UI/Mobile)"]:::client

    %% Main Application - Interface Layer
    subgraph "Interface Layer (API)"
        API_Hndlr["HTTP Handlers (app/interfaces/handler)"]:::interface
        API_Middleware["Middleware (app/interfaces/middleware)"]:::interface
        API_Request["Request Definitions (app/interfaces/request)"]:::interface
        API_Response["Response Definitions (app/interfaces/response)"]:::interface
        API_Server["Server Initialization (app/interfaces/server.go)"]:::interface
    end

    %% Main Application - Use Case Layer
    subgraph "Use Case Layer"
        UseCase["Business Logic (app/usecase)"]:::usecase
    end

    %% Main Application - Domain Layer
    subgraph "Domain Layer"
        Domain_Entities["Entities (app/domain/entity)"]:::domain
        Domain_Repo["Repository Interfaces (app/domain/repository)"]:::domain
    end

    %% Main Application - Infrastructure Layer
    subgraph "Infrastructure Layer"
        Infra["Repository Implementations (app/infrastructure)"]:::infrastructure
    end

    %% Main Application - Configuration & Utilities
    subgraph "Configuration & Utilities"
        Config["Configurations (app/configs)"]:::config
        Utils["Utility Packages (app/packages)"]:::config
    end

    %% Main Application - Database & Deployment
    subgraph "Database & Deployment"
        Migrations["Migrations (db/migrate & db/migration/sql)"]:::deployment
        DB_Config["DB Configuration (db/mysql/my.cnf)"]:::deployment
        Swagger["API Docs (swagger/swagger.yaml)"]:::deployment
        Docker["Deployment Files (Dockerfile, docker-compose.yml, Makefile)"]:::deployment
    end

    %% File Server (Separate Microservice)
    subgraph "File Server (Microservice)"
        FS_Config["Configuration (file-server/config/config.go)"]:::fileServer
        FS_Controller["Controller (file-server/pkg/controller/file.go)"]:::fileServer
        FS_Server["Server Initialization (file-server/pkg/server.go)"]:::fileServer
        FS_View["Views (file-server/pkg/view/file.go)"]:::fileServer
        FS_Upload["POST /upload/file Endpoint"]:::fileServer
    end

    %% Connections for Main Application
    Client -->|"calls"| API_Hndlr
    API_Hndlr -->|"invokes"| UseCase
    UseCase -->|"calls"| Domain_Repo
    Domain_Repo -->|"implemented by"| Infra
    Config -->|"configures"| API_Server
    Config -->|"sets up"| Infra
    Utils -->|"supports"| UseCase
    Infra -->|"DB operations"| DB_Config
    DB_Config -->|"managed by"| Migrations
    Docker -->|"deploys"| API_Server
    Swagger -->|"documents"| API_Hndlr

    %% Connections for File Server
    Client -->|"file upload"| FS_Server
    FS_Config -->|"configures"| FS_Server
    FS_Server -->|"routes to"| FS_Controller
    FS_Controller -->|"renders"| FS_View
    FS_Server -->|"exposes"| FS_Upload

    %% Click Events for Component Mapping
    click Domain_Entities "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/domain/entity"
    click Domain_Repo "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/domain/repository"
    click UseCase "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/usecase"
    click Infra "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/infrastructure"
    click API_Hndlr "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/interfaces/handler"
    click API_Middleware "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/interfaces/middleware"
    click API_Request "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/interfaces/request"
    click API_Response "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/interfaces/response"
    click API_Server "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/app/interfaces/server.go"
    click Config "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/configs"
    click Utils "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/app/packages"
    click Migrations "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/db/migrate"
    click DB_Config "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/db/mysql/my.cnf"
    click Swagger "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/swagger/swagger.yaml"
    click Docker "https://github.com/funcy-ict/funcy_portfolio_backend/tree/develop/Dockerfile"
    click FS_Config "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/file-server/config/config.go"
    click FS_Controller "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/file-server/pkg/controller/file.go"
    click FS_Server "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/file-server/pkg/server.go"
    click FS_View "https://github.com/funcy-ict/funcy_portfolio_backend/blob/develop/file-server/pkg/view/file.go"

    %% Styles
    classDef client fill:#F4E542,stroke:#333,stroke-width:2px;
    classDef interface fill:#8ED1FC,stroke:#333,stroke-width:2px;
    classDef usecase fill:#B2F2BB,stroke:#333,stroke-width:2px;
    classDef domain fill:#FFADAD,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#C9C9FF,stroke:#333,stroke-width:2px;
    classDef config fill:#FDFD96,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FDC7C7,stroke:#333,stroke-width:2px;
    classDef fileServer fill:#A0E7E5,stroke:#333,stroke-width:2px;
```
