# ham222/sep3 architecture

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

- Interactive diagram: https://gitdiagram.com/ham222/sep3
- Repository: https://github.com/ham222/sep3

## Overview

##### Project type and purpose
- This is a multi‐tier, full‐stack energy-conservation application called “WE/Save.”
- It uses a Blazor WebAssembly front end (Tier 1), a .NET Core Web API for authentication (also Tier 1), a Java Spring Boot REST/gRPC façade (Tier 2), and a Java Spring Boot gRPC service with a database backend (Tier 3).
- Users log in via the JWT auth server, then view and submit water/electric usage and advice via REST endpoints, which in turn call gRPC services that persist data to a database.

##### Main components
a. Frontend (Tier 1)
- Blazor WASM project (BlazorWasm/)
- UI pages (.razor), shared layouts, custom auth provider
- HTTP service wrappers (AdviceHttpService, UsageHttpService, UserHttpService, JwtAuthService)
b. Authentication Server (Tier 1)
- ASP.NET Core Web API (WebApi/)
- AuthController, AuthService, JWT issuance & validation
- Uses Domain/Models and Shared/Dtos for user, credentials
c. REST API Server (Tier 2)
- Java Spring Boot (tier2/src/main/java/via/sep3/tier2/)
- REST controllers (AuthController, RestApiController)
- Spring Security (JWTFilter/JWTUtil/MyUserDetailsService/SecurityConfig)
- Logic layer (interfaces + servicesImpl)
- Repository interfaces + gRPC‐based implementations
- Protobuf stubs under generatedprotos/ for calling Tier 3
d. gRPC Service Server (Tier 3)
- Java Spring Boot (tier3/)
- gRPC service implementations (AdviceManagement, ResourcesConsumption, UserManagement)
- Database service layer (entity, repository, service implementations)
- Connects to relational DB (configured in application.properties)
e. Shared artifacts
- Protobuf definitions (tier2/src…, tier3/src/main/proto)
- .NET “Shared” and “Domain” libraries for models & DTOs
- .NET HttpClients library (ClientInterface + Implementations)

##### Relationships and data flow
1. User interacts with Blazor UI →
2. Blazor calls ASP.NET Auth API over HTTPS → JWT token returned →
3. Blazor attaches JWT → calls Java Spring REST API endpoints over HTTPS →
4. REST API controllers invoke business services →
5. Business services call repositoryImpl classes →
6. repositoryImpl uses gRPC stubs → calls Tier 3 gRPC services →
7. gRPC service layer interacts with DB →
8. Data flows back up the chain to the frontend.

