# thanhchuong0410/interview architecture

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

- Interactive diagram: https://gitdiagram.com/thanhchuong0410/interview
- Repository: https://github.com/thanhchuong0410/interview

## Overview

##### Project Type and Purpose
- This is a Go-based backend microservice (RESTful API server) built with the Gin framework.
- Its primary function is to expose CRUD and custom‐search endpoints for tables like products, suppliers, categories, plus an export feature.
- It serves HTTPS on port 8080 with a static token-based authentication middleware and provides Swagger docs.

##### File Structure
- Top-level:
- main.go – application entry point, starts Gin HTTP server with TLS.
- go.mod/go.sum – module dependencies.
- README.md – setup and API documentation.
- output.pdf – probably generated API report or example.
- Directories:
- app/ – model definitions (model_base, model_categories, model_products, etc.).
- authentication/ – custom token check middleware.
- cert/ – TLS certificate and key.
- config/ – configuration loader (config.go).
- database/ – database connection logic (database.go).
- docs/ – Swagger definitions (swagger.json/yaml) and docs.go stub.

##### README for Additional Insights
- Uses `gin` in HTTPS mode: `[GIN-debug] Listening and serving HTTPS on :8080`.
- Token auth via `Authorization` header.
- API routes under `/api` namespace; methods: POST for custom_search and updates, GET for records.
- Returns structured JSON with `data`, `message`, `metadata`, `status`.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client (Web UI, Postman, Mobile)"]:::client

    %% Server Boundary
    subgraph "API Server"
        direction TB
        Main["Gin Router & HTTPS<br/>(main.go)"]:::compute
        Config["Config Loader<br/>(config/config.go)"]:::compute
        Auth["Auth Middleware<br/>(authentication/authentication.go)"]:::compute
        Handler["Request Handlers<br/>(Controller Layer)"]:::compute
        Service["Business Logic / Service Layer"]:::compute
        DBConn["DB Connection<br/>(database/database.go)"]:::compute
        subgraph "Model Layer"
            direction TB
            ModelBase["Model Base<br/>(app/model_base.go)"]:::compute
            ModelCat["Categories Model<br/>(app/model_categories.go)"]:::compute
            ModelProd["Products Model<br/>(app/model_products.go)"]:::compute
            ModelSupp["Suppliers Model<br/>(app/model_suppliers.go)"]:::compute
            ModelSearch["Custom Search Model<br/>(app/model_custom_search.go)"]:::compute
            ModelExport["Export Feature Model<br/>(app/model_export.go)"]:::compute
        end
    end

    %% TLS Certificates
    subgraph "TLS Certificates"
        direction TB
        CertCRT["cert.crt"]:::document
        CertKEY["cert.key"]:::document
    end

    %% Swagger Documentation
    subgraph "Swagger Docs"
        direction TB
        SwaggerJSON["swagger.json"]:::document
        SwaggerYAML["swagger.yaml"]:::document
        DocsGo["docs.go"]:::document
    end

    %% Static Docs
    README["README.md"]:::document
    Output["output.pdf"]:::document

    %% Database
    DB[(Database)]:::storage

    %% Module Files
    GOmod["go.mod"]:::document
    GOsum["go.sum"]:::document

    %% Relationships
    Client -->|HTTPS JSON| Main
    Main -->|loads config| Config
    Main -->|loads certificates| CertCRT
    Main -->|loads certificates| CertKEY
    Main -->|routes to| Auth
    Auth -->|valid token| Handler
    Handler -->|delegates to| Service
    Service -->|uses| DBConn
    DBConn -->|executes SQL| DB
    Service -->|reads/writes| ModelBase
    Service -->|reads/writes| ModelCat
    Service -->|reads/writes| ModelProd
    Service -->|reads/writes| ModelSupp
    Service -->|reads/writes| ModelSearch
    Service -->|reads/writes| ModelExport
    Handler -->|serves docs| SwaggerJSON
    Handler -->|serves docs| SwaggerYAML
    Handler -->|initializes docs| DocsGo
    Client -->|views docs| README
    Client -->|views example report| Output
    Config -->|dependencies| GOmod
    Config -->|dependencies| GOsum

    %% Click Events
    click Main "https://github.com/thanhchuong0410/interview/blob/main/main.go"
    click Config "https://github.com/thanhchuong0410/interview/blob/main/config/config.go"
    click Auth "https://github.com/thanhchuong0410/interview/blob/main/authentication/authentication.go"
    click DBConn "https://github.com/thanhchuong0410/interview/blob/main/database/database.go"
    click ModelBase "https://github.com/thanhchuong0410/interview/blob/main/app/model_base.go"
    click ModelCat "https://github.com/thanhchuong0410/interview/blob/main/app/model_categories.go"
    click ModelProd "https://github.com/thanhchuong0410/interview/blob/main/app/model_products.go"
    click ModelSupp "https://github.com/thanhchuong0410/interview/blob/main/app/model_suppliers.go"
    click ModelSearch "https://github.com/thanhchuong0410/interview/blob/main/app/model_custom_search.go"
    click ModelExport "https://github.com/thanhchuong0410/interview/blob/main/app/model_export.go"
    click CertCRT "https://github.com/thanhchuong0410/interview/blob/main/cert/cert.crt"
    click CertKEY "https://github.com/thanhchuong0410/interview/blob/main/cert/cert.key"
    click SwaggerJSON "https://github.com/thanhchuong0410/interview/blob/main/docs/swagger.json"
    click SwaggerYAML "https://github.com/thanhchuong0410/interview/blob/main/docs/swagger.yaml"
    click DocsGo "https://github.com/thanhchuong0410/interview/blob/main/docs/docs.go"
    click README "https://github.com/thanhchuong0410/interview/blob/main/README.md"
    click Output "https://github.com/thanhchuong0410/interview/blob/main/output.pdf"
    click GOmod "https://github.com/thanhchuong0410/interview/blob/main/go.mod"
    click GOsum "https://github.com/thanhchuong0410/interview/blob/main/go.sum"

    %% Styles
    classDef compute fill:#cfe2f3,stroke:#0366d6,color:#0366d6
    classDef storage fill:#d1e7dd,stroke:#198754,color:#198754
    classDef document fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef client fill:#fde2e4,stroke:#d6336c,color:#d6336c
```
