# 23klhuynh/vietnamese_restaurant architecture

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

- Interactive diagram: https://gitdiagram.com/23klhuynh/vietnamese_restaurant
- Repository: https://github.com/23klhuynh/vietnamese_restaurant

## Overview

##### Project type and purpose
- This is a full-stack web application (“Pho Viet”), consisting of:
- A React/TypeScript single-page application (client/)
- A Flask REST API server with JWT-based authentication (server/)
- A PostgreSQL database for persisting menu items and users
- Purpose: allow users to register, log in, browse a restaurant menu, add items to a cart, and place orders.

##### File structure
- Top-level:
- client/ – front-end code powered by Vite, React, TailwindCSS
- server/ – back-end Python Flask application
- client/:
- src/pages – Route-based views (Home, Login, Register, Menu, NotFound)
- src/components – Reusable UI fragments, navigation bar, menu items, cart
- src/auth/UserContext.tsx – React Context holds JWT and user info
- Hooks for scroll, UI behavior
- Configuration: vite.config.js, tailwind.config.js, tsconfig.json
- server/:
- app.py – Flask app instantiation and routing
- config.py – environment and database URI
- extensions.py – DB, JWT setup
- jwt_handlers.py – issue/verify tokens
- routes/ – auth.py (register, login, refresh, logout), menu.py (CRUD menu items)
- requirements.txt – Python dependencies

##### Key insights from README
- Uses JWT for authentication
- PostgreSQL as persistent store
- Deployed on Vercel (front end) and Render (back end)
- Start commands: npm run dev / flask app.py

##### Main components
a. Front-end Layer (client)
– Browser
– Hosted on Vercel
– React SPA
b. API Layer (server)
– Flask REST API
– Hosted on Render
– Modules: Auth service, Menu service
c. Data Layer
– PostgreSQL database
d. External Services
– Vercel CDN
– Render compute
– (Optional) Third-party analytics or payment if any

##### Relationships and interactions
- User (Browser) → HTTP(S) GET/POST → React SPA assets (Vercel CDN)
- React SPA → HTTP(S) API calls → Flask endpoints (Auth & Menu)
- Flask → SQL queries → PostgreSQL
- JWT issuance: Auth service → signs token → returned to client → stored in UserContext localStorage or HTTP-only cookie
- Protected API calls include JWT in Authorization header → validated by jwt_handlers

##### Architectural patterns and design principles
- Client-Server separation (SPA vs. REST API)
- Stateless authentication via JWT
- Modular back-end with Blueprints (routes/auth.py, routes/menu.py)
- React Context for global state (auth)
- Component-based UI (atoms, molecules, pages)
- Tailwind utility-first CSS integration

##### Technologies & frameworks
- Front-end: React, Vite, TypeScript, TailwindCSS
- Back-end: Flask, Flask-JWT-Extended, psycopg2 (or SQLAlchemy), Python 3.x
- Database: PostgreSQL
- Hosting: Vercel (front), Render (back)