##### Architectural patterns and principles
- Separation of concerns: UI, auth, API façade, data service
- Backend‐for‐Frontend: Tier 2 provides a tailored REST API for Blazor
- Layered architecture: controllers → services → repositories → data source
- Client‐Server with JWT: stateless auth via bearer tokens
- Service‐oriented / microservice style using gRPC for inter-tier calls
- Shared contracts via Protobuf to ensure strong typing across services

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Tier 1
    subgraph "Tier 1: Frontend & Auth Layer"
        direction TB
        subgraph "BlazorWasm App" 
            direction TB
            Pages["UI Pages"]:::tier1
            SharedUI["Shared Layouts"]:::tier1
            AuthProvider["CustomAuthProvider.cs"]:::tier1
            AdviceHttp["AdviceHttpService.cs"]:::tier1
            UsageHttp["UsageHttpService.cs"]:::tier1
            UserHttp["UserHttpService.cs"]:::tier1
            JwtAuthHttp["JwtAuthService.cs"]:::tier1
            BlazorProg["Program.cs"]:::tier1
            BlazorProj["BlazorWasm.csproj"]:::tier1
        end
        subgraph "ASP.NET Auth API"
            direction TB
            AuthCtrl["AuthController.cs"]:::tier1
            AuthSvc["AuthService.cs"]:::tier1
            IAuthSvc["IAuthService.cs"]:::tier1
            AuthProgram["Program.cs"]:::tier1
            AppSettings["appsettings.json"]:::tier1
            DomainModels["Domain/Models"]:::tier1
            DtosGetWater["GetWaterUsageDto.cs"]:::tier1
            AuthPolicies["AuthorizationPolicies.cs"]:::tier1
            UserLoginDto["UserLoginDto.cs"]:::tier1
            UserRegisterDto["UserRegisterDto.cs"]:::tier1
            SharedUser["Shared/Models/User.cs"]:::tier1
        end
    end

    %% Tier 2
    subgraph "Tier 2: REST API Layer"
        direction TB
        SpringApp["Tier2Application.java"]:::tier2
        WebConfig["WebConfiguration.java"]:::tier2
        AuthController2["AuthController.java"]:::tier2
        RestApiCtrl["RestApiController.java"]:::tier2
        JWTFilter["JWTFilter.java"]:::tier2
        JWTUtil["JWTUtil.java"]:::tier2
        MyUserDetails["MyUserDetailsService.java"]:::tier2
        SecurityCfg["SecurityConfig.java"]:::tier2
        subgraph Logic["Logic Layer"]
            direction TB
            Interfaces["interfaces/*.java"]:::tier2
            ServicesImpl["servicesImpl/*.java"]:::tier2
        end
        subgraph Repos["Repository Layer"]
            direction TB
            RepoInterfaces["Interfaces/*.java"]:::tier2
            RepoImpl["implementations/*.java"]:::tier2
        end
        ProtosStub2["Protobuf Stubs"]:::artifact
    end

    %% Tier 3
    subgraph "Tier 3: gRPC Service & DB"
        direction TB
        Tier3App["Tier3Application.java"]:::tier3
        subgraph GrpcServices["gRPC Services"]
            direction TB
            AdviceMgmt["AdviceManagement.java"]:::tier3
            ResourcesCons["ResourcesConsumption.java"]:::tier3
            UserMgmt["UserManagement.java"]:::tier3
        end
        subgraph DBService["Database Service Layer"]
            direction TB
            Entities["entity/*.java"]:::tier3
            Repositories3["repository/*.java"]:::tier3
            DbServicesImpl["service/implimentations/*.java"]:::tier3
        end
        ProtoDef["definitions.proto"]:::artifact
        Database[(Database)]:::db
    end

    %% Data flows
    Pages -->|"login request (HTTP+JSON)"| AuthCtrl
    AuthCtrl -->|"issues JWT (HTTP+JSON)"| Pages
    Pages -->|"API calls (HTTP+Bearer JWT)"| RestApiCtrl
    RestApiCtrl -->|"calls business services"| ServicesImpl
    ServicesImpl -->|"invokes repository implementations"| RepoImpl
    RepoImpl -->|"gRPC call"| AdviceMgmt
    RepoImpl -->|"gRPC call"| ResourcesCons
    RepoImpl -->|"gRPC call"| UserMgmt
    AdviceMgmt -->|"DB operations"| Entities
    ResourcesCons -->|"DB operations"| Entities
    UserMgmt -->|"DB operations"| Entities
    Entities -->|"persist data"| Database

    %% Protobuf links
    ProtosStub2 --- ProtoDef

    %% Click Events Tier1
    click Pages "https://github.com/ham222/sep3/tree/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Pages"
    click SharedUI "https://github.com/ham222/sep3/tree/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Shared"
    click AuthProvider "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Auth/CustomAuthProvider.cs"
    click AdviceHttp "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Services/Http/AdviceHttpService.cs"
    click UsageHttp "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Services/Http/UsageHttpService.cs"
    click UserHttp "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Services/Http/UserHttpService.cs"
    click JwtAuthHttp "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Services/Http/JwtAuthService.cs"
    click BlazorProg "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/Program.cs"
    click BlazorProj "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/BlazorWasm/BlazorWasm.csproj"
    click AuthCtrl "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/WebApi/Controllers/AuthController.cs"
    click AuthSvc "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/WebApi/Services/AuthService.cs"
    click IAuthSvc "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/WebApi/Services/IAuthService.cs"
    click AuthProgram "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/WebApi/Program.cs"
    click AppSettings "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/WebApi/appsettings.json"
    click DomainModels "https://github.com/ham222/sep3/tree/main/Tier1-Blazor/JwtAuth-master 2/Domain/Models"
    click DtosGetWater "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/Domain/DTOs/GetWaterUsageDto.cs"
    click AuthPolicies "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/Shared/Auth/AuthorizationPolicies.cs"
    click UserLoginDto "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/Shared/Dtos/UserLoginDto.cs"
    click UserRegisterDto "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/Shared/Dtos/UserRegisterDto.cs"
    click SharedUser "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/Shared/Models/User.cs"
    click Interfaces "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/HttpClients/ClientInterface/IWaterService.cs"
    click Repos "https://github.com/ham222/sep3/blob/main/Tier1-Blazor/JwtAuth-master 2/HttpClients/Implementations/WaterHttpClient.cs"

    %% Click Events Tier2
    click SpringApp "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/Tier2Application.java"
    click WebConfig "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/configuration/WebConfiguration.java"
    click AuthController2 "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/rest/AuthController.java"
    click RestApiCtrl "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/rest/RestApiController.java"
    click JWTFilter "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/security/JWTFilter.java"
    click JWTUtil "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/security/JWTUtil.java"
    click MyUserDetails "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/security/MyUserDetailsService.java"
    click SecurityCfg "https://github.com/ham222/sep3/blob/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/security/SecurityConfig.java"
    click Interfaces "https://github.com/ham222/sep3/tree/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/logic/interfaces"
    click ServicesImpl "https://github.com/ham222/sep3/tree/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/logic/servicesImpl"
    click RepoInterfaces "https://github.com/ham222/sep3/tree/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/repository/Interfaces"
    click RepoImpl "https://github.com/ham222/sep3/tree/main/Tier2-JavaSpring/tier2/src/main/java/via/sep3/tier2/repository/implementations"
    click ProtosStub2 "https://github.com/ham222/sep3/tree/main/Tier2-JavaSpring/tier2/src/main/java/via/generatedprotos"

    %% Click Events Tier3
    click Tier3App "https://github.com/ham222/sep3/blob/main/tier3/src/main/java/via/sep3/tier3/Tier3Application.java"
    click AdviceMgmt "https://github.com/ham222/sep3/blob/main/tier3/src/main/java/via/sep3/tier3/grpcservice/AdviceManagement.java"
    click ResourcesCons "https://github.com/ham222/sep3/blob/main/tier3/src/main/java/via/sep3/tier3/grpcservice/ResourcesConsumption.java"
    click UserMgmt "https://github.com/ham222/sep3/blob/main/tier3/src/main/java/via/sep3/tier3/grpcservice/UserManagement.java"
    click Entities "https://github.com/ham222/sep3/tree/main/tier3/src/main/java/via/sep3/tier3/database/entity"
    click Repositories3 "https://github.com/ham222/sep3/tree/main/tier3/src/main/java/via/sep3/tier3/database/repository"
    click DbServicesImpl "https://github.com/ham222/sep3/tree/main/tier3/src/main/java/via/sep3/tier3/database/service/implimentations"
    click ProtoDef "https://github.com/ham222/sep3/blob/main/tier3/src/main/proto/definitions.proto"
    click ProtosStub2 "https://github.com/ham222/sep3/tree/main/tier3/src/main/java/via/generatedprotos"

    %% Styles
    classDef tier1 fill:#ddeeff,stroke:#3399ff,stroke-width:1px;
    classDef tier2 fill:#ddffdd,stroke:#33aa33,stroke-width:1px;
    classDef tier3 fill:#ffebcc,stroke:#ff9933,stroke-width:1px;
    classDef db fill:#fff0b3,stroke:#ff9900,stroke-width:2px,shape:cylinder;
    classDef artifact fill:#f2f2f2,stroke:#888888,stroke-dasharray: 2 2;
```
