# mahmoud-mh/foood architecture

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

- Interactive diagram: https://gitdiagram.com/mahmoud-mh/foood
- Repository: https://github.com/mahmoud-mh/foood

## Overview

##### Project Type and Purpose
- This is a full‐stack web application for managing cooking recipes.
- Frontend is built with Next.js (App Router, React, Tailwind CSS), providing server‐rendered and client‐side pages for browsing, creating, editing, and administrating recipes.
- Backend is a modular NestJS monolith exposing a versioned REST API (`/api/v1/*`), handling authentication (JWT, Passport), business logic (recipes, ingredients, categories, users), file uploads (avatars, recipe images), and persistence (PostgreSQL via TypeORM).

##### File Structure Analysis
- Top‐level directories:
- /frontend – Next.js application
- /backend – NestJS API server + scripts + upload storage
- Backend modules under `/backend/src/modules`: auth, users, recipes, ingredients, categories, uploads.
- Shared code in `/backend/src/common` (DTOs, decorators, guards), configuration in `/backend/src/config`, entrypoint `/backend/src/main.ts`.
- Frontend pages organized under `/frontend/src/app` by domain (auth, recipes, admin, categories, profile).
- Frontend reusable components in `/frontend/src/components` and API wrappers in `/frontend/src/services`.

