# fiskra/sample-web-service architecture

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

- Interactive diagram: https://gitdiagram.com/fiskra/sample-web-service
- Repository: https://github.com/fiskra/sample-web-service

## Overview

##### Project type and purpose
- This is a SIMPLE WEB SERVICE PROJECT built with Spring Boot. It exposes RESTful endpoints for “User” and “Bookmark” resources via HTTP.
- It uses Java 8, Maven, Spring-Boot (web, JPA, security), Jersey, H2 in-memory DB, and an Angular.js front end (mentioned in README).

##### File structure
- Top-level files:
- pom.xml (Maven build configuration)
- LICENSE, readMe.md
- src/main/java/com/fiskra/ws
- SampleWsApplication.java – the Spring-Boot entry point
- ServletInitializer.java – for servlet container bootstrapping
- controller/BookmarkController.java & UserController.java – REST endpoints (presentation layer)
- model/Bookmark, BookmarkResource, User – JPA entities & HATEOAS resource wrappers
- repo/BookmarkRepository, UserRepository – Spring Data JPA repositories (data access layer)
- src/main/resources/application.properties – runtime configuration
- src/main/resources/import.sql – initial data load into H2
- src/test – integration/unit tests

##### Key architecture patterns & design principles
- Layered (tiered) architecture:
- Presentation layer (REST controllers)
- Business/domain model (entities & resource assemblers)
- Data access layer (Spring Data repositories)
- Persistence (H2 in-memory DB)
- Follows MVC-like separation for a REST API.
- Dependency Injection via Spring.
- Uses JPA for ORM; H2 for ephemeral development DB.
- REST HATEOAS principles (BookmarkResource) for enriched hypermedia responses.

##### Main components
a. External Clients
- Angular.js front-end (or any HTTP client / REST client)
- Curl/Postman for testing
b. Spring-Boot Application
- Embedded servlet container (Tomcat/Jetty)
- ServletInitializer
- SampleWsApplication (main)
c. REST Controllers
- UserController
- BookmarkController
d. Service/Resource Assemblers (optionally show BookmarkResource)
e. Data Access Layer
- UserRepository
- BookmarkRepository
f. Persistence
- H2 in-memory database
- import.sql pre-loading
g. Tests
- SampleWsApplicationTests (integration test)

##### Relationships & data flow
1) Client → HTTP request → Embedded Servlet Container
2) Container → SampleWsApplication context
3) Controller (UserController / BookmarkController) mapped via Jersey/Spring MVC
4) Controller calls Repository (UserRepository / BookmarkRepository)
5) Repository ↔ JPA ↔ H2 Database
6) Controller assembles response (possibly via BookmarkResource) and returns JSON/XML to client

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        AngularClient["Angular.js Frontend"]:::frontend
        CurlClient["HTTP Client (curl/Postman)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        subgraph "Embedded Servlet Container (Tomcat/Jetty)"
            SampleWsApp["SampleWsApplication\n(Spring Boot Entry)"]:::backend
            ServletInit["ServletInitializer"]:::backend
        end
        UserCtrl["UserController\n(REST Endpoint)"]:::backend
        BookmarkCtrl["BookmarkController\n(REST Endpoint)"]:::backend
    end

    %% Domain Layer
    subgraph "Domain Layer"
        UserEntity["User\n(JPA Entity)"]:::backend
        BookmarkEntity["Bookmark\n(JPA Entity)"]:::backend
        BookmarkRes["BookmarkResource\n(HATEOAS Resource)"]:::backend
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        UserRepo["UserRepository\n(Spring Data JPA)"]:::backend
        BookmarkRepo["BookmarkRepository\n(Spring Data JPA)"]:::backend
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        H2db["H2 In-Memory DB"]:::persistence
        ImportSql["import.sql\n(Data Initialization)"]:::persistence
        ApplicationProps["application.properties\n(Configuration)"]:::config
    end

    %% Testing
    subgraph "Testing"
        Tests["SampleWsApplicationTests\n(Integration Tests)"]:::tests
    end

    %% Top-level files
    pom["pom.xml"]:::config
    readMe["readMe.md"]:::config
    License["LICENSE"]:::config

    %% Connections
    AngularClient -->|"HTTP Request"| SampleWsApp
    CurlClient -->|"HTTP Request"| SampleWsApp
    SampleWsApp --> ServletInit
    SampleWsApp --> UserCtrl
    SampleWsApp --> BookmarkCtrl
    UserCtrl --> UserRepo
    BookmarkCtrl --> BookmarkRepo
    BookmarkCtrl --> BookmarkRes
    UserRepo -->|"JPA Queries"| H2db
    BookmarkRepo -->|"JPA Queries"| H2db
    ImportSql -->|"Pre-load Data"| H2db
    ApplicationProps --> SampleWsApp
    Tests --> UserCtrl
    Tests --> BookmarkCtrl

    %% Click Events
    click SampleWsApp "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/SampleWsApplication.java"
    click ServletInit "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/ServletInitializer.java"
    click UserCtrl "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/controller/UserController.java"
    click BookmarkCtrl "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/controller/BookmarkController.java"
    click UserEntity "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/model/User.java"
    click BookmarkEntity "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/model/Bookmark.java"
    click BookmarkRes "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/model/BookmarkResource.java"
    click UserRepo "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/repo/UserRepository.java"
    click BookmarkRepo "https://github.com/fiskra/sample-web-service/blob/master/src/main/java/com/fiskra/ws/repo/BookmarkRepository.java"
    click ApplicationProps "https://github.com/fiskra/sample-web-service/blob/master/src/main/resources/application.properties"
    click ImportSql "https://github.com/fiskra/sample-web-service/blob/master/src/main/resources/import.sql"
    click Tests "https://github.com/fiskra/sample-web-service/blob/master/src/test/java/com/fiskra/ws/SampleWsApplicationTests.java"
    click pom "https://github.com/fiskra/sample-web-service/blob/master/pom.xml"
    click readMe "https://github.com/fiskra/sample-web-service/blob/master/readMe.md"
    click License "https://github.com/fiskra/sample-web-service/tree/master/LICENSE"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#21618C,color:#1B4F72
    classDef backend fill:#ABEBC6,stroke:#1D8348,color:#145A32
    classDef persistence fill:#F9E79F,stroke:#B9770E,color:#7D6608
    classDef config fill:#D5D8DC,stroke:#566573,color:#1C2833
    classDef tests fill:#E8DAEF,stroke:#8E44AD,color:#4A235A
```
