# joeljohny/disasteraid architecture

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

- Interactive diagram: https://gitdiagram.com/joeljohny/disasteraid
- Repository: https://github.com/joeljohny/disasteraid

## Overview

##### Project type & purpose (from tree + minimal README)
**DisasterAid** is a **full-stack web application** with:
- **Frontend:** Angular SPA (`frontend/`)
- **Backend:** Node.js/Express API (`backend/`)
- **Data access:** Prisma (`backend/src/config/prisma.js`, `backend/prisma.config.ts`) connecting to a database (exact DB not shown in tree; Prisma implies a relational DB like Postgres/MySQL/SQLite).

Even though the root README is minimal, the code structure strongly indicates core features:
- **User authentication** (register/login, JWT-like flow) via `authController`, `authRoutes`, Angular `auth.service`, `auth.guard`, `auth.interceptor`.
- **Skills management** via `skillsController`, `skillsRoutes`.
- **Reports** endpoint(s) via `reportsRoutes`.

This is a classic “Angular SPA → REST API → DB” architecture.

##### Express App / Server Bootstrap
- `src/app.js`

##### Route Modules
- `authRoutes.js`
- `skillsRoutes.js`
- `reportsRoutes.js`
Each route module:
- exposes URL paths
- composes middleware chain
- delegates to controller functions

##### Middleware
- `authMiddleware.js`
- Validates token
- Attaches user context to request

##### Controllers
- `authController.js`
- `skillsController.js`
Controller as:
- “HTTP handlers” (input validation, orchestration)
- calls model/service/data layer

##### Models / Data Access
- `userModel.js`
- Prisma client wrapper: `config/prisma.js`
- DB config: `config/db.js`
Even if `userModel.js` is thin, show the intent:
- Domain model / persistence operations
- Prisma as the ORM/data mapper

##### Prisma
- Prisma as a distinct component (library) used by models/controllers:
- “Prisma Client → SQL DB”

`Express App` → mounts → `Routes` → (optional) `authMiddleware` → `Controllers` → `Prisma Client` → `Database`

##### Bootstrap + App Shell
- `main.ts`
- `app/app.ts`, `app.html`, `app.scss`
- `app.config.ts` (providers/configuration)

##### Routing
- `app.routes.ts`
- Routes to components (Login/Register/Dashboard)

##### Components
- `login.component.ts`
- `register.component.ts`
- `dashboard.component.ts`

##### Services
- `auth.service.ts` (HTTP calls, token handling)
Service as the primary client-side gateway to backend auth endpoints.

##### Interceptor
- `auth.interceptor.ts`

##### Guard
- `auth.guard.ts`

**Frontend arrowing pattern:**
`Components` → call → `AuthService` → uses → `Angular HttpClient` → passes through → `AuthInterceptor` → sends to → `Express API`

And for navigation:
`Router` → consults → `AuthGuard` → allows/denies → `Dashboard route`

##### Register/Login
- Angular Login/Register Component → AuthService → POST `/auth/*` → AuthController → DB (Prisma) → returns token/user

##### Authenticated API call
- Angular Dashboard → AuthService/other service → Interceptor adds token → GET `/skills` (or `/reports`) → AuthMiddleware verifies → SkillsController/Reports route → DB → returns data

##### Route protection
- Angular navigation to `/dashboard` → AuthGuard checks token/session → allow/redirect to login

##### Architectural patterns to explicitly encode
- **Layered backend**: Routes → Middleware → Controllers → Data Access (Prisma) → DB
- **SPA + REST**: Angular client is decoupled from backend via HTTP API
- **Cross-cutting concerns**:
- Frontend: Interceptor (auth header injection), Guard (authorization at routing)
- Backend: Auth middleware (authorization at API boundary)

##### “Don’t overthink it” decomposition checklist (specific to this project)
- Angular: App shell, Router, Login, Register, Dashboard, AuthService, AuthInterceptor, AuthGuard
- Express: app.js, authRoutes, skillsRoutes, reportsRoutes, authMiddleware, authController, skillsController
- Data: userModel, Prisma client, Database

- “Referenced by routes” / “Likely used for persistence” / “DB connector (legacy or supplementary)”

## Diagram (Mermaid)

