# sdp-3-group-4/straycare-web architecture

> Architecture diagram of the GitHub repository sdp-3-group-4/straycare-web, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sdp-3-group-4/straycare-web
- Repository: https://github.com/sdp-3-group-4/straycare-web

## Overview

#### Purpose and entry points
StrayCare is a full-stack social/rescue platform: authenticated users can create and engage with posts, chat, manage connections/bookmarks/notifications, locate clinics, apply for vet verification, and use a marketplace/cart flow. The React client starts at `src/main.tsx` and composes routing/application state in `src/App.tsx`. The NestJS API starts at `straycare-backend/src/main.ts` and assembles feature modules in `straycare-backend/src/app.module.ts`.

#### Client application shell
The frontend is a Vite TypeScript React SPA. Authentication state is centralized in `src/contexts/AuthContext.tsx`; cart state is separately shared through `src/contexts/CartContext.tsx`. Firebase client setup resides in `src/firebase.ts`. Protected content is gated by `src/components/auth/ProtectedRoute.tsx`, separating public authentication UI (`src/pages/AuthPage.tsx`) from the signed-in home experience (`src/pages/HomeFeedPage.tsx`).

#### Home feed and social interaction surface
`src/pages/HomeFeedPage.tsx` is the signed-in composition boundary for desktop/mobile navigation, central feed content, side panels, and overlays. Feed views specialize by domain—posts/profile/bookmarks/notifications/marketplace—under `src/components/home/feed/CenterFeed.tsx`, `src/components/home/feed/PostCard.tsx`, and `src/components/home/feed/MarketplaceFeed.tsx`. User actions such as post creation, comments, likes, bookmarks, profile edits, and donations flow through the frontend API layer at `src/services/api.ts` to corresponding backend modules.

#### Backend API and authorization boundary
Nest feature modules expose controller/service pairs for domain APIs. Firebase token validation is the primary request-security boundary via `straycare-backend/src/auth/firebase-auth.guard.ts` and Firebase server integration in `straycare-backend/src/firebase/firebase.service.ts`. Public-route exceptions are explicitly marked through `straycare-backend/src/auth/public.decorator.ts`. Core social APIs are implemented by `straycare-backend/src/posts/posts.controller.ts`, `straycare-backend/src/comments/comments.controller.ts`, and `straycare-backend/src/connections/connections.controller.ts`.

#### Persistence and domain services
Prisma is the backend persistence abstraction, with the canonical model and migration history in `straycare-backend/prisma/schema.prisma` and `straycare-backend/prisma/migrations/`. All feature services use the shared database layer from `straycare-backend/src/prisma/prisma.service.ts`. Major persisted domains include users, posts/media, interactions, conversations, marketplace data, notifications, and vet applications, represented by modules such as `straycare-backend/src/users/users.service.ts`, `straycare-backend/src/chat/chat.service.ts`, and `straycare-backend/src/marketplace/marketplace.service.ts`.

#### Commerce, location, and verification
Marketplace browsing and checkout UI are handled by `src/components/home/feed/MarketplaceProductModal.tsx` and `src/components/home/feed/MarketplaceCheckoutModal.tsx`, with client payment integration isolated in `src/services/payments.ts` and server-side marketplace operations in `straycare-backend/src/marketplace/marketplace.service.ts`. Clinic proximity begins with browser/user location logic in `src/hooks/useUserLocation.ts` and geographic utilities in `src/utils/geo.ts`. Vet verification submits to the dedicated server workflow at `straycare-backend/src/vet-applications/vet-applications.controller.ts`.

#### AI and deployment infrastructure
An AI rescue/response capability is isolated behind `straycare-backend/src/ai/ai-bot.controller.ts`, `straycare-backend/src/ai/auto-response.service.ts`, and `straycare-backend/src/ai/nim.service.ts`, keeping model-provider calls outside core social services. The frontend is configured for Firebase Hosting through `firebase.json`; Firebase is also the identity provider. The backend is containerizable via `straycare-backend/Dockerfile` and `straycare-backend/docker-compose.yml`, with environment-specific external credentials expected through its `.env.example`.