##### Key Insights from README
- System features: JWT‐based auth, role‐based access (USER/ADMIN), CRUD for recipes/ingredients/categories, file upload with Multer, image storage on disk, PostgreSQL backed by TypeORM, and automated API docs with Swagger.
- Tech stack: Next.js, React, TypeScript, Tailwind, Axios, NextAuth.js on the frontend; NestJS, TypeORM, Passport, JWT, bcrypt, Multer on the backend.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client
    Client["Client (Browser/Mobile)"]:::client

    %% Frontend Layer
    subgraph "Frontend (Next.js)" 
        direction TB
        NextApp["Next.js Frontend"]:::frontend
        subgraph "Pages"
            AuthPage["Auth Pages"]:::frontend
            RecipesPage["Recipes Pages"]:::frontend
            CategoriesPage["Categories Pages"]:::frontend
            AdminPage["Admin Pages"]:::frontend
            ProfilePage["Profile Pages"]:::frontend
        end
        Components["Shared Components"]:::frontend
        ServicesFW["API Wrappers / Services"]:::frontend
    end

    %% API Gateway / Load Balancer
    Gateway["API Gateway / Load Balancer\n(e.g., NGINX/Vercel)"]:::gateway

    %% Backend Layer
    subgraph "Backend (NestJS Monolith)"
        direction TB
        Entrypoint["Main Entry (main.ts)"]:::backend
        Config["Configuration"]:::backend
        Common["Shared Code (DTOs, Guards, Decorators)"]:::backend
        subgraph "Modules"
            direction TB
            AuthMod["Auth Module"]:::backend
            UsersMod["Users Module"]:::backend
            RecipesMod["Recipes Module"]:::backend
            IngredientsMod["Ingredients Module"]:::backend
            CategoriesMod["Categories Module"]:::backend
            UploadsMod["Uploads Module"]:::backend
        end
    end

    %% Data Stores
    DB["PostgreSQL Database"]:::db
    Storage["File Storage\n(/backend/uploads)"]:::storage

    %% External Services
    External["External Services (Email/SMS)"]:::external

    %% Connections
    Client -->|HTTPS| NextApp
    NextApp -->|HTTP /api/v1| Gateway
    Gateway -->|forwards requests| Entrypoint
    Entrypoint -->|loads modules| AuthMod
    Entrypoint -->|loads modules| UsersMod
    Entrypoint -->|loads modules| RecipesMod
    Entrypoint -->|loads modules| IngredientsMod
    Entrypoint -->|loads modules| CategoriesMod
    Entrypoint -->|loads modules| UploadsMod

    AuthMod -->|reads/writes| DB
    UsersMod -->|reads/writes| DB
    RecipesMod -->|reads/writes| DB
    IngredientsMod -->|reads/writes| DB
    CategoriesMod -->|reads/writes| DB
    UploadsMod -->|stores files| Storage

    AuthMod -->|sends emails| External
    AuthMod -->|issues JWT| NextApp

    %% Click Events Frontend
    click NextApp "https://github.com/mahmoud-mh/foood/tree/main/frontend/"
    click AuthPage "https://github.com/mahmoud-mh/foood/tree/main/frontend/src/app/auth/"
    click RecipesPage "https://github.com/mahmoud-mh/foood/tree/main/frontend/src/app/recipes/"
    click CategoriesPage "https://github.com/mahmoud-mh/foood/tree/main/frontend/src/app/categories/"
    click AdminPage "https://github.com/mahmoud-mh/foood/tree/main/frontend/src/app/admin/"
    click ProfilePage "https://github.com/mahmoud-mh/foood/tree/main/frontend/src/app/profile/"
    click Components "https://github.com/mahmoud-mh/foood/tree/main/frontend/src/components/"
    click ServicesFW "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/services/base/http.service.ts"
    click ServicesFW "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/services/auth.service.ts"
    click ServicesFW "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/services/recipe.service.ts"
    click ServicesFW "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/services/ingredient.service.ts"
    click ServicesFW "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/services/category.service.ts"
    click ServicesFW "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/services/user.service.ts"
    click NextApp "https://github.com/mahmoud-mh/foood/blob/main/frontend/src/app/globals.css"
    click NextApp "https://github.com/mahmoud-mh/foood/blob/main/frontend/next.config.ts"
    click NextApp "https://github.com/mahmoud-mh/foood/blob/main/frontend/tsconfig.json"

    %% Click Events Backend
    click Entrypoint "https://github.com/mahmoud-mh/foood/blob/main/backend/src/main.ts"
    click Config "https://github.com/mahmoud-mh/foood/blob/main/backend/src/config/config.module.ts"
    click Config "https://github.com/mahmoud-mh/foood/blob/main/backend/src/config/config.service.ts"
    click Config "https://github.com/mahmoud-mh/foood/blob/main/backend/src/config/database.config.ts"
    click Common "https://github.com/mahmoud-mh/foood/tree/main/backend/src/common/dto/"
    click Common "https://github.com/mahmoud-mh/foood/tree/main/backend/src/common/guards/"
    click Common "https://github.com/mahmoud-mh/foood/blob/main/backend/src/common/decorators/auth.decorators.ts"
    click AuthMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/auth/auth.module.ts"
    click AuthMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/auth/auth.controller.ts"
    click AuthMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/auth/auth.service.ts"
    click AuthMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/auth/strategies/local.strategy.ts"
    click AuthMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/auth/strategies/jwt.strategy.ts"
    click UsersMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/users/users.module.ts"
    click UsersMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/users/users.controller.ts"
    click UsersMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/users/users.service.ts"
    click UsersMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/users/entities/user.entity.ts"
    click RecipesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/recipes/recipes.module.ts"
    click RecipesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/recipes/recipes.controller.ts"
    click RecipesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/recipes/recipes.service.ts"
    click RecipesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/recipes/entities/recipe.entity.ts"
    click RecipesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/recipes/entities/recipe-step.entity.ts"
    click RecipesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/recipes/entities/recipe-ingredient.entity.ts"
    click IngredientsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/ingredients/ingredients.module.ts"
    click IngredientsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/ingredients/ingredients.controller.ts"
    click IngredientsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/ingredients/ingredients.service.ts"
    click IngredientsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/ingredients/entities/ingredient.entity.ts"
    click CategoriesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/categories/categories.module.ts"
    click CategoriesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/categories/categories.controller.ts"
    click CategoriesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/categories/categories.service.ts"
    click CategoriesMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/categories/entities/category.entity.ts"
    click UploadsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/uploads/uploads.module.ts"
    click UploadsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/uploads/uploads.controller.ts"
    click UploadsMod "https://github.com/mahmoud-mh/foood/blob/main/backend/src/modules/uploads/uploads.service.ts"

    %% Styles
    classDef client fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef frontend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef gateway fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef backend fill:#FFA500,stroke:#333,stroke-width:1px
    classDef db fill:#F0E68C,stroke:#333,stroke-width:1px
    classDef storage fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef external fill:#D8BFD8,stroke:#333,stroke-width:1px
```
