# guillermo-obyrne/friendlyeats architecture

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

- Interactive diagram: https://gitdiagram.com/guillermo-obyrne/friendlyeats
- Repository: https://github.com/guillermo-obyrne/friendlyeats

## Overview

##### Project type and purpose
- From the file tree and README, “Friendlychat” is a full-stack, real-time chat application.
- Frontend: Angular SPA (src/app, angular.json, tsconfig.json).
- Backend & hosting: Firebase (firebase.json, firestore.rules, functions/).
- Purpose: allow users to log in, send and receive chat messages in real time via Firestore, with optional cloud-function logic.

##### File structure
- Top-level:
– src/              → Angular application source
– functions/        → Firebase Cloud Functions (Node.js)
– firebase.json, firestore.rules, storage.rules → Firebase config
– angular.json      → Angular CLI build & serve config
– tailwind.config.js→ CSS utility framework config
- src/app:
– app.component.ts, app.routes.ts → Core module & routing
– components/header/ → Shared UI
– pages/login-page + chat-page → Feature modules
– services/chat.service.ts → Angular service for Firestore interaction
- functions:
– index.js (or equivalent) for any onWrite triggers or HTTP endpoints
– package.json for dependencies (firebase-admin, firebase-functions)

##### README for additional insights
- Angular CLI v16 project scaffolded by default.
- `ng serve`, `ng build`, `firebase` tooling implied.

a. Main components:
1. Angular Client (Browser SPA)
2. Firebase Authentication
3. Firestore Database (NoSQL real-time)
4. Firebase Cloud Functions
5. Firebase Hosting (serves the built SPA)
6. Optional: Firebase Storage (if using file uploads)
b. Relationships & interactions:
1. User ↔ Angular Client
2. Angular Client ↔ Auth SDK → Firebase Authentication
3. Angular Client ↔ Firestore SDK → Firestore (real-time listeners)
4. Angular Client ↔ Cloud Functions (via HTTP Callable or triggers)
5. Cloud Functions ↔ Firestore (admin operations, indexing)
6. Hosting serves the Angular bundle to the user’s browser
c. Architectural patterns:
- SPA on the client side
- Service layer in Angular (chat.service.ts) abstracting SDK calls
- Event-driven architecture: Firestore real-time updates
- Micro-backend via Cloud Functions for server-side logic
- Secure rules in Firestore and Storage to enforce data access
d. Key technologies:
- Angular, Angular CLI, TypeScript
- Tailwind CSS
- Firebase SDKs (Auth, Firestore, Functions, Hosting)
- Karma/Jasmine tests, Node.js for functions

##### Detailed breakdown
- Layer 1 (User & Browser): represents user’s actions, routing through Angular router
- Layer 2 (Angular App):
- app.module: imports AngularFireModule.initializeApp()
- ChatService: wrapper for Firestore.collection(“messages”)
- Layer 3 (Firebase Services):
- Authentication: user signin/signout
- Firestore: real-time messaging
- Functions: triggers on new messages or HTTP callable for moderation
- Hosting: serves compiled SPA
- Layer 4 (Security):
- Firestore rules restricting reads/writes to authenticated users
- Storage rules if images/files are supported

Final recommendation:
- Sketch a 2-column layout: left column = Client (Angular), right column = Firebase Cloud.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Zone
    subgraph "Client Zone"
        direction TB
        AngularSPA["Angular SPA"]:::client
        subgraph "Client Components"
            direction TB
            Main["Main Entry Point<br/>(src/main.ts)"]:::client
            AppComponent["App Component<br/>(app.component.ts)"]:::client
            AppRoutes["App Routing Module<br/>(app.routes.ts)"]:::client
            LoginPage["Login Page<br/>(login-page.component.ts)"]:::client
            ChatPage["Chat Page<br/>(chat-page.component.ts)"]:::client
            Header["Header Component<br/>(header.component.ts)"]:::client
            ChatService["ChatService<br/>(chat.service.ts)"]:::client
            Environment["Environment Config<br/>(environment.ts)"]:::client
            IndexHTML["Index HTML<br/>(index.html)"]:::client
            Styles["Global Styles<br/>(styles.css)"]:::client
        end
    end

    %% Backend Zone
    subgraph "Backend Zone"
        direction TB
        Hosting["Firebase Hosting"]:::backend
        Auth["Firebase Authentication"]:::backend
        Firestore["Firestore DB"]:::db
        Storage["Firebase Storage"]:::backend
        Functions["Cloud Functions"]:::backend
        RulesFS["Firestore Rules<br/>(firestore.rules)"]:::rules
        RulesST["Storage Rules<br/>(storage.rules)"]:::rules
        Indexes["Firestore Indexes<br/>(firestore.indexes.json)"]:::config
    end

    %% Connections
    User["User"]:::external
    User -->|"uses"| AngularSPA
    AngularSPA -->|"bootstraps via"| Main
    AngularSPA -->|"renders"| AppComponent
    AngularSPA -->|"loads"| IndexHTML
    AngularSPA -->|"applies styles from"| Styles
    AppComponent -->|"contains header"| Header
    AppComponent -->|"injects routes"| AppRoutes
    AppRoutes -->|"routes to"| LoginPage
    AppRoutes -->|"routes to"| ChatPage
    LoginPage -->|"calls"| ChatService
    ChatPage -->|"uses"| ChatService
    ChatService -->|"Auth SDK"| Auth
    ChatService -->|"Firestore SDK"| Firestore
    AngularSPA -->|"calls callable"| Functions
    Functions -->|"admin writes"| Firestore
    Hosting -->|"serves bundle to"| User
    Firestore -.->|"secured by"| RulesFS
    Storage -.->|"secured by"| RulesST
    Firestore -->|"indexes defined by"| Indexes

    %% Click events
    click AngularSPA "https://github.com/guillermo-obyrne/friendlyeats/tree/main/src/"
    click Main "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/main.ts"
    click AppComponent "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/app/app.component.ts"
    click AppRoutes "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/app/app.routes.ts"
    click LoginPage "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/app/pages/login-page/login-page.component.ts"
    click ChatPage "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/app/pages/chat-page/chat-page.component.ts"
    click Header "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/app/components/header/header.component.ts"
    click ChatService "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/app/services/chat.service.ts"
    click Environment "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/environments/environment.ts"
    click IndexHTML "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/index.html"
    click Styles "https://github.com/guillermo-obyrne/friendlyeats/blob/main/src/styles.css"
    click Hosting "https://github.com/guillermo-obyrne/friendlyeats/blob/main/firebase.json"
    click Auth "https://github.com/guillermo-obyrne/friendlyeats/blob/main/firebase.json"
    click Firestore "https://github.com/guillermo-obyrne/friendlyeats/blob/main/firebase.json"
    click Storage "https://github.com/guillermo-obyrne/friendlyeats/blob/main/storage.rules"
    click Functions "https://github.com/guillermo-obyrne/friendlyeats/tree/main/functions/"
    click RulesFS "https://github.com/guillermo-obyrne/friendlyeats/blob/main/firestore.rules"
    click RulesST "https://github.com/guillermo-obyrne/friendlyeats/blob/main/storage.rules"
    click Indexes "https://github.com/guillermo-obyrne/friendlyeats/blob/main/firestore.indexes.json"

    %% Styles
    classDef client fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0FFD8,stroke:#333,stroke-width:1px
    classDef db fill:#FFD8D0,stroke:#333,stroke-width:1px
    classDef rules fill:#FFEFD0,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef config fill:#F0F0F0,stroke:#333,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
```
