# abhinandpn/project-ecom architecture

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

- Interactive diagram: https://gitdiagram.com/abhinandpn/project-ecom
- Repository: https://github.com/abhinandpn/project-ecom

## Overview

##### Project Type & Purpose
- This is a backend project written in Go for an e-commerce platform. The project follows a Clean Architecture design, as indicated by the README’s clean architecture image and the clear separation into different layers (handler, usecase, domain, repository, etc.). Its purpose is to expose an API (likely RESTful) that handles e-commerce operations such as product management, order processing, user authentication, and payment administration.

##### Main Components of the System
- API Server:
- Located under cmd/api with the main.go file. It is the entry point that initializes the server and likely sets up routing based on definitions in pkg/api/routes.
- HTTP Handlers (Presentation Layer):
- Found in pkg/api/handler. These are responsible for receiving requests and returning responses. They delegate business operations to the usecase layer.
- Routing & Middleware:
- The routing files in pkg/api/routes (e.g., admin.go, user.go) and middleware in pkg/api/middleware (like auth.go) handle request routing and processes such as authentication.
- Usecase / Business Logic Layer:
- Under pkg/usecase, this layer contains the core business rules and application logic for e-commerce operations (admin, cart, coupon, order, payment, product, and user use cases). Usecase interfaces also ensure abstraction and loose coupling.
- Domain Models:
- Found in pkg/domain, the project defines primary business entities (admin, coupon, order, payment, product, user) that encapsulate the data and rules.
- Repository / Data Access Layer:
- Found in pkg/repository, these modules manage the persistence (e.g., admin.go, cart.go, coupon.go, etc.). Separate interfaces (located under pkg/repository/interface) are used to isolate data storage details.
- Configuration and Dependency Injection:
- The configuration management is handled by pkg/config/config.go. There’s also a dependency injection setup under pkg/di (using tools like wire) to manage the wiring of various modules.
- External Services Integration:
- The pkg/Twillio package suggests integration with Twilio for OTP (one-time-password) functionalities, which is common in authentication flows.
- Utility Layers:
- Helper functions (pkg/helper), request and response formatters (pkg/util/req and pkg/util/res) help to manage common functionalities and data transformation across the application.

##### Relationships and Interactions
- Client requests first enter through the API server’s main entry (cmd/api/main.go).
- Requests are routed using definitions in pkg/api/routes, which pass through middleware (such as auth from pkg/api/middleware) before reaching the handler functions found in pkg/api/handler.
- Handlers invoke business logic encapsulated in the usecase layer (pkg/usecase), which then operates on domain models (pkg/domain) and interacts with the repository layer (pkg/repository) for data persistence.
- External integrations (like Twilio for OTP) are invoked as needed from the corresponding pkg/Twillio components.
- Dependency injection (via pkg/di) ensures that these layers are properly wired and decoupled, following the Clean Architecture principles.

##### Final Touches
- Components are clearly labeled.
- Optionally, include notes on configuration management (pkg/config), which modulates the behavior of the application, and mention the role of the Makefile and CI configurations (from the .github/workflows directory) that assist in building, testing, and deploying the system.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% API Entry Point
    A["API Server"]:::api

    %% Presentation Layer
    subgraph "Presentation Layer"
        R["Routes"]:::presentation
        M["Middleware"]:::presentation
        H["HTTP Handlers"]:::presentation
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        U["Use Cases"]:::business
        D["Domain Models"]:::business
    end

    %% Data Access Layer
    subgraph "Data Access"
        REP["Repositories"]:::data
        RI["Repository Interfaces"]:::data
        DB["Persistent Storage"]:::data
    end

    %% Infrastructure & External Services
    subgraph "Infrastructure"
        CFG["Configuration"]:::infra
        DI["Dependency Injection"]:::infra
        T["Twilio OTP"]:::infra
        subgraph "Utility Layers"
            HLP["Helpers"]:::infra
            REQ["Request Formatters"]:::infra
            RES["Response Formatters"]:::infra
        end
    end

    %% Flow Connections
    A -->|"API_Request"| R
    R -->|"Route_Filter"| M
    M -->|"Auth_Check"| H
    H -->|"Business_Call"| U
    U -->|"Domain_Operation"| D
    U -->|"Data_Query"| REP
    REP -->|"DB_Query"| DB
    H -->|"OTP_Integration"| T
    H -->|"Use_Helper"| HLP
    H -->|"Format_Request"| REQ
    H -->|"Format_Response"| RES

    %% Dependency Injection wiring
    DI -->|"Wires_Handler"| H
    DI -->|"Wires_UseCase"| U
    DI -->|"Wires_Repository"| REP
    CFG -->|"Configures_API"| A

    %% Click Events
    click A "https://github.com/abhinandpn/project-ecom/blob/main/cmd/api/main.go"
    click R "https://github.com/abhinandpn/project-ecom/tree/main/pkg/api/routes"
    click M "https://github.com/abhinandpn/project-ecom/blob/main/pkg/api/middleware/auth.go"
    click H "https://github.com/abhinandpn/project-ecom/tree/main/pkg/api/handler"
    click U "https://github.com/abhinandpn/project-ecom/tree/main/pkg/usecase"
    click D "https://github.com/abhinandpn/project-ecom/tree/main/pkg/domain"
    click REP "https://github.com/abhinandpn/project-ecom/tree/main/pkg/repository"
    click RI "https://github.com/abhinandpn/project-ecom/tree/main/pkg/repository/interface"
    click CFG "https://github.com/abhinandpn/project-ecom/blob/main/pkg/config/config.go"
    click DI "https://github.com/abhinandpn/project-ecom/tree/main/pkg/di"
    click T "https://github.com/abhinandpn/project-ecom/blob/main/pkg/Twillio/TwilioOtp.go"
    click HLP "https://github.com/abhinandpn/project-ecom/tree/main/pkg/helper"
    click REQ "https://github.com/abhinandpn/project-ecom/tree/main/pkg/util/req"
    click RES "https://github.com/abhinandpn/project-ecom/tree/main/pkg/util/res"

    %% Styles
    classDef api fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef presentation fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef business fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef infra fill:#f8d7da,stroke:#333,stroke-width:2px;
```
