# ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang architecture

> Architecture diagram of the GitHub repository ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang
- Repository: https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang

## Overview

##### Project type and purpose
- This is a Go-based backend REST API service. It exposes user and product endpoints, applies business logic (e.g. scoring), persists data in a relational database (via raw SQL in `db_queries`), and integrates with two external AI APIs (Gemini and Hface).

##### File structure
- cmd/serve.go & main.go: application entrypoints
- config/: configuration loader
- rest/: HTTP layer
- handlers/…: per-resource handler implementations
- middlewares/: cross-cutting concerns (auth, CORS, logging)
- logic/: core business rules (e.g. scoring.go)
- repo/: data access layer (user, product, score)
- db_queries/: SQL scripts
- utils/: JWT issuance, token validation

##### README
- Minimal content; no architecture section—so deduce layers/directions from code layout.

- Blue = HTTP & Routing
- Green = Business Logic
- Orange = Data Access
- Gray = External Services

##### Essential details to capture
- Configuration loading at startup (config/config.go)
- Middleware sequence (auth → cors → logger → manager)
- Handler grouping by resource (user vs. product)
- Logic layer’s scoring component
- Repository layer’s SQL scripts and DB interactions
- Two external AI integrations

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client"]:::external
    subgraph "Go Application"
        direction TB
        Config["Config Loader\n(config/config.go)"]:::http
        Serve["Serve Entrypoint\n(cmd/serve.go)"]:::http
        Main["Main Entrypoint\n(main.go)"]:::http
        HTTP["HTTP Server\n(router)"]:::http

        subgraph "Middleware Layer"
            direction TB
            Auth["Auth Middleware"]:::http
            Cors["CORS Middleware"]:::http
            Logger["Logger Middleware"]:::http
            Manager["Manager Middleware"]:::http
        end

        subgraph "Handlers Layer"
            direction TB
            subgraph "User Handlers"
                direction TB
                URoutes["User Routes\n(routes.go)"]:::http
                UHandler["User Handler\n(handler.go)"]:::http
                CreateUser["Create User"]:::http
                LoginUser["Login User"]:::http
                UpdateUser["Update User"]:::http
            end
            subgraph "Product Handlers"
                direction TB
                PRoutes["Product Routes\n(routes.go)"]:::http
                PHandler["Product Handler\n(handler.go)"]:::http
                GetProduct["Get Product"]:::http
                SearchProduct["Search Product"]:::http
                RequestProduct["Request Product"]:::http
                UpdateProduct["Update Product"]:::http
                Gemini["Gemini API"]:::external
                Hface["Hface API"]:::external
            end
        end

        Logic["Scoring Logic\n(scoring.go)"]:::logic

        subgraph "Repository Layer"
            direction TB
            RepoUser["User Repo\n(repo/user.go)"]:::data
            RepoProduct["Product Repo\n(repo/product.go)"]:::data
            RepoScore["Score Repo\n(repo/score.go)"]:::data
        end

        UtilsJWT["JWT Utility\n(utils/jwt.go)"]:::utils
        Validate["Validate Token\n(utils/validate_token.go)"]:::utils
    end

    subgraph "Database Scripts"
        direction TB
        dbUserSQL["user.sql"]:::data
        dbProductSQL["product.sql"]:::data
        dbTokenSQL["token.sql"]:::data
    end

    DB["Relational Database"]:::data

    Client --> HTTP
    Config --> HTTP
    Serve --> HTTP
    Main --> HTTP

    HTTP --> Auth --> Cors --> Logger --> Manager
    Manager --> URoutes
    Manager --> PRoutes

    URoutes --> UHandler
    UHandler --> CreateUser
    UHandler --> LoginUser
    UHandler --> UpdateUser

    PRoutes --> PHandler
    PHandler --> GetProduct
    PHandler --> SearchProduct
    PHandler --> RequestProduct
    PHandler --> UpdateProduct

    CreateUser --> Logic
    LoginUser --> Logic
    UpdateUser --> Logic
    GetProduct --> Logic
    SearchProduct --> Logic
    RequestProduct --> Logic
    UpdateProduct --> Logic

    Logic --> RepoUser
    Logic --> RepoProduct
    Logic --> RepoScore

    RepoUser --> dbUserSQL --> DB
    RepoProduct --> dbProductSQL --> DB
    RepoScore --> dbTokenSQL --> DB

    PHandler --> Gemini
    PHandler --> Hface

    Auth --> UtilsJWT
    Auth --> Validate

    click Config "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/config/config.go"
    click Serve "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/cmd/serve.go"
    click Main "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/main.go"
    click Auth "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/middlewares/auth.go"
    click Cors "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/middlewares/cors.go"
    click Logger "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/middlewares/logger.go"
    click Manager "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/middlewares/manager.go"
    click URoutes "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/user/routes.go"
    click UHandler "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/user/handler.go"
    click CreateUser "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/user/create_user.go"
    click LoginUser "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/user/login_user.go"
    click UpdateUser "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/user/update_user.go"
    click PRoutes "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/routes.go"
    click PHandler "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/handler.go"
    click GetProduct "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/get_product.go"
    click SearchProduct "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/search_product.go"
    click RequestProduct "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/request_product.go"
    click UpdateProduct "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/update_prdct.go"
    click Gemini "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/gemini_api.go"
    click Hface "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/rest/handlers/product/hface_api.go"
    click Logic "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/logic/scoring.go"
    click RepoUser "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/repo/user.go"
    click RepoProduct "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/repo/product.go"
    click RepoScore "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/repo/score.go"
    click dbUserSQL "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/db_queries/user.sql"
    click dbProductSQL "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/db_queries/product.sql"
    click dbTokenSQL "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/db_queries/token.sql"
    click UtilsJWT "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/utils/jwt.go"
    click Validate "https://github.com/ecoscanai/ecoscan-an-eco-friendly-product-scanner-golang/blob/main/utils/validate_token.go"

    classDef http fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef logic fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef data fill:#FFE7B1,stroke:#333,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef utils fill:#F0F0F0,stroke:#333,stroke-width:1px
```
