# nhatnhudinh/golden-finger architecture

> Architecture diagram of the GitHub repository nhatnhudinh/golden-finger, 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/nhatnhudinh/golden-finger
- Repository: https://github.com/nhatnhudinh/golden-finger

## Overview

##### Project Type and Purpose
- Project Type: This is a full-stack e-commerce web application built with Jakarta EE.
- Purpose: It provides two distinct experiences—a customer-facing shop interface and an administrative dashboard for managing products, orders, users, categories, suppliers, and sales analytics. Additionally, it integrates external services like VNPay for payment processing and uses SQL Server for data persistence.

##### File Structure to Identify Main Components
- src/java – Contains the application’s backend logic:
- Controller packages: Separate controllers for admin, shop, and user interfaces (e.g., AdminHomeServlet, LoginServlet). They serve as the entry points for HTTP requests.
- DAL (Data Access Layer): DAO classes (e.g., CategoryDAO, OrderDAO, ProductDAO) handle database interactions.
- Model: Entity classes representing domain objects (e.g., Product, Order, User).
- Filter: Request filters (AdminFilter, HomeFilter) enforce authentication and authorization.
- Utils: Utility classes (DBConnect, PasswordUtils, ServletUtils) for common functionality.
- Config and common classes: For payment configuration and VNPay integration.
- web – Contains all web assets:
- JSP pages for both storefront (shop.jsp, product.jsp, checkout.jsp, etc.) and admin dashboard (dashboard folder).
- Assets (CSS, JS, images) that reflect both customer (Tailwind, jQuery) and admin (custom JS/CSS) interfaces.
- WEB-INF configuration: Including web.xml and context.xml, which set up servlet mappings and deploy configurations.
- lib – External libraries (e.g., Jakarta EE libraries, SQL Server JDBC driver, Gson, JAXB, etc.) that support various functionalities.
- build.xml and nbproject – Build configurations (Ant scripts and NetBeans project files) that indicate the Java and Jakarta EE technologies in use.
- script.sql – Contains the SQL scripts for initializing the SQL Server database.

##### System’s Main Components and Their Interactions
- Client Applications (Presentation Layer):
- Web Browser: Users access the e-commerce website through JSP pages.
- Separate interfaces for customers (shopping, cart, checkout, profile) and admins (dashboard, order management, product management).
- Web Server / Application Server:
- Jakarta EE Container (e.g., Apache Tomcat or similar) that hosts the application.
- Servlet Controllers handle incoming HTTP requests and determine whether they go to the customer-facing or admin sections.
- Business Logic and Middleware:
- Controller Layer: Segregates functionality for shop, user, and admin operations.
- Filters: Enforce security (authentication, session management) before reaching the controllers.
- Utility Modules: DBConnect for establishing database connections and PasswordUtils for secure password processing.
- Data Access Layer:
- DAO Classes: Abstract interactions with the SQL Server database, handling CRUD operations on models.
- Database:
- SQL Server Database: Stores all data including user accounts, orders, products, categories, suppliers, etc.
- script.sql for setting up initial schema and data.
- External Services:
- VNPay Integration: Configured within the application (via Config.java) for handling payment transactions.
- Email (javax.mail): For notifications, password recovery, etc.

##### Architectural Patterns and Design Principles
- MVC Pattern: The separation of concerns is visible with JSP views, servlet controllers, and DAO/model backends.
- Layered Architecture: Clear demarcation between presentation, business logic, data access, and integration layers.
- Role-Based Access Control: Implemented via filters and distinct servlet controllers ensuring security.
- Modular Design: Separate packages for controllers, models, DAL, and utilities promote a clean, maintainable codebase.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        C1["Customer Browser Interface"]:::client
        C2["Admin Browser Interface"]:::client
    end

    %% Web Presentation Layer
    WP["Web Presentation Layer<br/>(JSPs & Assets)"]:::web

    %% Application Server
    subgraph "Application Server"
        subgraph "Controller Layer"
            A1["Admin Controller"]:::server
            A2["Shop Controller"]:::server
            A3["User Controller"]:::server
        end
        subgraph "Security & Utilities"
            SU1["Request Filters"]:::server
            SU2["Utility Modules"]:::server
        end
        AL["Domain Model Classes"]:::server
        PI["VNPay Integration"]:::server
    end

    %% Data Access Layer
    DAL["Data Access Layer<br/>(DAO Classes)"]:::dal

    %% Database
    DB["SQL Server Database"]:::db

    %% External Services
    ES["External Services<br/>(VNPay & Email)"]:::ext

    %% Configuration and Build
    AC["Application Configuration<br/>(web.xml, context.xml)"]:::config
    BC["Build / Project Config<br/>(Ant & NetBeans)"]:::config

    %% Connections
    C1 --> WP
    C2 --> WP
    WP -->|"delivers request"| A1
    WP -->|"delivers request"| A2
    WP -->|"delivers request"| A3
    SU1 -->|"secures"| A1
    SU1 -->|"secures"| A2
    SU1 -->|"secures"| A3
    SU2 ---|"supports"| A1
    SU2 ---|"supports"| A2
    SU2 ---|"supports"| A3
    A1 -->|"uses"| AL
    A2 -->|"uses"| AL
    A3 -->|"uses"| AL
    A1 -->|"CRUD"| DAL
    A2 -->|"CRUD"| DAL
    A3 -->|"CRUD"| DAL
    DAL -->|"queries"| DB
    PI -->|"calls"| ES
    AC ---|"configures"| A1
    AC ---|"configures"| A2
    AC ---|"configures"| A3
    BC ---|"builds"| A1
    BC ---|"builds"| A2
    BC ---|"builds"| A3

    %% Click Events
    click A1 "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/controller/admin"
    click A2 "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/controller/shop"
    click A3 "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/controller/user"
    click DAL "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/dal"
    click AL "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/model"
    click SU1 "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/filter"
    click SU2 "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/utils"
    click PI "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/src/java/com/vnpay/common"
    click WP "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/web"
    click DB "https://github.com/nhatnhudinh/golden-finger/blob/main/GoldenFinger/script.sql"
    click AC "https://github.com/nhatnhudinh/golden-finger/tree/main/GoldenFinger/web/WEB-INF"
    click BC "https://github.com/nhatnhudinh/golden-finger/blob/main/GoldenFinger/build.xml"

    %% Styles
    classDef client fill:#aed581,stroke:#4caf50,stroke-width:2px;
    classDef web fill:#81d4fa,stroke:#039be5,stroke-width:2px;
    classDef server fill:#ffe082,stroke:#ffb300,stroke-width:2px;
    classDef dal fill:#ffab91,stroke:#ff7043,stroke-width:2px;
    classDef db fill:#bcaaa4,stroke:#8d6e63,stroke-width:2px;
    classDef ext fill:#ce93d8,stroke:#ab47bc,stroke-width:2px;
    classDef config fill:#fff59d,stroke:#fdd835,stroke-width:2px;
```
