# ducshntrong/dacs3_banxe architecture

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

- Interactive diagram: https://gitdiagram.com/ducshntrong/dacs3_banxe
- Repository: https://github.com/ducshntrong/dacs3_banxe

## Overview

##### Project type and purpose
- This is an Android mobile e-commerce application (Java) for buying electric bikes and bicycles.
- It provides product browsing, search, cart management, checkout, user authentication, and order history.
- It uses Retrofit to call an external RESTful API backed by a MySQL database.

##### File structure
- app/ – Android Studio module containing all application code and resources.
– src/main/java/com/example/banhang/
· activity/ – UI screens (Activities) for each feature (Main, Details, Cart, Checkout, Login, Register, etc.).
· adapter/ – RecyclerView adapters mapping model data into list/grid items.
· model/ – POJO model classes and “Model” helper classes; includes EventBus events.
· retrofit/ – Network layer (ApiBanHang interface, RetrofitClient factory).
· Interface/ – callback interfaces for click events.
· utils/ – utility functions (e.g., network checks, formatting).
– src/main/res/ – XML layouts, drawables, anims, values and other resources.
– src/androidTest & src/test – instrumentation and unit tests.
- build.gradle, settings.gradle, Gradle wrapper files – build and configuration.

##### README for additional insights
- Confirms Java + MySQL usage (backend not in this repo).
- Describes main screens and workflows via screenshots.

a. Mobile Application (Android client)
– UI Layer: Activities & XML layouts
– Presentation Layer: Adapters, Click Listeners, EventBus events
– Data Layer: RetrofitClient + ApiBanHang interface, Utils
– Model Layer: Model classes (e.g., SanPhamMoiModel, UserModel) mapping JSON ↔ Java objects
b. External Services
– REST API Server (HTTP endpoints)
– MySQL Database behind the API
c. Data Flow & Interaction
– User taps UI → Activity triggers Adapter click listener → calls Data Layer
– RetrofitClient issues HTTP request → API Server → MySQL → JSON response
– Retrofit parses JSON → Model objects → EventBus or callback → UI updates

##### Architectural patterns and design principles
- Layered architecture: UI → Presentation → Data → External Services
- Separation of concerns: Activities handle view logic, Adapters handle list binding, Models handle data, Retrofit handles networking
- Callback-driven interactions via interfaces (ItemClickListener, IImageClickListener) and EventBus for decoupling

##### Technologies, frameworks, and libraries
- Java, Android SDK
- Retrofit2 for HTTP client
- Gson / Moshi (via Retrofit) for JSON serialization
- RecyclerView + Adapters for dynamic lists
- EventBus (org.greenrobot:eventbus) for intra-app events
- MySQL (external) as persistence

