diff --git a/.gitignore b/.gitignore index 996c3e4..f0e663d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ frontend/node_modules/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ +.antigravitycli/ # Added by cargo diff --git a/README.md b/README.md index 2e383a2..c6078be 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The HTML code for the frontend can be generated by using `trunk build`. The resu > } > ``` -## Diagramms +## Diagrams ### Class Diagramm ```mermaid classDiagram @@ -283,15 +283,111 @@ classDiagram ``` +### Sequence Diagrams +#### 1. System Initialization & Administrator Setup +```mermaid +sequenceDiagram + autonumber + actor Admin as Initial Administrator + participant FE as Frontend (Yew) + participant BE as Backend (Axum) + database DB as Database (Postgres) + + Note over Admin, DB: System Initialization Flow + FE->>BE: GET /api/check-admin + BE->>DB: SELECT COUNT(*) FROM users WHERE is_admin = true + DB-->>BE: 0 (No admin found) + BE-->>FE: HTTP 200 OK {"exists": false} + FE-->>Admin: Render Admin Setup Page + Admin->>FE: Input username, password, first/last name + FE->>BE: POST /api/setup-admin {username, pwd, ...} + Note over BE: Hash password using Argon2 + BE->>DB: INSERT INTO users (username, pwd, is_admin, ...) + DB-->>BE: Success + BE-->>FE: HTTP 200 OK {"status": "success"} + FE-->>Admin: Redirect to Login Page +``` + +#### 2. User Authentication Flow (Login) + +```mermaid +sequenceDiagram + autonumber + actor User as User / Admin + participant FE as Frontend (Yew) + participant BE as Backend (Axum) + database DB as Database (Postgres) + + Note over User, DB: Authentication & Cookie Session Setup + User->>FE: Enter username & password + FE->>BE: POST /api/login {username, pwd} + BE->>DB: SELECT * FROM users WHERE username = $1 + DB-->>BE: Return user record with password hash + Note over BE: Verify password using Argon2 + alt Password Valid + Note over BE: Generate JWT token containing claims (sub: user_id) + Note over BE: Build HttpOnly, Secure, Lax cookie 'token' + BE-->>FE: HTTP 200 OK {"status": "success", "token": "...", "user": {...}}
Header: Set-Cookie: token=...; Path=/; HttpOnly; SameSite=Lax + Note over FE: Save auth state to global context + FE-->>User: Redirect to Dashboard / Home + else Password Invalid + BE-->>FE: HTTP 400 Bad Request {"status": "error", "message": "Invalid password"} + FE-->>User: Display error message + end +``` + +#### 3. Ticket Lifecycle Flow + +```mermaid +sequenceDiagram + autonumber + actor User as Authenticated User + actor Admin as Administrator + participant FE as Frontend (Yew) + participant BE as Backend (Axum) + database DB as Database (Postgres) + + Note over User, DB: Ticket Creation Flow (Protected Route) + User->>FE: Fill out ticket form & submit + FE->>BE: POST /api/tickets/create {category, betreff, description, room} (Includes 'token' cookie) + Note over BE: validate_token middleware decodes & verifies JWT + BE->>DB: INSERT INTO tickets (category, description, betreff, room, user_id) + DB-->>BE: Success + BE-->>FE: HTTP 200 OK {"status": "success"} + FE-->>User: Clear form & display success notification + + Note over Admin, DB: Ticket Review & Resolution (Admin Only Route) + Admin->>FE: View Ticket Board + FE->>BE: GET /api/tickets (Includes 'token' cookie) + Note over BE: validate_token middleware checks JWT + BE->>DB: SELECT tickets JOIN users ... + DB-->>BE: Return list of tickets + BE-->>FE: HTTP 200 OK [tickets] + FE-->>Admin: Render Ticket List + + Admin->>FE: Click "Resolve" on ticket + FE->>BE: PATCH /api/tickets/{id} {"status": "Resolved"} (Includes 'token' cookie) + Note over BE: validate_admin middleware verifies token & checks is_admin = true + BE->>DB: UPDATE tickets SET status = $1 WHERE id = $2 + DB-->>BE: Success + BE-->>FE: HTTP 200 OK {"status": "success"} + FE-->>Admin: Update ticket status in UI +``` ## Usage of AI -Github Copilot CLI was used with the model Claude Haiku 4.5 to generate most of the documentation: +Github Copilot CLI was used with the model Claude Haiku 4.5 to generate most of the documentation + +Google Antigravity generated the Sequence Diagrams ### Prompt Generate comments for cargo doc describing the indivilual components and create links to relevant structs, functions etc. +Generate a sequence diagramm in @[README.md] behind the class diagramms + ### Output The comments with `///` or `//!` I've gone over most of it and modified it to my needs and opinions + +The sequence Diagrams above