# win24-gruppprojekt/frontend architecture

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

- Interactive diagram: https://gitdiagram.com/win24-gruppprojekt/frontend
- Repository: https://github.com/win24-gruppprojekt/frontend

## Overview

##### Project type and purpose
- This is a Single-Page Application (SPA) frontend built with React and Vite.
- Its purpose is to provide a user portal (gym members) and trainer portal (session creation) that integrates with multiple backend microservices (Events, Venues, Bookings, Auth, Notifications).
- It’s hosted as a static web app (Azure Static Web Apps via `.github/workflows/...yml`) and communicates exclusively over RESTful HTTP.

##### File structure
Top-level:
- index.html, public/staticwebapp.config.json → static host entry point & routing rules
- vite.config.js, .env → build & environment configuration
- src/ → all React source code
– layouts/ → layout components (LandingLayout, PortalLayout)
– pages/ → top-level pages (StartPage, SessionListPage, ProfilePage, etc.)
– components/ → reusable UI (SessionCard, Header, modals, buttons, filters, etc.)
– lib/api.js & lib/http.js → wrapper around fetch for token injection, retries, error handling
– main.jsx & App.jsx → root of React router & context setup
- .eslint.config.js → coding standards
- package.json → dependencies (React, React Router, react-spinners, etc.)

##### README insights
- Confirms React 18 + Vite, React Router DOM for routing, custom CSS, React hooks for state, fetch wrapper for API calls.
- Lists five backend microservices with distinct responsibilities and configurable base URLs via `.env` (VITE_*_API_BASE_URL).
- Shows role-based UI: trainer vs. member flows.
- Mentions hosted as static web app and used for a school assignment.

- Browser / User device (desktop/mobile)
- Static-hosting environment (Azure Static Web Apps / CDN)
- React SPA (App.jsx + Router + layouts + pages + components)
- API Client (lib/http.js + lib/api.js for token handling + fetch wrapper)
- Five External Microservices:
– AuthService (JWT login/refresh)
– EventService (CRUD sessions)
– VenueService (location data)
– BookingService (book/unbook sessions)
– NotificationService (email confirmations)
- Configuration Layer (.env → VITE_*_API_BASE_URL)

b. Relationships & interactions:
1. Browser requests index.html from Static-host → React assets (JS/CSS).
2. SPA boots, React Router hands off to StartPage or authenticated PortalLayout.
3. User actions (view sessions, book, create) trigger lib/api calls.
4. API client injects JWT (AuthService) and dispatches HTTP requests to the appropriate microservice endpoint.
5. Microservices respond; SPA updates state via hooks and re-renders components.
6. BookingService → on success → NotificationService for email notifications (the SPA may trigger this or the backend orchestrates it).

c. Architectural patterns & design principles:
- SPA pattern with client-side routing (React Router).
- Modular React components (separation of concerns).
- Single API client layer for cross-cutting concerns (logging, retries, auth injection).
- Environment-driven configuration for microservice endpoints.
- Role-based UI rendering (conditional rendering based on JWT claims).