- External REST API Server and MySQL Database.
- Callouts for key dependencies (Retrofit2, EventBus, RecyclerView).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Mobile Application"
        subgraph "UI Layer"
            MA["MainActivity"]:::ui
            CTA["ChiTietActivity"]:::ui
            GA["GioHangActivity"]:::ui
            TTA["ThanhToanActivity"]:::ui
            DLA["DangNhapActivity"]:::ui
            DK["DangKiActivity"]:::ui
            XA["XemDonActivity"]:::ui
            Layouts["Layouts (XML)"]:::ui
        end
        subgraph "Presentation Layer"
            SPA["SanPhamMoiAdapter"]:::presentation
            CTAp["ChiTietAdapter"]:::presentation
            GAa["GioHangAdapter"]:::presentation
            DA["DonHangAdapter"]:::presentation
            LSA["LoaiSpAdapter"]:::presentation
            LA["loaiAdapter"]:::presentation
            XDA["xeDapAdapter"]:::presentation
            ICL["ItemClickListener"]:::presentation
            IICL["IImageClickListenner"]:::presentation
            TTE["TinhTongEvent"]:::presentation
        end
        subgraph "Data Layer"
            RC["RetrofitClient"]:::network
            API["ApiBanHang"]:::network
            Utils["Utils"]:::network
        end
        subgraph "Model Layer"
            SP["SanPhamMoi & SanPhamMoiModel"]:::model
            US["User & UserModel"]:::model
            DH["DonHang & DonHangModel"]:::model
            LS["LoaiSp & LoaiSpModel"]:::model
            GH["GioHang"]:::model
            IT["Item"]:::model
        end
    end

    subgraph "External Services"
        API_S["REST API Server"]:::external
        DB["MySQL Database"]:::external
    end

    %% Data flow
    MA -->|"user action"| SPA
    CTA -->|"user action"| CTAp
    GA -->|"user action"| GAa
    TTA -->|"user action"| DA
    DLA -->|"user action"| ICL
    DK -->|"user action"| IICL
    XA -->|"user action"| TTE

    SPA -->|"adapter callback"| RC
    CTAp -->|"adapter callback"| RC
    GAa -->|"adapter callback"| RC
    DA -->|"adapter callback"| RC
    LSA -->|"adapter callback"| RC
    LA -->|"adapter callback"| RC
    XDA -->|"adapter callback"| RC

    RC -->|"HTTP request"| API_S
    API_S -->|"SQL query"| DB
    DB -->|"JSON data"| API_S
    API_S -->|"JSON response"| RC

    RC -->|"parse JSON"| SP
    RC -->|"parse JSON"| US
    RC -->|"parse JSON"| DH
    RC -->|"parse JSON"| LS
    RC -->|"parse JSON"| GH
    RC -->|"parse JSON"| IT

    SP -->|"model update"| TTE
    US -->|"model update"| TTE
    DH -->|"model update"| TTE
    LS -->|"model update"| TTE
    GH -->|"model update"| TTE
    IT -->|"model update"| TTE

    TTE -->|"eventbus"| MA
    TTE -->|"eventbus"| CTA
    TTE -->|"eventbus"| GA
    TTE -->|"eventbus"| TTA
    TTE -->|"eventbus"| DLA
    TTE -->|"eventbus"| DK
    TTE -->|"eventbus"| XA

    %% Click events
    click MA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/MainActivity.java"
    click CTA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/ChiTietActivity.java"
    click GA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/GioHangActivity.java"
    click TTA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/ThanhToanActivity.java"
    click DLA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/DangNhapActivity.java"
    click DK "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/DangKiActivity.java"
    click XA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/activity/XemDonActivity.java"
    click Layouts "https://github.com/ducshntrong/dacs3_banxe/tree/master/app/src/main/res/layout/"

    click SPA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/SanPhamMoiAdapter.java"
    click CTAp "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/ChiTietAdapter.java"
    click GAa "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/GioHangAdapter.java"
    click DA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/DonHangAdapter.java"
    click LSA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/LoaiSpAdapter.java"
    click LA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/loaiAdapter.java"
    click XDA "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/adapter/xeDapAdapter.java"
    click ICL "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/Interface/ItemClickListener.java"
    click IICL "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/Interface/IImageClickListenner.java"
    click TTE "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/EventBus/TinhTongEvent.java"

    click RC "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/retrofit/RetrofitClient.java"
    click API "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/retrofit/ApiBanHang.java"
    click Utils "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/utils/Utils.java"

    click SP "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/SanPhamMoi.java"
    click SP "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/SanPhamMoiModel.java"
    click US "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/User.java"
    click US "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/UserModel.java"
    click DH "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/DonHang.java"
    click DH "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/DonHangModel.java"
    click LS "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/LoaiSp.java"
    click LS "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/LoaiSpModel.java"
    click GH "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/GioHang.java"
    click IT "https://github.com/ducshntrong/dacs3_banxe/blob/master/app/src/main/java/com/example/banhang/model/Item.java"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,stroke-width:1px
    classDef presentation fill:#DFF5D8,stroke:#22863A,stroke-width:1px
    classDef network fill:#FFEFD5,stroke:#D2691E,stroke-width:1px
    classDef model fill:#EADFFD,stroke:#6F42C1,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#6A737D,stroke-width:1px,stroke-dasharray: 3 3
```
