# mek3911/sofra architecture

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

- Interactive diagram: https://gitdiagram.com/mek3911/sofra
- Repository: https://github.com/mek3911/sofra

## Overview

1. **Overall shape**
   This is a **client-side React single-page app** built with **TypeScript + Vite**. There is no custom backend service in the repo; the browser app talks directly to **Firebase** for persistence, auth, and file storage.

2. **App entry and shell**
   `src/main.tsx` bootstraps the app into `index.html`, and `src/App.tsx` is the top-level composition/routing layer. `src/index.css` and `vite.config.ts` indicate a standard Vite front-end build pipeline.

3. **Primary user flows**
   The UI is split into role-specific experiences:
   - **Customer**: `Landing`, `Auth`, `CustomerFeed`, `Cart`, `CustomerOrders`, `Profile`
   - **Chef**: `ChefDashboard`, `ChefList`, `ChefDishes`, `ChefOrders`, `ChefProfile`
   - **Admin**: `AdminPanel`, `AdminChefs`, `AdminDishes`, `AdminOrders`, `AdminSettings`
   This suggests a marketplace/ordering domain with multiple personas operating on shared food/order data.

4. **Shared application state**
   `src/context/CartContext.tsx` is the main shared client-side state boundary. It likely holds cart contents and related actions used by customer-facing components such as `Cart` and item browsing views.

5. **Firebase integration boundary**
   `src/firebase.ts` is the central integration point for the backend services. Based on the file set, the app likely uses:
   - **Firebase Auth** for login/session handling
   - **Firestore** for dishes, chefs, orders, profiles, and settings
   - **Firebase Storage** for images/uploads  
   The repo includes `firestore.rules` and `storage.rules`, so data access is controlled at the Firebase layer rather than through a server API.

6. **Role and data governance**
   The presence of separate admin and chef components, plus Firebase rules, implies access control is an important architectural boundary. Role-based UI is implemented in the client, while actual enforcement is delegated to **Firestore/Storage security rules**.

7. **Content and media handling**
   `src/utils/imageOptimizer.ts` indicates image upload or optimization is part of the data flow, probably for dish or profile images. The `testUpload.ts` and `testUpload2.ts` files reinforce that storage/media upload is a first-class path in the app.

8. **Seed and maintenance tooling**
   `src/utils/seedData.ts` and `scripts/updateCategories.ts` are repo-level data utilities. These are not runtime UI pieces; they support bootstrapping or maintaining catalog data, which helps explain how Firestore collections are populated and kept consistent.

9. **Deployment/runtime footprint**
   `vercel.json` suggests the built SPA is deployed as a static front-end, likely on Vercel. `package.json`, `package-lock.json`, and `tsconfig.json` define the Node/TypeScript build environment. `metadata.json`, `firebase-applet-config.json`, and `firebase-blueprint.json` indicate this repo was generated or managed through AI Studio/Firebase tooling.

10. **Resilience and UX boundaries**
   `src/components/ErrorBoundary.tsx` provides a UI-level fault isolation layer so rendering/runtime errors don’t take down the whole experience. `src/components/Navigation.tsx` is the shared shell for moving across the different persona views.

11. **External-service note**
   The README asks for a `GEMINI_API_KEY`, which suggests the app may have been created in AI Studio and may integrate with Gemini-assisted features or generation context, but there is no obvious dedicated Gemini service layer in the file tree. The dominant runtime architecture is still the React app + Firebase backend.

12. **Diagram-friendly summary**
   For an architecture diagram, model this as:
   - **Browser SPA** with shared cart state and role-based UI
   - **Firebase Auth / Firestore / Storage** as the backend data plane
   - **Security rules** as the enforcement boundary
   - **Vite/Vercel** as build and deployment infrastructure
   - **Scripts/utils** as offline maintenance and data-seeding support