```mermaid
flowchart TD

%% =========================================================
%% Level 1 — System Context
%% =========================================================
subgraph "C4 — Level 1: System Context"
direction TB

U["End User (Browser)"]:::external

subgraph "DisasterAid Web App"
direction TB
SYS["DisasterAid (Web Application)"]:::system
end

DB[("Relational Database\n(vendor via env/prisma config)")]:::db

U <-->|"HTTPS"| SYS
SYS <-->|"SQL_via_Prisma"| DB
end

%% =========================================================
%% Level 2 — Containers
%% =========================================================
subgraph "C4 — Level 2: Containers"
direction TB

subgraph "Frontend Container"
direction TB
FE["Angular SPA (Frontend)"]:::frontend
end

subgraph "Backend Container"
direction TB
BE["Node.js / Express REST API (Backend)"]:::backend
end

DB2[("Relational Database")]:::db

U2["End User (Browser)"]:::external

U2 <-->|"HTTPS"| FE
FE -->|"HTTPS_JSON_/auth/*_/skills/*_/reports/*"| BE
BE <-->|"SQL_via_Prisma"| DB2

N2["Notes:\n- Auth is internal to backend\n- Token used by client and verified by backend"]:::note
FE -.->|"uses_token_for_calls"| N2
BE -.->|"verifies_token_for_protected_endpoints"| N2
end

%% =========================================================
%% Level 3 — Components (Frontend + Backend internals)
%% =========================================================
subgraph "C4 — Level 3: Components"
direction TB

%% ---------------- Frontend internals ----------------
subgraph "Angular SPA — Internal Components"
direction TB

subgraph "Bootstrap & App Shell"
direction TB
FE_MAIN["main.ts (Bootstrap)"]:::frontend
FE_APP["app.ts (Root App)"]:::frontend
FE_HTML["app.html (Template)"]:::frontend
FE_SCSS["app.scss (Styles)"]:::frontend
FE_CFG["app.config.ts (Providers/Config)"]:::frontend
end

subgraph "Routing & Navigation"
direction TB
FE_ROUTES["app.routes.ts (Client-side Routing)"]:::frontend
FE_GUARD["auth.guard.ts (Route Guard)"]:::crosscut
end

subgraph "UI Components"
direction TB
FE_LOGIN["login.component.ts"]:::frontend
FE_REGISTER["register.component.ts"]:::frontend
FE_DASH["dashboard.component.ts"]:::frontend
end

subgraph "Client API & Cross-cutting"
direction TB
FE_AUTH_SVC["auth.service.ts (Auth API Gateway / Token Handling)"]:::frontend
FE_INTERCEPT["auth.interceptor.ts (Adds Authorization Header)"]:::crosscut
FE_HTTP["Angular HttpClient"]:::frontend
end

%% Frontend flows
FE_MAIN -->|"bootstraps"| FE_APP
FE_APP -->|"renders"| FE_HTML
FE_APP -.->|"styles"| FE_SCSS
FE_APP -->|"uses_providers"| FE_CFG

FE_APP -->|"configures"| FE_ROUTES
FE_ROUTES -->|"guards_navigation_with"| FE_GUARD
FE_ROUTES -->|"routes_to"| FE_LOGIN
FE_ROUTES -->|"routes_to"| FE_REGISTER
FE_ROUTES -->|"routes_to"| FE_DASH

FE_LOGIN -->|"calls"| FE_AUTH_SVC
FE_REGISTER -->|"calls"| FE_AUTH_SVC
FE_DASH -->|"calls"| FE_AUTH_SVC

FE_AUTH_SVC -->|"uses"| FE_HTTP
FE_HTTP -->|"passes_through"| FE_INTERCEPT

end

%% ---------------- Backend internals ----------------
subgraph "Express API — Internal Components"
direction TB

subgraph "Server Bootstrap"
direction TB
BE_APP["app.js (Express App Bootstrap)"]:::backend
end

subgraph "Routes (Express Routers)"
direction TB
BE_AUTH_R["authRoutes.js"]:::backend
BE_SKILLS_R["skillsRoutes.js"]:::backend
BE_REPORTS_R["reportsRoutes.js"]:::backend
end

subgraph "Middleware (Cross-cutting)"
direction TB
BE_AUTH_MW["authMiddleware.js (Bearer Token Verification)"]:::crosscut
end

subgraph "Controllers (HTTP Handlers)"
direction TB
BE_AUTH_C["authController.js (Login/Register Handlers)"]:::backend
BE_SKILLS_C["skillsController.js"]:::backend
BE_REPORTS_C["reportsRoutes.js (reports endpoints)"]:::backend
end

subgraph "Data Access Layer"
direction TB
BE_USER_MODEL["userModel.js (Persistence/Domain Mapping)"]:::data
BE_PRISMA["prisma.js (Prisma Client Wrapper)"]:::data
BE_DB_CFG["db.js (DB Connector/Config)"]:::data
BE_PRISMA_CFG["prisma.config.ts (Prisma Project Config)"]:::data
DB3[("Relational Database")]:::db
end

%% Backend wiring
BE_APP -->|"mounts"| BE_AUTH_R
BE_APP -->|"mounts"| BE_SKILLS_R
BE_APP -->|"mounts"| BE_REPORTS_R

%% Route to controller + middleware
BE_AUTH_R -->|"delegates"| BE_AUTH_C
BE_SKILLS_R -->|"uses_for_protected_routes"| BE_AUTH_MW
BE_REPORTS_R -->|"uses_for_protected_routes"| BE_AUTH_MW

BE_AUTH_MW -->|"allows_request_to"| BE_SKILLS_C
BE_AUTH_MW -->|"allows_request_to"| BE_REPORTS_C

BE_SKILLS_R -->|"delegates"| BE_SKILLS_C
BE_REPORTS_R -->|"delegates"| BE_REPORTS_C

%% Controllers to data
BE_AUTH_C -->|"reads_writes_users"| BE_USER_MODEL
BE_SKILLS_C -->|"queries"| BE_PRISMA
BE_REPORTS_C -->|"queries"| BE_PRISMA

BE_USER_MODEL -->|"uses"| BE_PRISMA
BE_PRISMA -.->|"configured_by"| BE_PRISMA_CFG
BE_PRISMA -.->|"may_use"| BE_DB_CFG
BE_PRISMA -->|"SQL"| DB3

end

%% ---------------- Cross-container runtime flows ----------------
FE_INTERCEPT -->|"HTTPS_JSON + Bearer_JWT_in_Authorization"| BE_APP

%% ---------------- Key runtime flows (annotated) ----------------
subgraph "Key Runtime Flows (Annotated)"
direction TB
KF1["1) Register/Login:\nLogin/Register → AuthService → POST_/auth/* → AuthController → Prisma → DB → token"]:::note
KF2["2) Authenticated API Call:\nDashboard → Interceptor adds Bearer token → GET_/skills or /reports → AuthMiddleware → Controller → Prisma → DB"]:::note
KF3["3) Route Protection:\nNavigate_/dashboard → AuthGuard checks token/session → allow_or_redirect"]:::note
end

FE_LOGIN -.->|"implements"| KF1
FE_REGISTER -.->|"implements"| KF1
BE_AUTH_C -.->|"implements"| KF1

FE_DASH -.->|"implements"| KF2
BE_AUTH_MW -.->|"implements"| KF2

FE_GUARD -.->|"implements"| KF3
FE_ROUTES -.->|"implements"| KF3

end

%% =========================================================
%% Click Events (from component mapping)
%% =========================================================
click FE_MAIN "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/main.ts"
click FE_APP "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/app.ts"
click FE_HTML "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/app.html"
click FE_SCSS "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/app.scss"
click FE_CFG "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/app.config.ts"
click FE_ROUTES "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/app.routes.ts"
click FE_LOGIN "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/components/login/login.component.ts"
click FE_REGISTER "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/components/register/register.component.ts"
click FE_DASH "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/components/dashboard/dashboard.component.ts"
click FE_AUTH_SVC "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/services/auth.service.ts"
click FE_GUARD "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/guards/auth.guard.ts"
click FE_INTERCEPT "https://github.com/joeljohny/disasteraid/blob/main/frontend/src/app/interceptors/auth.interceptor.ts"

click BE_APP "https://github.com/joeljohny/disasteraid/blob/main/backend/src/app.js"
click BE_AUTH_R "https://github.com/joeljohny/disasteraid/blob/main/backend/src/routes/authRoutes.js"
click BE_SKILLS_R "https://github.com/joeljohny/disasteraid/blob/main/backend/src/routes/skillsRoutes.js"
click BE_REPORTS_R "https://github.com/joeljohny/disasteraid/blob/main/backend/src/routes/reportsRoutes.js"
click BE_AUTH_C "https://github.com/joeljohny/disasteraid/blob/main/backend/src/controllers/authController.js"
click BE_SKILLS_C "https://github.com/joeljohny/disasteraid/blob/main/backend/src/controllers/skillsController.js"
click BE_AUTH_MW "https://github.com/joeljohny/disasteraid/blob/main/backend/src/middleware/authMiddleware.js"
click BE_USER_MODEL "https://github.com/joeljohny/disasteraid/blob/main/backend/src/models/userModel.js"
click BE_PRISMA "https://github.com/joeljohny/disasteraid/blob/main/backend/src/config/prisma.js"
click BE_DB_CFG "https://github.com/joeljohny/disasteraid/blob/main/backend/src/config/db.js"
click BE_PRISMA_CFG "https://github.com/joeljohny/disasteraid/blob/main/backend/prisma.config.ts"

%% =========================================================
%% Styles
%% =========================================================
classDef external fill:#f2f2f2,stroke:#6b7280,stroke-width:1px,color:#111827
classDef system fill:#e5e7eb,stroke:#111827,stroke-width:2px,color:#111827
classDef frontend fill:#dbeafe,stroke:#1d4ed8,stroke-width:1.5px,color:#0b1f44
classDef backend fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#052e16
classDef data fill:#ffedd5,stroke:#f97316,stroke-width:1.5px,color:#431407
classDef db fill:#fed7aa,stroke:#c2410c,stroke-width:2px,color:#431407
classDef crosscut fill:#e5e7eb,stroke:#374151,stroke-width:1.5px,color:#111827
classDef note fill:#fff7ed,stroke:#9a3412,stroke-width:1px,color:#7c2d12,stroke-dasharray: 3 3
```
