# javierscode/check-my-menu architecture

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

- Interactive diagram: https://gitdiagram.com/javierscode/check-my-menu
- Repository: https://github.com/javierscode/check-my-menu

## Overview

##### Main Components
- Backend Service: An Express.js application that follows hexagonal architecture. Its components include:
- Domain Layer: Entities (e.g., category, dish, restaurant, user), value objects, enums, and domain-level exceptions.
- Application Layer: Use-cases (e.g., create, edit, delete functionality for categories, dishes, restaurants, and user authentication) and application-specific exceptions.
- Infrastructure Layer: Controllers (handling HTTP requests), dependency injection setup, data transfer objects (DTOs), middlewares (auth, error handling), routing, persistence repositories (both in-memory and PostgreSQL implementations), and external utilities (e.g., JWT service, crypto, math utilities).

- Frontend Service: A Next.js application that contains:
- Client-side components: Organized into atoms, molecules, and organisms (e.g., AdminAside, DishCard, CategoryCard).
- Pages and routes: Both public (menu view for customers, domain-specific pages) and private administrative routes (for restaurant management) with associated server-side rendering logic (using get-server-side-props patterns for authentication).
- State and context management: Using custom hooks and context (such as auth context) to manage client-side state.
- API routes: Next.js API endpoints that complement the frontend functionality, particularly for authentication and data manipulation.

- Database: PostgreSQL is used as the primary persistence layer with Docker Compose handling service startup (port 54320). The backend interacts with this database through specific PostgreSQL repository implementations.

- Shared/Supporting Packages:
- ESLint configuration and tsconfig packages standardize the coding guidelines and TypeScript configurations across the monorepo.
- CI/CD pipelines (GitHub workflows) also play a supporting role in ensuring the deployments for both backend and web.

##### Relationships and Interactions
- User Interaction: Clients (restaurant users and customers) interact with the Next.js frontend via a web browser.
- API Communication: The web frontend makes API calls—either directly on Next.js API routes or as proxy calls—to the backend to perform CRUD operations (e.g., logging in, managing menus, generating QR codes).
- Backend Processing: The Express backend processes incoming requests, routes them through its controllers, and then delegates commands/queries to the application use-cases, which in turn call the domain logic.
- Data Flow to Persistence: The infrastructure layer’s repository implementations (PostgreSQL / in-memory alternatives) perform the actual database operations.
- Dependency Management: The dependency injection container assembles the various modules (controllers, use-cases, repositories, services) to maintain loose coupling.

##### Architectural Patterns and Technologies
- Hexagonal Architecture: Emphasize how the backend is divided into core domain logic, application services (use-cases), and external adapters (controllers, persistence, DI).
- MVC and Component-Based UI: The frontend follows typical Next.js architecture (page-based routing combined with React component hierarchies ranging from atoms to organisms).
- Technology Stack:
- Backend uses Express.js, TypeScript, Jest (for testing), and Docker for containerization.
- Frontend uses Next.js, React, TypeScript, and supports both server-side rendering and client signaling.
- PostgreSQL handles data persistence.

##### Elements
- Clear Labels: Use clear labels to designate each major component (e.g., “Express Backend – Domain, Application, Infrastructure”, “Next.js Frontend – Client Components, API Routes, SSR Services”, “PostgreSQL Database”, etc.).
- Detail Core Services: Highlight key services like JWT authentication, image upload integration (via Supabase in the web backend), and QR generator services.
- CI/CD and DevOps: Optionally, include a smaller section to illustrate the automation (GitHub workflows, Docker Compose) ensuring deployments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    User["Web Browser (User)"]:::user

    %% Frontend Subgraph
    subgraph "Next.js Frontend"
        FE_Client["Client Components (Atoms, Molecules, Organisms)"]:::frontend
        FE_Pages["Pages & Routes (Public & Admin)"]:::frontend
        FE_Server["SSR & API Routes (get-server-side-props, API endpoints)"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Express Backend"
        BE_Infra["Infrastructure Layer (Controllers, DI, DTOs, Middlewares, Repositories, Utilities)"]:::backend
        BE_App["Application Layer (Use-cases, Exceptions)"]:::backend
        BE_Domain["Domain Layer (Entities, VOs, Enums, Domain Exceptions)"]:::backend
    end

    %% Database Subgraph
    subgraph "PostgreSQL Database"
        DB_Docker["Docker Compose Config"]:::database
        DB_Persistence["PostgreSQL Persistence (Repositories Implementation)"]:::database
    end

    %% Shared Configurations Subgraph
    subgraph "Shared Configurations & CI/CD"
        ESLint["ESLint Config"]:::shared
        TS["TypeScript Config"]:::shared
        CI_CD["CI/CD Pipelines"]:::shared
    end

    %% Connections
    User --> FE_Client
    FE_Client --> FE_Pages
    FE_Pages --> FE_Server
    FE_Server -->|"API_call"| BE_Infra
    BE_Infra -->|"process_request"| BE_App
    BE_App -->|"business_logic"| BE_Domain
    BE_Infra -->|"persistence_ops"| DB_Persistence
    DB_Docker -->|"configures"| DB_Persistence

    %% Dependencies to Shared Configurations (optional)
    FE_Server --- ESLint
    FE_Server --- TS
    BE_Infra --- ESLint
    BE_Infra --- TS
    BE_Infra --- CI_CD
    FE_Server --- CI_CD

    %% Click Events
    click BE_Domain "https://github.com/javierscode/check-my-menu/tree/main/apps/backend/src/domain"
    click BE_App "https://github.com/javierscode/check-my-menu/tree/main/apps/backend/src/application"
    click BE_Infra "https://github.com/javierscode/check-my-menu/tree/main/apps/backend/src/infrastructure"
    click DB_Docker "https://github.com/javierscode/check-my-menu/blob/main/apps/backend/docker-compose.yml"
    click DB_Persistence "https://github.com/javierscode/check-my-menu/tree/main/apps/backend/src/infrastructure/persistence"
    click FE_Client "https://github.com/javierscode/check-my-menu/tree/main/apps/web/src/client/components"
    click FE_Pages "https://github.com/javierscode/check-my-menu/tree/main/apps/web/src/pages"
    click FE_Server "https://github.com/javierscode/check-my-menu/tree/main/apps/web/src/server"
    click ESLint "https://github.com/javierscode/check-my-menu/tree/main/packages/eslint-config-custom"
    click TS "https://github.com/javierscode/check-my-menu/tree/main/packages/tsconfig"
    click CI_CD "https://github.com/javierscode/check-my-menu/tree/main/.github/workflows"

    %% Styles
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef frontend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef database fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef shared fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef user fill:#E0FFFF,stroke:#333,stroke-width:2px;
```