##### Final checklist
- [ ] All components labeled (Browser, React SPA, Auth Service, Menu Service, DB)
- [ ] Clear boundary of hosting environments
- [ ] Notes on major frameworks/technologies in each component

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Browser and CDN
    Browser["User Browser"]:::external
    CDN["Vercel CDN"]:::external
    Browser -->|"HTTPS GET assets"| CDN

    subgraph "Front-end (Vercel)" 
        direction TB
        ReactSPA["React SPA (Vite + Tailwind)"]:::frontend
        CDN -->|serves SPA| ReactSPA

        subgraph "Pages" 
            direction TB
            Home["Home.tsx"]:::frontend
            Login["Login.tsx"]:::frontend
            Register["Register.tsx"]:::frontend
            MenuPage["Menu.tsx"]:::frontend
            NotFound["NotFound.tsx"]:::frontend
        end

        subgraph "Components"
            direction TB
            Cart["Cart.tsx"]:::frontend
            MenuItemCards["MenuItemCards.tsx"]:::frontend
            MenuItemsNav["MenuItemsNav.tsx"]:::frontend
            Navbar["Navbar.tsx"]:::frontend
            NavbarLinks["NavbarLinks.tsx"]:::frontend
            Sidebar["Sidebar.tsx"]:::frontend
            Fragments["fragments/"]:::frontend
        end

        subgraph "Context & Hooks"
            direction TB
            UserContext["UserContext.tsx"]:::frontend
            useScroll["useScroll.tsx"]:::frontend
            SmoothScroll["SmoothScroll.tsx"]:::frontend
        end

        subgraph "Configs"
            direction TB
            ViteConfig["vite.config.js"]:::frontend
            TailwindConfig["tailwind.config.js"]:::frontend
            TSConfig["tsconfig.json"]:::frontend
        end

        ReactSPA -->|"renders routes"| Pages
        ReactSPA -->|"uses components"| Components
        ReactSPA -->|"auth state"| UserContext
        ReactSPA -->|"scroll hooks"| useScroll
        ReactSPA -->|"UI hooks"| SmoothScroll
        ReactSPA -->|"build config"| ViteConfig
        ReactSPA -->|"styling config"| TailwindConfig
        ReactSPA -->|"ts config"| TSConfig
    end

    %% API Layer
    ReactSPA -->|"HTTPS API calls (JWT auth)"| API

    subgraph "API Layer (Render)"
        direction TB
        API["Flask REST API"]:::backend

        subgraph "Auth Service"
            direction TB
            AppPy["app.py"]:::backend
            ConfigPy["config.py"]:::backend
            Extensions["extensions.py"]:::backend
            JWTHandlers["jwt_handlers.py"]:::backend
            AuthRoutes["auth.py"]:::backend
        end

        subgraph "Menu Service"
            direction TB
            MenuRoutes["menu.py"]:::backend
        end

        Requirements["requirements.txt"]:::backend

        API --> AuthService
        API --> MenuService
    end

    %% Data Layer
    API -->|"SQL queries"| Postgres
    Postgres["PostgreSQL DB"]:::database

    %% Click Events
    click ReactSPA "https://github.com/23klhuynh/vietnamese_restaurant/tree/main/client/src"
    click Home "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/pages/Home.tsx"
    click Login "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/pages/Login.tsx"
    click Register "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/pages/Register.tsx"
    click MenuPage "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/pages/Menu.tsx"
    click NotFound "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/pages/NotFound.tsx"
    click Cart "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/components/cart/Cart.tsx"
    click MenuItemCards "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/components/menu/MenuItemCards.tsx"
    click MenuItemsNav "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/components/menu/MenuItemsNav.tsx"
    click Navbar "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/components/navbar/Navbar.tsx"
    click NavbarLinks "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/components/navbar/NavbarLinks.tsx"
    click Sidebar "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/components/navbar/Sidebar.tsx"
    click Fragments "https://github.com/23klhuynh/vietnamese_restaurant/tree/main/client/src/components/fragments"
    click UserContext "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/auth/UserContext.tsx"
    click useScroll "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/hooks/useScroll.tsx"
    click SmoothScroll "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/src/hooks/SmoothScroll.tsx"
    click ViteConfig "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/vite.config.js"
    click TailwindConfig "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/tailwind.config.js"
    click TSConfig "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/client/tsconfig.json"
    click AppPy "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/app.py"
    click ConfigPy "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/config.py"
    click Extensions "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/extensions.py"
    click JWTHandlers "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/jwt_handlers.py"
    click AuthRoutes "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/routes/auth.py"
    click MenuRoutes "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/routes/menu.py"
    click Requirements "https://github.com/23klhuynh/vietnamese_restaurant/blob/main/server/requirements.txt"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#1E70BF,color:#1E70BF
    classDef backend fill:#DFF5D0,stroke:#3A7D0B,color:#3A7D0B
    classDef database fill:#FFE8B0,stroke:#BF6F00,color:#BF6F00
    classDef external fill:#E0E0E0,stroke:#7F7F7F,color:#7F7F7F
    class Browser,CDN external
    class ReactSPA,Home,Login,Register,MenuPage,NotFound,Cart,MenuItemCards,MenuItemsNav,Navbar,NavbarLinks,Sidebar,Fragments,UserContext,useScroll,SmoothScroll,ViteConfig,TailwindConfig,TSConfig frontend
    class API,AppPy,ConfigPy,Extensions,JWTHandlers,AuthRoutes,MenuRoutes,Requirements backend
    class Postgres database
```
