# adelaveres/bookstore-spring-angular architecture

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

- Interactive diagram: https://gitdiagram.com/adelaveres/bookstore-spring-angular
- Repository: https://github.com/adelaveres/bookstore-spring-angular

## Overview

##### Main Components
- Frontend Client: Represented by the AngularJS app, static assets (JavaScript, CSS), and Freemarker templates (in the src/main/resources/templates folder). This covers the user interfaces for login, employee view, and admin view.
- Backend (Application Server): Based on Spring Boot, it includes controllers (AppController, RestApiController), service classes (BookService, EmployeeService, LoginService, and report generation mechanisms like PdfReport and CsvReport), and model classes (Book, Employee, LoginAccount, etc.).
- Service Layer: Encapsulated in the “services” package. It contains business logic (such as selling books, updating employee records, and generating reports) and acts as an intermediary between controllers and models.
- Data/Model Layer: Contained in the “model” package, which represents domain entities like books, employees, and login accounts.
- Integration/Utility Components: This includes utility classes (like CustomErrorType), configuration files (application.properties), and external libraries (such as the iText library for PDF generation).

##### Relationships and Interactions
- The Frontend client (AngularJS and Freemarker templates) sends user requests (like login, CRUD operations on books/employees) to the Backend.
- Controllers in the Spring Boot application receive these requests and delegate them to the corresponding Service Layer components.
- Services perform the necessary business logic (including validations, report generation, and data manipulation) and interact with domain models.
- Although there is no explicit database directory indicated, the domain model and possibly the application.properties file hint at data persistence (which may be in-memory or connected to an actual database).
- External libraries (e.g., com.lowagie.text for PDF generation) are used by services when creating reports.

##### Architectural Patterns to Highlight
- Layered (n-tier) architecture: With separate layers for presentation (frontend), business logic (service layer), and data (model layer).
- MVC Pattern: The controllers (in com.bookstore.controller) act as the intermediaries between the view (FTL templates and AngularJS-based UI) and the model.
- Dependency Injection: Employed by Spring Boot to wire together controllers, services, and utilities.
- Report Generation: Notable use of a Report Factory pattern for handling different report types (PDF and CSV), suggesting extensibility in the reporting mechanism.

##### Relevant Technologies, Frameworks, and Libraries
- Spring Boot for the backend application framework.
- AngularJS for the client-side dynamic scripting.
- Bootstrap and CSS for UI styling.
- Maven (pom.xml) for dependency management and build configuration.
- External libraries such as com.lowagie.text for PDF creation.
- Freemarker (ftl files) for dynamic webpage rendering.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        FE1("AngularJS Client"):::frontend
        FE2("Freemarker Templates"):::frontend
        FE3("Static Assets"):::frontend
    end

    subgraph "Backend Layer"
        subgraph "Controller Layer"
            C1("AppController"):::controller
            C2("RestApiController"):::controller
        end

        subgraph "Service Layer"
            S1("BookService"):::service
            S2("EmployeeService"):::service
            S3("LoginService"):::service
            subgraph "Report Generation Module"
                R1("ReportFactory"):::report
                R2("PdfReport"):::report
                R3("CsvReport"):::report
            end
        end

        subgraph "Data/Model Layer"
            M1("Book"):::model
            M2("Employee"):::model
            M3("LoginAccount"):::model
        end
    end

    subgraph "Integration/Utility"
        I1("CustomErrorType"):::utility
        I2("application.properties"):::utility
    end

    %% Connections from Frontend to Controller
    FE1 -->|"HTTP_Request"| C1
    FE1 -->|"HTTP_Request"| C2
    FE2 -->|"Rendered_View"| C1
    FE3 -->|"Rendered_View"| C2

    %% Controller delegations to Service Layer
    C1 -->|"delegatesTo"| S1
    C1 -->|"delegatesTo"| S2
    C2 -->|"delegatesTo"| S3
    C2 -->|"delegatesTo"| R1
    
    %% Report Generation usage
    R1 -->|"uses"| R2
    R1 -->|"uses"| R3

    %% Services interact with Model Layer
    S1 -->|"updatesQueries"| M1
    S2 -->|"updatesQueries"| M2
    S3 -->|"authenticates"| M3

    %% Integration and Utility interactions
    S1 -->|"handlesErrors"| I1
    S2 -->|"handlesErrors"| I1
    C1 -->|"configFrom"| I2
    C2 -->|"configFrom"| I2

    %% Styles
    classDef frontend fill:#C5E1A5,stroke:#33691E,stroke-width:2px;
    classDef controller fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef service fill:#FFE082,stroke:#FF6F00,stroke-width:2px;
    classDef report fill:#FFCDD2,stroke:#B71C1C,stroke-width:2px;
    classDef model fill:#D1C4E9,stroke:#4A148C,stroke-width:2px;
    classDef utility fill:#CFD8DC,stroke:#455A64,stroke-width:2px;

    %% Click Events
    click FE2 "https://github.com/adelaveres/bookstore-spring-angular/tree/master/src/main/resources/templates"
    click FE3 "https://github.com/adelaveres/bookstore-spring-angular/tree/master/src/main/resources/static"
    click C1 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/controller/AppController.java"
    click C2 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/controller/RestApiController.java"
    click S1 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/services/BookService.java"
    click S2 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/services/EmployeeService.java"
    click S3 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/services/LoginService.java"
    click R1 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/services/ReportFactory.java"
    click R2 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/services/PdfReport.java"
    click R3 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/services/CsvReport.java"
    click M1 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/model/Book.java"
    click M2 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/model/Employee.java"
    click M3 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/model/LoginAccount.java"
    click I1 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/java/com/bookstore/util/CustomErrorType.java"
    click I2 "https://github.com/adelaveres/bookstore-spring-angular/blob/master/src/main/resources/application.properties"
```