d. Key technologies & frameworks:
- React 18, React Router DOM
- Vite (dev + build tooling)
- Fetch wrapper in src/lib (for retries, token management)
- react-spinners for loading states
- Azure Static Web Apps (CI/CD via GitHub Actions)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser UI)" 
        direction TB
        Browser["Browser"]:::frontend
        subgraph "React SPA"
            direction TB
            indexHTML["index.html"]:::frontend
            click indexHTML "https://github.com/win24-gruppprojekt/frontend/blob/main/index.html"
            SrcDir["src/"]:::frontend
            click SrcDir "https://github.com/win24-gruppprojekt/frontend/tree/main/src/"
            subgraph "App & Router"
                direction TB
                MainJS["main.jsx"]:::frontend
                click MainJS "https://github.com/win24-gruppprojekt/frontend/blob/main/src/main.jsx"
                AppJS["App.jsx"]:::frontend
                click AppJS "https://github.com/win24-gruppprojekt/frontend/blob/main/src/App.jsx"
            end
            subgraph "Layouts"
                direction TB
                LandingLayout["LandingLayout.jsx"]:::frontend
                click LandingLayout "https://github.com/win24-gruppprojekt/frontend/blob/main/src/layouts/LandingLayout.jsx"
                PortalLayout["PortalLayout.jsx"]:::frontend
                click PortalLayout "https://github.com/win24-gruppprojekt/frontend/blob/main/src/layouts/PortalLayout.jsx"
            end
            subgraph "Pages"
                direction TB
                StartPage["StartPage.jsx"]:::frontend
                click StartPage "https://github.com/win24-gruppprojekt/frontend/blob/main/src/pages/StartPage.jsx"
                SessionListPage["SessionListPage.jsx"]:::frontend
                click SessionListPage "https://github.com/win24-gruppprojekt/frontend/blob/main/src/pages/SessionListPage.jsx"
                SessionDetailsPage["SessionDetailsPage.jsx"]:::frontend
                click SessionDetailsPage "https://github.com/win24-gruppprojekt/frontend/blob/main/src/pages/SessionDetailsPage.jsx"
                ProfilePage["ProfilePage.jsx"]:::frontend
                click ProfilePage "https://github.com/win24-gruppprojekt/frontend/blob/main/src/pages/ProfilePage.jsx"
                AboutPage["AboutPage.jsx"]:::frontend
                click AboutPage "https://github.com/win24-gruppprojekt/frontend/blob/main/src/pages/AboutPage.jsx"
                ComponentsPage["ComponentsPage.jsx"]:::frontend
                click ComponentsPage "https://github.com/win24-gruppprojekt/frontend/blob/main/src/pages/ComponentsPage.jsx"
            end
            ReusableComponents["components/"]:::frontend
            click ReusableComponents "https://github.com/win24-gruppprojekt/frontend/tree/main/src/components/"
            subgraph "API Client Layer"
                direction TB
                HttpJS["http.js"]:::apiLayer
                click HttpJS "https://github.com/win24-gruppprojekt/frontend/blob/main/src/lib/http.js"
                ApiJS["api.js"]:::apiLayer
                click ApiJS "https://github.com/win24-gruppprojekt/frontend/blob/main/src/lib/api.js"
                EnvConfig[".env"]:::apiLayer
                click EnvConfig "https://github.com/win24-gruppprojekt/frontend/blob/main/.env"
            end
            StyleCSS["style.css"]:::frontend
            click StyleCSS "https://github.com/win24-gruppprojekt/frontend/blob/main/src/style.css"
            ImgDir["img/"]:::frontend
            click ImgDir "https://github.com/win24-gruppprojekt/frontend/tree/main/src/img/"
        end
        GitConfig[".gitignore & eslint.config.js"]:::frontend
        click GitConfig "https://github.com/win24-gruppprojekt/frontend/blob/main/.gitignore"
        click GitConfig "https://github.com/win24-gruppprojekt/frontend/blob/main/eslint.config.js"
        PackageJSON["package.json & package-lock.json"]:::frontend
        click PackageJSON "https://github.com/win24-gruppprojekt/frontend/blob/main/package.json"
        click PackageJSON "https://github.com/win24-gruppprojekt/frontend/blob/main/package-lock.json"
    end

    %% Hosting/Infra Layer
    subgraph "Static Hosting Infrastructure" 
        direction TB
        StaticHost["Azure Static Web Apps / CDN"]:::hosting
        SWAWorkflow["GitHub Actions Workflow"]:::hosting
        click SWAWorkflow "https://github.com/win24-gruppprojekt/frontend/blob/main/.github/workflows/azure-static-web-apps-proud-glacier-04e577903.yml"
        ViteConfig["vite.config.js"]:::hosting
        click ViteConfig "https://github.com/win24-gruppprojekt/frontend/blob/main/vite.config.js"
    end

    %% Backend Microservices
    subgraph "Backend Microservices"
        direction TB
        AuthService["Auth Service (JWT)"]:::service
        EventService["Event Service (Sessions)"]:::service
        VenueService["Venue Service (Locations)"]:::service
        BookingService["Booking Service (Book/Unbook)"]:::service
        NotificationService["Notification Service (Emails)"]:::service
    end

    %% Connections
    Browser -->|"HTTPS: GET assets"| StaticHost
    StaticHost -->|"Serves HTML, JS, CSS"| Browser
    Browser -->|"User Actions (clicks)"| indexHTML
    Browser -->|"SPA Boot"| AppJS
    AppJS -->|"Renders Layouts & Pages"| LandingLayout
    AppJS -->|"Renders Layouts & Pages"| PortalLayout
    PortalLayout -->|"Loads Pages"| SessionListPage
    SessionListPage -->|"API Calls via"| HttpJS
    HttpJS -->|"wraps fetch to"| ApiJS
    EnvConfig -->|"provides base URLs"| ApiJS
    ApiJS -->|"HTTP/REST JWT"| AuthService
    ApiJS -->|"HTTP/REST JWT"| EventService
    ApiJS -->|"HTTP/REST JWT"| VenueService
    ApiJS -->|"HTTP/REST JWT"| BookingService
    ApiJS -->|"HTTP/REST JWT"| NotificationService
    BookingService -->|"On Success triggers"| NotificationService
    StaticHost -.->|".github workflow deploys"| SWAWorkflow

    %% Styling
    classDef frontend fill:#D0E8FF,stroke:#004080,stroke-width:1px;
    classDef hosting fill:#DFFFE0,stroke:#088A08,stroke-width:1px;
    classDef apiLayer fill:#FFF5B1,stroke:#B8860B,stroke-width:1px;
    classDef service fill:#FFE0B2,stroke:#B35900,stroke-width:1px;
```
