# harutouizumi/group12 architecture

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

- Interactive diagram: https://gitdiagram.com/harutouizumi/group12
- Repository: https://github.com/harutouizumi/group12

## Overview

1. **System shape**
   - AuctionHub is a single Java 17/Maven codebase with two runtime roles: a **JavaFX client** and an optional **TCP server**.
   - Persistence is via **SQLite** (`auction.db` in production, `test_auction.db` in tests).
   - The same project supports both **standalone local execution** and **client–server multi-machine execution**.

2. **Entry points and launch paths**
   - `auction.MainApp` is the client entry point.
   - `auction.server.ServerMain` / `AuctionServer` start the backend server.
   - Shell/batch scripts (`start.sh`, `run_server.sh`, etc.) wrap build and launch concerns, but do not change the core architecture.

3. **Presentation layer**
   - The UI is built with **JavaFX 21** using a mix of **FXML** and Java-based pages/controllers.
   - Main UI structure lives under `auction.ui`: `pages`, `components`, `controller`, and `MainLayout`.
   - `login.fxml` and `auction_list.fxml` are the main FXML-bound views; `style.css` provides shared styling.

4. **Session, login, and role-based UI**
   - `auction.session.Session` holds the current authentication state and user context.
   - The application distinguishes **ADMIN**, **SELLER**, and **BIDDER** roles through the model layer.
   - Page classes such as `AdminPage`, `SellerProfilePage`, `BidderProfilePage`, and `ProfilePage` indicate role-specific navigation and functionality.

5. **Domain model**
   - Core entities are under `auction.model`, centered on `User`, `Auction`, `Item`, and `BidTransaction`.
   - `Item` has category-specific subclasses: `ElectronicsItem`, `ArtItem`, and `VehicleItem`.
   - `AuctionStatus` models lifecycle state, while `Admin`, `Seller`, and `Bidder` specialize user behavior.

6. **Factories and object creation**
   - `UserFactory` and `ItemFactory` create role- and category-specific model instances.
   - These factories are the main boundary for translating user input or database data into typed domain objects.

7. **Persistence boundary**
   - Data access is split by DAO interfaces (`AuctionDAO`, `UserDAO`) and concrete implementations in `dao.impl`.
   - `auction.db.Database` and `DatabaseInit` manage SQLite connection/configuration and initial seeding.
   - The README indicates default accounts are created automatically on first run, and passwords are stored hashed via `PasswordUtil` (SHA-256).

8. **Bid transaction flow**
   - The critical business operation is `placeBid`, implemented in `AuctionDAOImpl`.
   - That flow validates auction status, balance, and bid rules; updates the current leader; refunds the previous leader; deducts the new bid amount; and records the transaction in one database transaction.
   - This makes the DAO layer the central transactional boundary for auction state changes.

9. **Server-side networking**
   - In client–server mode, clients communicate through `auction.network` and `auction.server`.
   - `Protocol` defines the message contract between client and server.
   - `ClientHandler` handles each connected client thread, `AuctionServer` accepts connections, and `ServerBroadcaster` fan-outs updates to all clients.

10. **Real-time update path**
   - A bid submitted from the UI reaches the server, is persisted, then triggers a broadcast back to all connected clients.
   - This is the key runtime data flow for the “realtime bidding” behavior described in the README.
   - `ServerConnection` and `ConnectionManager` represent the client-side transport boundary.

11. **Background services and time-based behavior**
   - `AuctionScheduler` handles periodic auction maintenance, including automatic closing/checking of auctions.
   - The README also mentions anti-sniping behavior and cross-process refresh support; those concerns are reflected in service classes such as `CrossProcessRefreshService`.
   - `LogService` is the shared logging boundary for operational events.

12. **Observer-driven notifications**
   - `BidEventManager` and `BidObserver` implement an observer pattern around bid events.
   - `LogObserver` and `UIRefreshObserver` show that bid changes can trigger both logging and UI refresh actions.
   - This sits between business logic and side effects, especially for real-time feedback.

13. **Error handling**
   - Domain-specific exceptions are explicit: `InvalidBidException`, `AuctionClosedException`, `InsufficientBalanceException`, and `AuthenticationException`.
   - These exceptions define the main failure boundaries for bidding and login flows, and they help the UI and server return user-facing errors cleanly.

14. **Quality and verification**
   - Unit tests cover DAO behavior, protocol handling, factories, observer logic, scheduler behavior, exceptions, and password hashing.
   - CI is configured via GitHub Actions, so the repository has automated build/test validation around these core layers.

15. **How to draw the architecture**
   - A useful diagram should show: **JavaFX UI → session/controller → client network layer → server handler → DAO/SQLite**, with a side path for **broadcast/observer notifications** back to all clients.
   - Keep the **DAO + SQLite** boundary as the persistence core, and the **server/broadcast layer** as the concurrency/realtime core.