Main entry points: [`src/App.tsx`](https://github.com/mek3911/sofra/blob/main/src/App.tsx) (App shell), [`src/firebase.ts`](https://github.com/mek3911/sofra/blob/main/src/firebase.ts) (Firebase), [`src/components/CustomerFeed.tsx`](https://github.com/mek3911/sofra/blob/main/src/components/CustomerFeed.tsx) (Customer flow), [`src/main.tsx`](https://github.com/mek3911/sofra/blob/main/src/main.tsx) (main)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["Browser app"]
  node_n_main(("main<br/>entrypoint<br/>[main.tsx]"))
  node_n_app["App shell<br/>composition<br/>[App.tsx]"]
  node_n_nav["Navigation<br/>shell nav<br/>[Navigation.tsx]"]
  node_n_error["Error boundary<br/>ui guard<br/>[ErrorBoundary.tsx]"]
  node_n_cartctx["Cart context<br/>shared state<br/>[CartContext.tsx]"]
  node_n_landing["Landing<br/>customer entry<br/>[Landing.tsx]"]
  node_n_auth["Auth<br/>[Auth.tsx]"]
  node_n_customer["Customer flow<br/>customer views<br/>[CustomerFeed.tsx]"]
  node_n_chef["Chef flow<br/>chef views<br/>[ChefDashboard.tsx]"]
  node_n_admin["Admin flow<br/>admin views<br/>[AdminPanel.tsx]"]
end

subgraph group_grp_backend["Firebase backend"]
  node_n_firebase[("Firebase<br/>service client<br/>[firebase.ts]")]
  node_n_rules_fs["Firestore rules<br/>security rules<br/>[firestore.rules]"]
  node_n_rules_st["Storage rules<br/>security rules<br/>[storage.rules]"]
end

subgraph group_grp_ops["Build & ops"]
  node_n_seed["Seed data<br/>data bootstrap<br/>[seedData.ts]"]
  node_n_imgopt["Image optimizer<br/>media utility<br/>[imageOptimizer.ts]"]
  node_n_updatecats["Update categories<br/>maintenance script"]
  node_n_vite{{"Vite build<br/>frontend build<br/>[vite.config.ts]"}}
  node_n_deploy["Vercel deploy<br/>static deploy<br/>[vercel.json]"]
end

node_n_main -->|"mounts"| node_n_app
node_n_app -->|"uses"| node_n_nav
node_n_app -->|"wraps"| node_n_error
node_n_app -->|"routes"| node_n_landing
node_n_app -->|"routes"| node_n_auth
node_n_app -->|"routes"| node_n_customer
node_n_app -->|"routes"| node_n_chef
node_n_app -->|"routes"| node_n_admin
node_n_customer -->|"shares"| node_n_cartctx
node_n_customer -->|"reads/writes"| node_n_firebase
node_n_chef -->|"reads/writes"| node_n_firebase
node_n_admin -->|"reads/writes"| node_n_firebase
node_n_firebase -->|"governed by"| node_n_rules_fs
node_n_firebase -->|"governed by"| node_n_rules_st
node_n_seed -.->|"seeds"| node_n_firebase
node_n_updatecats -.->|"maintains"| node_n_firebase
node_n_imgopt -.->|"supports"| node_n_firebase
node_n_vite -->|"builds"| node_n_main
node_n_deploy -->|"hosts"| node_n_vite

click node_n_main "https://github.com/mek3911/sofra/blob/main/src/main.tsx"
click node_n_app "https://github.com/mek3911/sofra/blob/main/src/App.tsx"
click node_n_nav "https://github.com/mek3911/sofra/blob/main/src/components/Navigation.tsx"
click node_n_error "https://github.com/mek3911/sofra/blob/main/src/components/ErrorBoundary.tsx"
click node_n_cartctx "https://github.com/mek3911/sofra/blob/main/src/context/CartContext.tsx"
click node_n_landing "https://github.com/mek3911/sofra/blob/main/src/components/Landing.tsx"
click node_n_auth "https://github.com/mek3911/sofra/blob/main/src/components/Auth.tsx"
click node_n_customer "https://github.com/mek3911/sofra/blob/main/src/components/CustomerFeed.tsx"
click node_n_chef "https://github.com/mek3911/sofra/blob/main/src/components/ChefDashboard.tsx"
click node_n_admin "https://github.com/mek3911/sofra/blob/main/src/components/AdminPanel.tsx"
click node_n_firebase "https://github.com/mek3911/sofra/blob/main/src/firebase.ts"
click node_n_rules_fs "https://github.com/mek3911/sofra/blob/main/firestore.rules"
click node_n_rules_st "https://github.com/mek3911/sofra/blob/main/storage.rules"
click node_n_seed "https://github.com/mek3911/sofra/blob/main/src/utils/seedData.ts"
click node_n_imgopt "https://github.com/mek3911/sofra/blob/main/src/utils/imageOptimizer.ts"
click node_n_updatecats "https://github.com/mek3911/sofra/blob/main/scripts/updateCategories.ts"
click node_n_vite "https://github.com/mek3911/sofra/blob/main/vite.config.ts"
click node_n_deploy "https://github.com/mek3911/sofra/blob/main/vercel.json"

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_n_main,node_n_app,node_n_nav,node_n_error,node_n_cartctx,node_n_landing,node_n_auth,node_n_customer,node_n_chef,node_n_admin toneBlue
class node_n_firebase,node_n_rules_fs,node_n_rules_st toneAmber
class node_n_seed,node_n_imgopt,node_n_updatecats,node_n_vite,node_n_deploy toneMint
```

## Components

### Browser app

Client-side React SPA and shared UI state.

- [main](https://github.com/mek3911/sofra/blob/main/src/main.tsx): entrypoint · Bootstraps the React app into the page. · `src/main.tsx`
- [App shell](https://github.com/mek3911/sofra/blob/main/src/App.tsx): composition · Top-level app composition and route selection. · `src/App.tsx`
- [Navigation](https://github.com/mek3911/sofra/blob/main/src/components/Navigation.tsx): shell nav · Shared in-app navigation across personas. · `src/components/Navigation.tsx`
- [Error boundary](https://github.com/mek3911/sofra/blob/main/src/components/ErrorBoundary.tsx): ui guard · Catches rendering errors in the UI tree. · `src/components/ErrorBoundary.tsx`
- [Cart context](https://github.com/mek3911/sofra/blob/main/src/context/CartContext.tsx): shared state · Client-side cart state and actions. · `src/context/CartContext.tsx`
- [Landing](https://github.com/mek3911/sofra/blob/main/src/components/Landing.tsx): customer entry · Public entry page for the app. · `src/components/Landing.tsx`
- [Auth](https://github.com/mek3911/sofra/blob/main/src/components/Auth.tsx): customer auth · Login and session entry for customers. · `src/components/Auth.tsx`
- [Customer flow](https://github.com/mek3911/sofra/blob/main/src/components/CustomerFeed.tsx): customer views · Feed, cart, orders, and profile views for customers. · `src/components/CustomerFeed.tsx`
- [Chef flow](https://github.com/mek3911/sofra/blob/main/src/components/ChefDashboard.tsx): chef views · Dashboard and operational views for chefs. · `src/components/ChefDashboard.tsx`
- [Admin flow](https://github.com/mek3911/sofra/blob/main/src/components/AdminPanel.tsx): admin views · Administrative management views for the marketplace. · `src/components/AdminPanel.tsx`

### Firebase backend

Auth, database, storage, and security rules.

- [Firebase](https://github.com/mek3911/sofra/blob/main/src/firebase.ts): service client · Central client integration for backend services. · `src/firebase.ts`
- [Firestore rules](https://github.com/mek3911/sofra/blob/main/firestore.rules): security rules · Access control for database operations. · `firestore.rules`
- [Storage rules](https://github.com/mek3911/sofra/blob/main/storage.rules): security rules · Access control for file upload and download. · `storage.rules`

### Build & ops

Vite build, deployment, and repo tooling.

- [Seed data](https://github.com/mek3911/sofra/blob/main/src/utils/seedData.ts): data bootstrap · Catalog bootstrap and data shaping utilities. · `src/utils/seedData.ts`
- [Image optimizer](https://github.com/mek3911/sofra/blob/main/src/utils/imageOptimizer.ts): media utility · Image processing for uploads and display. · `src/utils/imageOptimizer.ts`
- [Update categories](https://github.com/mek3911/sofra/blob/main/scripts/updateCategories.ts): maintenance script · Offline script for category maintenance. · `scripts/updateCategories.ts`
- [Vite build](https://github.com/mek3911/sofra/blob/main/vite.config.ts): frontend build · TypeScript/Vite build configuration. · `vite.config.ts`
- [Vercel deploy](https://github.com/mek3911/sofra/blob/main/vercel.json): static deploy · Static hosting and deployment configuration. · `vercel.json`

## Connections

- main → App shell: mounts · Bootstraps the top-level app.
- App shell → Navigation: uses · Renders shared navigation.
- App shell → Error boundary: wraps · Isolated UI error handling.
- App shell → Landing: routes · Public entry experience.
- App shell → Auth: routes · Authentication flow.
- App shell → Customer flow: routes · Customer-facing experience.
- App shell → Chef flow: routes · Chef-facing experience.
- App shell → Admin flow: routes · Admin-facing experience.
- Customer flow → Cart context: shares · Uses shared cart state.
- Customer flow → Firebase: reads/writes · Consumes backend data.
- Chef flow → Firebase: reads/writes · Operates on shared marketplace data.
- Admin flow → Firebase: reads/writes · Manages marketplace data and settings.
- Firebase → Firestore rules: governed by · Database access is enforced by rules.
- Firebase → Storage rules: governed by · Storage access is enforced by rules.
- Seed data → Firebase: seeds · Initializes or populates backend data.
- Update categories → Firebase: maintains · Updates catalog data offline.
- Image optimizer → Firebase: supports · Prepares media for storage workflows.
- Vite build → main: builds · Compiles the SPA entry and assets.
- Vercel deploy → Vite build: hosts · Deploys the built frontend as static output.
