# bui-danh-tung-bengo4/file-uploader architecture

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

- Interactive diagram: https://gitdiagram.com/bui-danh-tung-bengo4/file-uploader
- Repository: https://github.com/bui-danh-tung-bengo4/file-uploader

## Overview

##### Main Components
- Frontend Application:
- Built with Vue (as evident from the “frontend” directory files like App.vue, main.ts, router, components, etc.)
- Handles user interactions for registration, login, file uploads, file lists, search, etc.
- Communicates with backend APIs (using services like FileApiService.ts and UserApiService.ts).
- Backend Application:
- Implemented in Go (files such as main.go, various controllers, services, usecases).
- Divided into functional areas:
- Authentication (under backend/controller/auth and corresponding usecases for login and registration)
- File Management (controllers for file operations, file usecases, repository for file data in MySQL or MinIO storage)
- Notification/SSE (backend/controller/sse and backend/sse directory that manage server-sent events)
- Logging & Error Handling (backend/controller/error and utils for logging request info)
- Architectural layering patterns are visible (controllers → usecases → repositories/infra)
- Database & Storage Components:
- The backend/containers include a directory for database initialization scripts (DDL and test data) suggesting an underlying MySQL database.
- Cloud storage integration is handled via AWS (aws/s3.go and aws/ses.go in infra) and a MinIO implementation is available (in backend/infra/storage/minio). Also, a phpMyAdmin container is provided for easy database viewing.
- External & Containerized Services:
- Docker Compose is used (docker-compose.yml) to manage the multi-container environment.
- GitHub workflows exist to run CI/CD processes.
- Containers include a database server and phpMyAdmin for management.

##### Relationships and Interactions
- The frontend sends HTTP API requests (likely RESTful calls) to the backend.
- The backend controllers act as the entry point for different business operations (authentication, file uploads, file listing, and search).
- Controllers delegate logic to “usecase” packages where business rules are implemented.
- Repositories in the “infra” package (for MySQL and cloud storage like AWS/MinIO) are used by usecases to load or persist model data.
- When a file is uploaded, the backend may interact with cloud storage (e.g., AWS S3 or a MinIO server) as well as with the MySQL database to update file metadata.
- Components such as SSE controllers indicate that real-time notifications or logs may be streamed to the frontend.

##### Architectural Patterns and Principles
- Separation of concerns: The clear division between controllers, use cases, and infra packages shows adherence to layered architecture.
- RESTful API design: The endpoints (as seen in routes.json) are likely designed following RESTful principles.
- Containerization: Docker Compose helps in orchestrating multiple services (database, phpMyAdmin, Go backend, and possibly the frontend if containerized).

##### Relevant Technologies/Frameworks/Libraries
- Frontend: Vue.js, Vite, TypeScript (indicated by .ts and .d.ts files), and Vue Router.
- Backend: Go (with controllers, models, usecases, and repositories), likely using popular libraries for routing and sessions (e.g., Gorilla sessions as seen in mocks), and AWS SDKs for cloud storage operations.
- Database: MySQL (with initialization scripts provided).
- Storage: MinIO for S3 compatible storage and direct AWS integrations.
- CI/CD: GitHub Actions as seen in the .github/workflows/cicd.yml.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend Application"]:::frontend
        API["User & File API Services"]:::services
    end

    %% Backend Layer
    subgraph "Backend Layer"
        Auth["Authentication Module"]:::backend
        FC["File Controller"]:::backend
        FU["File Usecase"]:::backend
        SSECtrl["SSE Controller"]:::backend
        SSENotif["SSE Notifier"]:::backend
        ErrCtrl["Error Controller"]:::backend
        LogUtil["Log Request Utility"]:::backend
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        DBInit["DB Initialization Scripts"]:::database
        DB["MySQL Database"]:::database
        AWS["AWS Cloud Storage"]:::cloud
        Minio["MinIO Storage"]:::storage
        phpMyAdmin["phpMyAdmin"]:::container
    end

    %% Connections from Frontend to Backend
    FE -->|"API_request"| API
    API -->|"calls"| Auth
    API -->|"calls"| FC
    API -->|"subscribes"| SSECtrl

    %% Backend internal flow
    FC -->|"delegates"| FU
    FU -->|"persists_metadata"| DB
    FU -->|"stores_file"| AWS
    FU -->|"stores_file"| Minio

    %% SSE sends notifications
    SSENotif -->|"notification"| FE

    %% Error handling flow
    ErrCtrl -->|"logs"| LogUtil

    %% Click Events
    click FE "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/frontend/"
    click API "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/frontend/src/services/"
    click Auth "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/controller/auth/"
    click FC "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/controller/file/"
    click FU "https://github.com/bui-danh-tung-bengo4/file-uploader/blob/main/backend/usecase/file_usecase.go"
    click SSECtrl "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/controller/sse/"
    click SSENotif "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/sse/"
    click ErrCtrl "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/controller/error/"
    click LogUtil "https://github.com/bui-danh-tung-bengo4/file-uploader/blob/main/backend/controller/shared/log_request_info.go"
    click DBInit "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/containers/db/initdb/"
    click AWS "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/infra/aws/"
    click Minio "https://github.com/bui-danh-tung-bengo4/file-uploader/tree/main/backend/infra/storage/minio/"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef services fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef backend fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef database fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef cloud fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef storage fill:#f5c6cb,stroke:#721c24,stroke-width:2px;
    classDef container fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