Main entry points: [`src/main/java/auction/server/ClientHandler.java`](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ClientHandler.java) (Client handler), [`src/main/java/auction/dao/impl/AuctionDAOImpl.java`](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/dao/impl/AuctionDAOImpl.java) (Auction DAO), [`src/main/java/auction/ui/MainLayout.java`](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/ui/MainLayout.java) (Main layout), [`src/main/java/auction/ui/controller`](https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/controller) (Controllers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_mainapp(("Main app<br/>JavaFX entry<br/>[MainApp.java]"))
  node_ui_layout["Main layout<br/>UI shell<br/>[MainLayout.java]"]
  node_ui_pages["Pages"]
  node_ui_components["Components<br/>UI widgets"]
  node_ui_ctrl["Controllers"]
  node_session(("Session<br/>auth state<br/>[Session.java]"))
end

subgraph group_runtime["Runtime"]
  node_client_conn["Client conn<br/>transport client"]
  node_server_main(("Server main<br/>server entry<br/>[ServerMain.java]"))
  node_auction_server["Auction server<br/>tcp acceptor<br/>[AuctionServer.java]"]
  node_client_handler["Client handler<br/>per-client worker<br/>[ClientHandler.java]"]
  node_broadcaster["Broadcaster<br/>fan-out"]
  node_protocol["Protocol<br/>message contract<br/>[Protocol.java]"]
end

subgraph group_core["Core"]
  node_auction_dao[("Auction DAO<br/>persistence boundary")]
  node_user_dao[("User DAO<br/>persistence boundary<br/>[UserDAOImpl.java]")]
  node_database[("SQLite DB<br/>sqlite access<br/>[Database.java]")]
  node_model["Domain model<br/>entities"]
  node_factories["Factories<br/>object creation"]
  node_scheduler["Scheduler<br/>maintenance service"]
  node_refresh["Refresh service<br/>cross-process sync"]
end

subgraph group_support["Support"]
  node_log_service["Log service<br/>ops logging<br/>[LogService.java]"]
  node_password_util(("Password util<br/>crypto helper<br/>[PasswordUtil.java]"))
end

node_mainapp -->|"starts"| node_ui_layout
node_ui_layout -->|"navigates"| node_ui_pages
node_ui_layout -->|"composes"| node_ui_components
node_ui_pages -->|"binds"| node_ui_ctrl
node_ui_ctrl -->|"reads state"| node_session
node_ui_ctrl -->|"sends bid"| node_client_conn
node_client_conn -->|"encodes"| node_protocol
node_server_main -->|"boots"| node_auction_server
node_auction_server -->|"spawns"| node_client_handler
node_client_handler -->|"decodes"| node_protocol
node_client_handler -->|"persists bid"| node_auction_dao
node_client_handler -->|"broadcasts"| node_broadcaster
node_auction_dao -->|"uses"| node_database
node_user_dao -->|"uses"| node_database
node_auction_dao -->|"maps"| node_model
node_user_dao -->|"creates"| node_factories
node_factories -->|"instantiates"| node_model
node_scheduler -->|"closes auctions"| node_auction_dao
node_refresh -->|"triggers sync"| node_broadcaster
node_log_service -->|"records events"| node_broadcaster
node_password_util -->|"hashes"| node_user_dao

click node_mainapp "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/MainApp.java"
click node_ui_layout "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/ui/MainLayout.java"
click node_ui_pages "https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/pages"
click node_ui_components "https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/components"
click node_ui_ctrl "https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/controller"
click node_session "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/session/Session.java"
click node_client_conn "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/client/ConnectionManager.java"
click node_server_main "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ServerMain.java"
click node_auction_server "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/AuctionServer.java"
click node_client_handler "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ClientHandler.java"
click node_broadcaster "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ServerBroadcaster.java"
click node_protocol "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/network/Protocol.java"
click node_auction_dao "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/dao/impl/AuctionDAOImpl.java"
click node_user_dao "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/dao/impl/UserDAOImpl.java"
click node_database "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/db/Database.java"
click node_model "https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/model"
click node_factories "https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/factory"
click node_scheduler "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/service/AuctionScheduler.java"
click node_refresh "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/service/CrossProcessRefreshService.java"
click node_log_service "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/service/LogService.java"
click node_password_util "https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/util/PasswordUtil.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mainapp,node_ui_layout,node_ui_pages,node_ui_components,node_ui_ctrl,node_session toneBlue
class node_client_conn,node_server_main,node_auction_server,node_client_handler,node_broadcaster,node_protocol toneAmber
class node_auction_dao,node_user_dao,node_database,node_model,node_factories,node_scheduler,node_refresh toneMint
class node_log_service,node_password_util toneRose
```

## Components

### Presentation

JavaFX UI, pages, and session state.

- [Main app](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/MainApp.java): JavaFX entry · Client entry point. · `src/main/java/auction/MainApp.java`
- [Main layout](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/ui/MainLayout.java): UI shell · Top-level JavaFX navigation and composition. · `src/main/java/auction/ui/MainLayout.java`
- [Pages](https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/pages): UI pages · Role-specific and workflow screens. · `src/main/java/auction/ui/pages`
- [Components](https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/components): UI widgets · Reusable JavaFX widgets and small view parts. · `src/main/java/auction/ui/components`
- [Controllers](https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/ui/controller): FXML controllers · FXML-bound UI controllers for login and listings. · `src/main/java/auction/ui/controller`
- [Session](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/session/Session.java): auth state · Current user context and login state. · `src/main/java/auction/session/Session.java`

### Runtime

Client networking and server-side request handling.

- [Client conn](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/client/ConnectionManager.java): transport client · Client-side connection manager for server communication. · `src/main/java/auction/client/ConnectionManager.java`
- [Server main](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ServerMain.java): server entry · Backend launcher for the TCP server. · `src/main/java/auction/server/ServerMain.java`
- [Auction server](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/AuctionServer.java): tcp acceptor · Accepts client connections and coordinates server runtime. · `src/main/java/auction/server/AuctionServer.java`
- [Client handler](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ClientHandler.java): per-client worker · Handles one connected client connection. · `src/main/java/auction/server/ClientHandler.java`
- [Broadcaster](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/server/ServerBroadcaster.java): fan-out · Pushes server updates to connected clients. · `src/main/java/auction/server/ServerBroadcaster.java`
- [Protocol](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/network/Protocol.java): message contract · Shared client-server message format. · `src/main/java/auction/network/Protocol.java`

### Core

Domain model, factories, persistence, and services.

- [Auction DAO](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/dao/impl/AuctionDAOImpl.java): persistence boundary · Auction queries and transactional bid updates. · `src/main/java/auction/dao/impl/AuctionDAOImpl.java`
- [User DAO](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/dao/impl/UserDAOImpl.java): persistence boundary · User lookup and account persistence. · `src/main/java/auction/dao/impl/UserDAOImpl.java`
- [SQLite DB](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/db/Database.java): sqlite access · Database connection and initialization boundary. · `src/main/java/auction/db/Database.java`
- [Domain model](https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/model): entities · Users, auctions, items, and bid transactions. · `src/main/java/auction/model`
- [Factories](https://github.com/harutouizumi/group12/tree/main/src/main/java/auction/factory): object creation · Creates typed users and item variants. · `src/main/java/auction/factory`
- [Scheduler](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/service/AuctionScheduler.java): maintenance service · Background auction maintenance and closing. · `src/main/java/auction/service/AuctionScheduler.java`
- [Refresh service](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/service/CrossProcessRefreshService.java): cross-process sync · Supports cross-process refresh behavior. · `src/main/java/auction/service/CrossProcessRefreshService.java`

### Support

Utility and operational boundaries.

- [Log service](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/service/LogService.java): ops logging · Shared logging boundary for operational events. · `src/main/java/auction/service/LogService.java`
- [Password util](https://github.com/harutouizumi/group12/blob/main/src/main/java/auction/util/PasswordUtil.java): crypto helper · Password hashing utility used for stored credentials. · `src/main/java/auction/util/PasswordUtil.java`

## Connections

- Main app → Main layout: starts · Launches the JavaFX shell.
- Main layout → Pages: navigates · Hosts role-specific screens.
- Main layout → Components: composes · Uses reusable UI widgets.
- Pages → Controllers: binds · FXML pages connect to controllers.
- Controllers → Session: reads state · Controllers consult login and role context.
- Controllers → Client conn: sends bid · UI actions reach the transport layer.
- Client conn → Protocol: encodes · Client messages follow the shared protocol.
- Server main → Auction server: boots · Server entry starts the backend.
- Auction server → Client handler: spawns · Creates a worker per connected client.
- Client handler → Protocol: decodes · Handles protocol messages from clients.
- Client handler → Auction DAO: persists bid · Bid operations reach the transactional DAO.
- Client handler → Broadcaster: broadcasts · Server updates fan out after state changes.
- Auction DAO → SQLite DB: uses · DAO reads and writes SQLite.
- User DAO → SQLite DB: uses · User persistence goes through SQLite.
- Auction DAO → Domain model: maps · Persists domain entities and auction state.
- User DAO → Factories: creates · Converts stored data into typed users.
- Factories → Domain model: instantiates · Builds concrete domain objects.
- Scheduler → Auction DAO: closes auctions · Background maintenance updates auction state.
- Refresh service → Broadcaster: triggers sync · Supports cross-process refresh behavior.
- Log service → Broadcaster: records events · Operational events are logged around updates.
- Password util → User DAO: hashes · Passwords are hashed before persistence.