Main entry points: [`src/App.tsx`](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/App.tsx) (Application shell), [`straycare-backend/src/app.module.ts`](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/app.module.ts) (Feature assembly), [`src/pages/HomeFeedPage.tsx`](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/pages/HomeFeedPage.tsx) (Signed-in home), [`src/components/home/feed/MarketplaceCheckoutModal.tsx`](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/home/feed/MarketplaceCheckoutModal.tsx) (Marketplace checkout)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_client_main(("Client entry<br/>Vite bootstrap<br/>[main.tsx]"))
  node_client_app["Application shell<br/>React router/state<br/>[App.tsx]"]
  node_auth_context["Auth state<br/>React context<br/>[AuthContext.tsx]"]
  node_cart_context["Cart state<br/>React context<br/>[CartContext.tsx]"]
  node_firebase_client["Firebase client<br/>identity SDK setup<br/>[firebase.ts]"]
  node_protected_route["Protected routes<br/>route guard<br/>[ProtectedRoute.tsx]"]
  node_auth_page["Authentication UI<br/>public page<br/>[AuthPage.tsx]"]
  node_home["Signed-in home<br/>page composition<br/>[HomeFeedPage.tsx]"]
  node_feed["Social feed<br/>post/profile views<br/>[CenterFeed.tsx]"]
  node_marketplace_ui["Marketplace checkout<br/>commerce UI"]
  node_client_api["Frontend API layer<br/>HTTP client<br/>[api.ts]"]
  node_payments["Payment integration<br/>client payment service<br/>[payments.ts]"]
end

subgraph group_api["NestJS API"]
  node_api_main(("API entry<br/>Nest bootstrap<br/>[main.ts]"))
  node_api_module["Feature assembly<br/>Nest root module<br/>[app.module.ts]"]
  node_auth_guard["Firebase auth guard<br/>request authorization"]
  node_social_api["Social APIs<br/>posts/comments/connections"]
  node_domain_services["Domain services<br/>users/chat/marketplace"]
  node_vet_api["Vet verification<br/>application workflow"]
  node_ai_api["AI rescue responses<br/>AI workflow"]
end

subgraph group_data["Data &amp; Integrations"]
  node_prisma_service[("Prisma database layer<br/>shared persistence service<br/>[prisma.service.ts]")]
  node_prisma_schema["Data model &amp; migrations<br/>Prisma schema<br/>[schema.prisma]"]
  node_firebase_server["Firebase server integration<br/>token validation"]
end

subgraph group_ops["Deployment"]
  node_firebase_hosting["Firebase Hosting<br/>SPA hosting<br/>[firebase.json]"]
  node_backend_container["Backend container<br/>Docker image"]
end

node_client_main -->|"mounts"| node_client_app
node_client_app -->|"provides"| node_auth_context
node_client_app -->|"provides"| node_cart_context
node_firebase_client -->|"authenticates"| node_auth_context
node_client_app -->|"public route"| node_auth_page
node_client_app -->|"gates signed-in routes"| node_protected_route
node_protected_route -->|"allows"| node_home
node_home -->|"composes"| node_feed
node_home -->|"opens"| node_marketplace_ui
node_feed -->|"social actions"| node_client_api
node_marketplace_ui -->|"catalog and orders"| node_client_api
node_marketplace_ui -->|"payment flow"| node_payments
node_client_api -->|"API requests"| node_api_main
node_api_main -->|"boots"| node_api_module
node_api_module -->|"applies"| node_auth_guard
node_auth_guard -->|"validates tokens with"| node_firebase_server
node_api_module -->|"registers"| node_social_api
node_api_module -->|"registers"| node_vet_api
node_api_module -->|"registers"| node_ai_api
node_social_api -->|"delegates to"| node_domain_services
node_vet_api -->|"persists applications"| node_prisma_service
node_domain_services -->|"reads and writes"| node_prisma_service
node_prisma_service -->|"uses model"| node_prisma_schema
node_firebase_hosting -->|"serves SPA"| node_client_main
node_backend_container -->|"runs"| node_api_main

