# shakirchaya0/fullstack-app architecture

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

- Interactive diagram: https://gitdiagram.com/shakirchaya0/fullstack-app
- Repository: https://github.com/shakirchaya0/fullstack-app

## Overview

##### Project Type and Purpose
- This is a full-stack restaurant management system with two distinct codebases:
- Frontend: React + TypeScript (Vite)
- Backend: Node.js + TypeScript, layered/DDD architecture
- Purpose: Allow customers to scan QR codes to browse menus, order, pay (via Mercado Pago), reserve tables; staff manage orders, menus, reservations, payments, and customer relations.

##### File Structure
- Top-level: `frontend/`, `backend/`
- Frontend/src:
- `features/` – feature modules (News, Products, Login, Reservation, Payment, Profile…)
- `routes/` – React Router routes
- `shared/` – reusable hooks, components, contexts
- `store/` – Redux slices
- Backend/src:
- `presentation/` – controllers, routes, middleware (Express/Koa)
- `application/` – services/use-cases
- `domain/` – entities, repositories interfaces
- `infrastructure/` – config, database adapter, external services (MercadoPago client, SMTP client, WebSocket server)
- `scripts/` – bootstrapping
- Configuration: `.env`, PostgreSQL, Mercado Pago sandbox, SMTP settings, WebSocket URL.

##### Main Components
a. **Client Mobile Device (Browser/SPA)**
- React application served by Vite on port 5173
- Communicates over HTTP/HTTPS and WebSocket
b. **API Gateway / Backend Service**
- Node.js TypeScript service
- Layers: Presentation, Application, Domain, Infrastructure
- Exposes REST endpoints (orders, menus, reservations, payments, auth)
- WebSocket endpoint for real-time updates (e.g., order status)
c. **Database**
- PostgreSQL
- Tables: Users, Roles, Products, Orders, Reservations, Payments, News, etc.
d. **External Services**
- Mercado Pago (Sandbox) for payment processing
- SMTP (e.g., Gmail or Mailtrap) for email confirmations/reset links
- (Optional) Public tunnel (ngrok) for Webhook testing
e. **Administrative UI (Desktop/Web)**
- Same React SPA or a separate route accessible by staff/admin roles for order management, menu updates, table availability.

##### Relationships & Data Flow
- Client ↔ Backend (REST API):
- Login/Signup, fetch menu, create order/reservation, user profile
- Client ↔ Backend (WebSocket):
- Real-time order status, table readiness, push notifications
- Backend ↔ Database:
- CRUD operations on domain entities via repository layer
- Backend ↔ Mercado Pago:
- Initiate payment, receive payment confirmation (synchronous)
- Webhook callback (asynchronous) → Backend updates order status
- Backend ↔ SMTP Service:
- Send order receipt, reservation confirmation, password reset emails

##### Architectural Patterns & Design Principles
- **Layered (Onion) Architecture / DDD**
- Presentation → Application (use cases) → Domain (business rules) → Infrastructure
- **Feature-based modularization** on the frontend
- **CQRS/Separation of Concerns**: controllers orchestrate use cases, repositories handle persistence
- **Env-driven configuration** for endpoints & secrets
- **External integration adapters** for payments and mail

- Versioned services or ports annotated

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Mobile/Browser Client"]:::client

    %% Frontend
    subgraph "Frontend (React + TypeScript)" 
        direction TB
        UI["React SPA\n(Vite:5173)"]:::frontend
        Features["Features Module\n(news, products,\nreservation, payment)"]:::frontend
        Store["Redux Store / React Query"]:::frontend
        Shared["Shared Components & Hooks"]:::frontend
    end

    %% Backend
    subgraph "Backend Service (Node.js + TypeScript)" 
        direction TB
        subgraph "Presentation Layer" 
            Controllers["Controllers & Routes\n(Express/Koa)"]:::backend1
            Middleware["Auth & Logging\nMiddleware"]:::backend1
        end
        subgraph "Application Layer"
            UseCases["Use-Cases / Services"]:::backend2
        end
        subgraph "Domain Layer"
            Entities["Entities & Interfaces"]:::backend3
            Repos["Repository Interfaces"]:::backend3
        end
        subgraph "Infrastructure Layer"
            DBAdapter["Database Adapter\n(TypeORM/Prisma)"]:::backend4
            MercadoClient["MercadoPago Client"]:::backend4
            SMTPClient["SMTP Client"]:::backend4
            WebSocketSvc["WebSocket Server"]:::backend4
        end
    end

    %% Database
    DB[(PostgreSQL Database)]:::db

    %% External Services
    MercadoPago(("MercadoPago Sandbox")):::external
    SMTP(("SMTP Service")):::external

    %% Connections
    Client -->|"HTTP/HTTPS"| UI
    UI -->|"REST API\n(HTTP 3000)"| Controllers
    Client -->|"WebSocket (WS)"| WebSocketSvc
    Controllers -->|"invoke"| UseCases
    UseCases -->|"business logic"| Entities
    UseCases -->|"use repository"| Repos
    Repos -->|"SQL queries"| DBAdapter
    DBAdapter -->|"SQL"| DB
    UseCases -->|"process payment\n(API call)"| MercadoClient
    MercadoClient -->|"HTTP"| MercadoPago
    UseCases -->|"send email\n(SMTP)"| SMTPClient
    SMTPClient -->|"SMTP"| SMTP

    %% Styles
    classDef client fill:#E8F4FC,stroke:#6CA0DC,color:#000
    classDef frontend fill:#DAE8FC,stroke:#6C8EBF,color:#000
    classDef backend1 fill:#D0E8D0,stroke:#6CA66C,color:#000
    classDef backend2 fill:#C0E0BF,stroke:#58A65C,color:#000
    classDef backend3 fill:#B0D8AE,stroke:#508A4E,color:#000
    classDef backend4 fill:#A0D0A0,stroke:#487C40,color:#000
    classDef db fill:#FFE6CC,stroke:#D79B00,color:#000
    classDef external fill:#F2F2F2,stroke:#A6A6A6,color:#000
```
