# lucax011/localmenu_frontendb2b architecture

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

- Interactive diagram: https://gitdiagram.com/lucax011/localmenu_frontendb2b
- Repository: https://github.com/lucax011/localmenu_frontendb2b

## Overview

##### Project type and purpose
- This is a full-stack-ish client application: an Expo + TypeScript React Native/React Web frontend for B2B merchants.
- It provides login, dashboard, business profile management, CRUD for products, an OCR-assisted menu import flow, order management, and report generation.

##### File structure
- Top-level files: configuration for ESLint, Prettier, Husky, Docker, Jenkins, Expo, Babel, Jest, Cypress, TypeScript.
- src/api: Axios clients for two external services (backend and OCR).
- src/features: feature-based screens/modules (auth, business, dashboard, products, orders, ocr, reports).
- src/store: global state (Zustand for auth).
- src/utils: validation helpers (zod).
- Cypress & Jest directories for E2E and unit tests.
- Dockerfile/docker-compose: containerized web build. Jenkinsfile: CI pipeline.

##### README for additional insights
- Stack: Expo + TS with React Navigation, Zustand, React Query, Axios, RN Paper, react-hook-form + zod.
- Two external APIs:
- Backend (NestJS) handles auth, business, products, orders, reports
- OCR service (FastAPI) handles image/PDF extraction
- Local infra: Docker for web, Jenkins for CI
- Testing: Jest + Testing Library (unit), Cypress (E2E on Expo Web)

##### Main components
a. Frontend Client (Expo)
- Presentation layer: feature-based screens (LoginScreen, DashboardScreen, BusinessScreen, ProductsListScreen, ProductFormScreen, OCRImportScreen, OCRReviewScreen, OrdersScreen, ReportsScreen)
- State management: Zustand (authStore)
- Data fetching: React Query + Axios
- Forms & validation: react-hook-form + zod (validators.ts)

b. API Clients
- BackendClient (src/api/client.ts + src/api/ocr.ts)
- OCRClient

c. External Services
- NestJS Backend (POST /auth/login; CRUD /products; GET/PUT /businesses/me; GET/PUT orders; POST /reports/generate)
- FastAPI OCR (POST /ocr/extract)

d. Development/CI Infrastructure
- Docker & docker-compose (web)
- Jenkins pipeline (install, lint, test, build, docker)
- Expo CLI (mobile + web dev server)

##### Relationships & data flow
- User interacts with Feature Screens → invokes React Query hooks → Axios clients → External APIs
- OCR flow:
1. OCRImportScreen picks media → OCRClient.upload(file) → FastAPI returns extracted items
2. OCRReviewScreen displays items → edits validated by zod → on confirm triggers BackendClient.createProducts()
- Auth flow: LoginScreen → BackendClient.login() → authStore persists token → Axios interceptors attach token
- Business/products/orders/reports flows similarly use React Query → BackendClient calls

##### Architectural patterns & design principles
- Feature-based modularization (each screen/domain in its own folder)
- Unidirectional data flow (React Query + Zustand for global auth)
- Separation of concerns: presentation (UI screens), data (API clients), state (store), validation (utils)
- CI/CD via Jenkins, containerization via Docker

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client UI Layer
    subgraph "Client UI" 
        App["App.tsx"]:::ui
        Login["LoginScreen"]:::ui
        Dashboard["DashboardScreen"]:::ui
        Business["BusinessScreen"]:::ui
        ProductsList["ProductsListScreen"]:::ui
        ProductForm["ProductFormScreen"]:::ui
        OCRImport["OCRImportScreen"]:::ui
        OCRReview["OCRReviewScreen"]:::ui
        Orders["OrdersScreen"]:::ui
        Reports["ReportsScreen"]:::ui
    end

    %% State & Data Layer
    subgraph "State & Data Layer"
        Store["authStore.ts"]:::state
        Query["React Query"]:::state
        Validators["validators.ts"]:::state
    end

    %% API Clients Layer
    subgraph "API Clients"
        BackendClient["BackendClient (client.ts)"]:::api
        OCRClient["OCRClient (ocr.ts)"]:::api
    end

    %% External Services Layer
    subgraph "External Services"
        Backend["NestJS Backend\n(POST /auth, CRUD /products, /businesses, /orders, /reports)"]:::service
        OCRService["FastAPI OCR\n(POST /ocr/extract)"]:::service
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        Docker["Docker & docker-compose"]:::infra
        Jenkins["Jenkins Pipeline"]:::infra
        ExpoConfig["app.config.ts & app.json"]:::infra
        ExpoCLI["Expo Dev Server"]:::infra
    end

    %% Connections - UI to State & Data
    App --> Login
    App --> Dashboard
    App --> Business
    App --> ProductsList
    App --> ProductForm
    App --> OCRImport
    App --> OCRReview
    App --> Orders
    App --> Reports

    Login --> Query
    Dashboard --> Query
    Business --> Query
    ProductsList --> Query
    ProductForm --> Query
    Orders --> Query
    Reports --> Query

    OCRImport --> OCRClient
    OCRClient --> OCRService
    OCRService --> OCRReview

    OCRReview --> Validators
    OCRReview --> Query

    %% State & Data to API Clients
    Query --> BackendClient
    Store --> BackendClient

    %% API Clients to External Services
    BackendClient --> Backend
    OCRClient --> OCRService

    %% Infrastructure flows
    Jenkins --> Docker
    Docker --> ExpoCLI
    ExpoConfig --> ExpoCLI

    %% Click Events
    click App "https://github.com/lucax011/localmenu_frontendb2b/blob/master/App.tsx"
    click Login "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/auth/LoginScreen.tsx"
    click Dashboard "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/dashboard/DashboardScreen.tsx"
    click Business "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/business/BusinessScreen.tsx"
    click ProductsList "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/products/ProductsListScreen.tsx"
    click ProductForm "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/products/ProductFormScreen.tsx"
    click OCRImport "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/ocr/OCRImportScreen.tsx"
    click OCRReview "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/ocr/OCRReviewScreen.tsx"
    click Orders "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/orders/OrdersScreen.tsx"
    click Reports "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/features/reports/ReportsScreen.tsx"
    click Store "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/store/authStore.ts"
    click BackendClient "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/api/client.ts"
    click OCRClient "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/api/ocr.ts"
    click Validators "https://github.com/lucax011/localmenu_frontendb2b/blob/master/src/utils/validators.ts"
    click Docker "https://github.com/lucax011/localmenu_frontendb2b/blob/master/Dockerfile & docker-compose.yml"
    click Jenkins "https://github.com/lucax011/localmenu_frontendb2b/tree/master/Jenkinsfile"
    click ExpoConfig "https://github.com/lucax011/localmenu_frontendb2b/blob/master/app.config.ts"
    click ExpoConfig "https://github.com/lucax011/localmenu_frontendb2b/blob/master/app.json"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#0366d6,color:#0366d6;
    classDef state fill:#d4edda,stroke:#28a745,color:#155724;
    classDef api fill:#ffe5b4,stroke:#fd7e14,color:#663c00;
    classDef service fill:#f8d7da,stroke:#dc3545,color:#721c24;
    classDef infra fill:#e2e3e5,stroke:#6c757d,color:#343a40;
```