click node_client_main "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/main.tsx"
click node_client_app "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/App.tsx"
click node_auth_context "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/contexts/AuthContext.tsx"
click node_cart_context "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/contexts/CartContext.tsx"
click node_firebase_client "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/firebase.ts"
click node_protected_route "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/auth/ProtectedRoute.tsx"
click node_auth_page "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/pages/AuthPage.tsx"
click node_home "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/pages/HomeFeedPage.tsx"
click node_feed "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/home/feed/CenterFeed.tsx"
click node_marketplace_ui "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/home/feed/MarketplaceCheckoutModal.tsx"
click node_client_api "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/services/api.ts"
click node_payments "https://github.com/sdp-3-group-4/straycare-web/blob/main/src/services/payments.ts"
click node_api_main "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/main.ts"
click node_api_module "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/app.module.ts"
click node_auth_guard "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/auth/firebase-auth.guard.ts"
click node_social_api "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/posts/posts.controller.ts"
click node_domain_services "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/marketplace/marketplace.service.ts"
click node_vet_api "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/vet-applications/vet-applications.controller.ts"
click node_ai_api "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/ai/ai-bot.controller.ts"
click node_prisma_service "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/prisma/prisma.service.ts"
click node_prisma_schema "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/prisma/schema.prisma"
click node_firebase_server "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/firebase/firebase.service.ts"
click node_firebase_hosting "https://github.com/sdp-3-group-4/straycare-web/blob/main/firebase.json"
click node_backend_container "https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_main,node_client_app,node_auth_context,node_cart_context,node_firebase_client,node_protected_route,node_auth_page,node_home,node_feed,node_marketplace_ui,node_client_api,node_payments toneBlue
class node_api_main,node_api_module,node_auth_guard,node_social_api,node_domain_services,node_vet_api,node_ai_api toneAmber
class node_prisma_service,node_prisma_schema,node_firebase_server toneMint
class node_firebase_hosting,node_backend_container toneRose
```

## Components

### React Client

- [Client entry](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/main.tsx): Vite bootstrap · `src/main.tsx`
- [Application shell](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/App.tsx): React router/state · `src/App.tsx`
- [Auth state](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/contexts/AuthContext.tsx): React context · `src/contexts/AuthContext.tsx`
- [Cart state](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/contexts/CartContext.tsx): React context · `src/contexts/CartContext.tsx`
- [Firebase client](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/firebase.ts): identity SDK setup · `src/firebase.ts`
- [Protected routes](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/auth/ProtectedRoute.tsx): route guard · `src/components/auth/ProtectedRoute.tsx`
- [Authentication UI](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/pages/AuthPage.tsx): public page · `src/pages/AuthPage.tsx`
- [Signed-in home](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/pages/HomeFeedPage.tsx): page composition · Composes navigation, feed, panels, and overlays. · `src/pages/HomeFeedPage.tsx`
- [Social feed](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/home/feed/CenterFeed.tsx): post/profile views · `src/components/home/feed/CenterFeed.tsx`
- [Marketplace checkout](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/components/home/feed/MarketplaceCheckoutModal.tsx): commerce UI · `src/components/home/feed/MarketplaceCheckoutModal.tsx`
- [Frontend API layer](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/services/api.ts): HTTP client · `src/services/api.ts`
- [Payment integration](https://github.com/sdp-3-group-4/straycare-web/blob/main/src/services/payments.ts): client payment service · `src/services/payments.ts`

### NestJS API

- [API entry](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/main.ts): Nest bootstrap · `straycare-backend/src/main.ts`
- [Feature assembly](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/app.module.ts): Nest root module · `straycare-backend/src/app.module.ts`
- [Firebase auth guard](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/auth/firebase-auth.guard.ts): request authorization · Public endpoints opt out through the public decorator. · `straycare-backend/src/auth/firebase-auth.guard.ts`
- [Social APIs](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/posts/posts.controller.ts): posts/comments/connections · `straycare-backend/src/posts/posts.controller.ts`
- [Domain services](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/marketplace/marketplace.service.ts): users/chat/marketplace · `straycare-backend/src/marketplace/marketplace.service.ts`
- [Vet verification](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/vet-applications/vet-applications.controller.ts): application workflow · `straycare-backend/src/vet-applications/vet-applications.controller.ts`
- [AI rescue responses](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/ai/ai-bot.controller.ts): AI workflow · `straycare-backend/src/ai/ai-bot.controller.ts`

### Data & Integrations

- [Prisma database layer](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/prisma/prisma.service.ts): shared persistence service · `straycare-backend/src/prisma/prisma.service.ts`
- [Data model & migrations](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/prisma/schema.prisma): Prisma schema · Defines persisted social, chat, commerce, notification, and vet domains. · `straycare-backend/prisma/schema.prisma`
- [Firebase server integration](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/src/firebase/firebase.service.ts): token validation · `straycare-backend/src/firebase/firebase.service.ts`

### Deployment

- [Firebase Hosting](https://github.com/sdp-3-group-4/straycare-web/blob/main/firebase.json): SPA hosting · `firebase.json`
- [Backend container](https://github.com/sdp-3-group-4/straycare-web/blob/main/straycare-backend/Dockerfile): Docker image · `straycare-backend/Dockerfile`

## Connections

- Client entry → Application shell: mounts
- Application shell → Auth state: provides
- Application shell → Cart state: provides
- Firebase client → Auth state: authenticates
- Application shell → Authentication UI: public route
- Application shell → Protected routes: gates signed-in routes
- Protected routes → Signed-in home: allows
- Signed-in home → Social feed: composes
- Signed-in home → Marketplace checkout: opens
- Social feed → Frontend API layer: social actions
- Marketplace checkout → Frontend API layer: catalog and orders
- Marketplace checkout → Payment integration: payment flow
- Frontend API layer → API entry: API requests
- API entry → Feature assembly: boots
- Feature assembly → Firebase auth guard: applies
- Firebase auth guard → Firebase server integration: validates tokens with
- Feature assembly → Social APIs: registers
- Feature assembly → Vet verification: registers
- Feature assembly → AI rescue responses: registers
- Social APIs → Domain services: delegates to
- Vet verification → Prisma database layer: persists applications
- Domain services → Prisma database layer: reads and writes
- Prisma database layer → Data model & migrations: uses model
- Firebase Hosting → Client entry: serves SPA
- Backend container → API entry: runs
