# alad1n0/project-back architecture

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

- Interactive diagram: https://gitdiagram.com/alad1n0/project-back
- Repository: https://github.com/alad1n0/project-back

## Overview

##### Project type and purpose
- This is a NestJS–Prisma backend API (no frontend code).
- Purpose: Support a restaurant-ordering platform with features for users, restaurants, products, categories, baskets, favorites, ratings, promotions, FAQs, and OTP-based authentication.

##### File structure
- Top-level: Nest config (`nest-cli.json`), TypeScript setup (`tsconfig.json`), Prisma schema & migrations (`prisma/`), source code (`src/`), tests (`test/`).
- `src/` is organized into Nest modules: `auth`, `users`, `restaurants`, `categories`, `product`, `basket`, `favorites`, `rating`, `service/otp`, `config`, plus shared helpers and middleware.
- `prisma/` contains:
- `schema/` (modular .prisma files per domain entity)
- `migrations/` (SQL migration history)
- `seed/` scripts that prepopulate the database.
- No separate frontend—monolithic backend with modular architecture.

##### README
- Confirms this is a NestJS TypeScript starter extended for a food-ordering domain.

a. Main components
- Client (mobile/web) – HTTP/HTTPS requests
- NestJS Application
– Modules: Auth, Users, Restaurants, Categories, Products, Basket, Favorites, Ratings, Promotions, FAQ, OTP Service
– Shared layers: Controllers (entry points), Services (business logic), DTOs (validation), Middleware (JWT), Helpers
- Prisma Client (ORM)
- Database (e.g. PostgreSQL)
- External SMS/OTP Provider (Infobip)
b. Relationships & interactions
- Client → HTTP → Controllers → Services → Prisma Client → Database
- Auth module uses `OTP Service` → External SMS Provider
- Services may call other services (e.g. Basket service reads Products, Users, Restaurant details)
- Seed scripts populate Database before app start
c. Architectural patterns & principles
- Modular organization: each domain in its own Nest module
- MVC-style flow within each module (Controller → Service → Data Layer)
- Layered separation: HTTP layer, business-logic layer, ORM/data layer
- Single point of DB access via Prisma service
d. Key technologies
- NestJS (Modules, Controllers, Services, Middleware)
- TypeScript
- Prisma ORM + migrations + seed scripts
- PostgreSQL (or another SQL DB)
- Infobip SMS API for OTP

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client (Mobile/Web)"]:::client

    %% API Layer
    subgraph "API Layer"
        direction TB
        AppMain["Application Entry (main.ts)"]:::api
        AppModule["Root Module (app.module.ts)"]:::api
        JWTMiddleware["JWT Middleware"]:::api
        AuthController["Auth Controller"]:::api
        UsersController["Users Controller"]:::api
        RestaurantsController["Restaurants Controller"]:::api
        CategoriesController["Categories Controller"]:::api
        ProductsController["Product Controller"]:::api
        BasketController["Basket Controller"]:::api
        FavoritesController["Favorites Controller"]:::api
        RatingsController["Ratings Controller"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        AuthService["Auth Service"]:::service
        OTPService["OTP Service"]:::service
        UsersService["Users Service"]:::service
        RestaurantsService["Restaurants Service"]:::service
        CategoriesService["Categories Service"]:::service
        ProductService["Product Service"]:::service
        BasketService["Basket Service"]:::service
        FavoritesService["Favorites Service"]:::service
        RatingsService["Ratings Service"]:::service
        ResponseHelper["Response Helper"]:::service
        BasketFormatter["Basket Formatter"]:::service

        %% DTOs
        OAuthDTO["OAuth DTO"]:::dto
        UpdateUserPhoneDTO["UpdateUserPhone DTO"]:::dto
        UpdateUserProfileDTO["UpdateUserProfile DTO"]:::dto
        GetRestaurantDTO["GetRestaurant DTO"]:::dto
        UpdateBasketDTO["UpdateBasket DTO"]:::dto
        ActionsFavoriteDTO["ActionsFavorite DTO"]:::dto
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PrismaService["Prisma Client Service"]:::data
        DB["PostgreSQL Database"]:::data
        Migrations["Database Migrations"]:::data
        SchemaDefs["Schema Definitions"]:::data
        SeedScripts["Seed Scripts"]:::data
    end

    %% External
    subgraph "External Services"
        direction TB
        Infobip["Infobip SMS API"]:::external
    end

    %% Connections
    Client -->|calls HTTP| AppMain
    AppMain --> AppModule
    AppModule --> JWTMiddleware
    JWTMiddleware --> AuthController
    JWTMiddleware --> UsersController
    JWTMiddleware --> RestaurantsController
    JWTMiddleware --> CategoriesController
    JWTMiddleware --> ProductsController
    JWTMiddleware --> BasketController
    JWTMiddleware --> FavoritesController
    JWTMiddleware --> RatingsController

    AuthController -->|uses| AuthService
    UsersController -->|uses| UsersService
    RestaurantsController -->|uses| RestaurantsService
    CategoriesController -->|uses| CategoriesService
    ProductsController -->|uses| ProductService
    BasketController -->|uses| BasketService
    FavoritesController -->|uses| FavoritesService
    RatingsController -->|uses| RatingsService

    AuthService -->|calls| OTPService
    OTPService -->|sends SMS| Infobip

    AuthService -->|reads/writes| PrismaService
    UsersService -->|reads/writes| PrismaService
    RestaurantsService -->|reads/writes| PrismaService
    CategoriesService -->|reads/writes| PrismaService
    ProductService -->|reads/writes| PrismaService
    BasketService -->|reads/writes| PrismaService
    FavoritesService -->|reads/writes| PrismaService
    RatingsService -->|reads/writes| PrismaService

    BasketService --> BasketFormatter
    AllServices --> ResponseHelper

    PrismaService -->|executes SQL| DB
    Migrations -->|run on startup| DB
    SeedScripts -->|populate| DB
    SchemaDefs -->|define tables| DB

    %% DTO relationships
    AuthController --> OAuthDTO
    UsersController --> UpdateUserPhoneDTO
    UsersController --> UpdateUserProfileDTO
    RestaurantsController --> GetRestaurantDTO
    BasketController --> UpdateBasketDTO
    FavoritesController --> ActionsFavoriteDTO

    %% Click Events
    click AuthModule "https://github.com/alad1n0/project-back/blob/main/src/auth/auth.module.ts"
    click AuthController "https://github.com/alad1n0/project-back/blob/main/src/auth/auth.controller.ts"
    click AuthService "https://github.com/alad1n0/project-back/blob/main/src/auth/auth.service.ts"
    click OAuthDTO "https://github.com/alad1n0/project-back/blob/main/src/auth/dto/oauth.dto.ts"
    click UsersModule "https://github.com/alad1n0/project-back/blob/main/src/users/users.module.ts"
    click UsersController "https://github.com/alad1n0/project-back/blob/main/src/users/users.controller.ts"
    click UsersService "https://github.com/alad1n0/project-back/blob/main/src/users/users.service.ts"
    click UpdateUserPhoneDTO "https://github.com/alad1n0/project-back/blob/main/src/users/dto/update-user-phone.dto.ts"
    click UpdateUserProfileDTO "https://github.com/alad1n0/project-back/blob/main/src/users/dto/update-user-profile.dto.ts"
    click RestaurantsModule "https://github.com/alad1n0/project-back/blob/main/src/restaurants/restaurants.module.ts"
    click RestaurantsController "https://github.com/alad1n0/project-back/blob/main/src/restaurants/restaurants.controller.ts"
    click RestaurantsService "https://github.com/alad1n0/project-back/blob/main/src/restaurants/restaurants.service.ts"
    click GetRestaurantDTO "https://github.com/alad1n0/project-back/blob/main/src/restaurants/dto/get-restaurant.dto.ts"
    click CategoriesModule "https://github.com/alad1n0/project-back/blob/main/src/categories/categories.module.ts"
    click CategoriesController "https://github.com/alad1n0/project-back/blob/main/src/categories/categories.controller.ts"
    click CategoriesService "https://github.com/alad1n0/project-back/blob/main/src/categories/categories.service.ts"
    click ProductsModule "https://github.com/alad1n0/project-back/blob/main/src/product/product.module.ts"
    click ProductsController "https://github.com/alad1n0/project-back/blob/main/src/product/product.controller.ts"
    click ProductService "https://github.com/alad1n0/project-back/blob/main/src/product/product.service.ts"
    click BasketModule "https://github.com/alad1n0/project-back/blob/main/src/basket/basket.module.ts"
    click BasketController "https://github.com/alad1n0/project-back/blob/main/src/basket/basket.controller.ts"
    click BasketService "https://github.com/alad1n0/project-back/blob/main/src/basket/basket.service.ts"
    click UpdateBasketDTO "https://github.com/alad1n0/project-back/blob/main/src/basket/dto/update-basket.dto.ts"
    click BasketFormatter "https://github.com/alad1n0/project-back/blob/main/src/basket/helper/basket.formatter.ts"
    click FavoritesModule "https://github.com/alad1n0/project-back/blob/main/src/favorites/favorites.module.ts"
    click FavoritesController "https://github.com/alad1n0/project-back/blob/main/src/favorites/favorites.controller.ts"
    click FavoritesService "https://github.com/alad1n0/project-back/blob/main/src/favorites/favorites.service.ts"
    click ActionsFavoriteDTO "https://github.com/alad1n0/project-back/blob/main/src/favorites/dto/actions-favorite.dto.ts"
    click RatingsModule "https://github.com/alad1n0/project-back/blob/main/src/rating/ratings.module.ts"
    click RatingsController "https://github.com/alad1n0/project-back/blob/main/src/rating/ratings.controller.ts"
    click RatingsService "https://github.com/alad1n0/project-back/blob/main/src/rating/ratings.service.ts"
    click OTPService "https://github.com/alad1n0/project-back/blob/main/src/service/otp/otp.service.ts"
    click Infobip "https://github.com/alad1n0/project-back/blob/main/src/config/infobip.config.ts"
    click JWTMiddleware "https://github.com/alad1n0/project-back/blob/main/src/middleware/jwt.middleware.ts"
    click PrismaService "https://github.com/alad1n0/project-back/blob/main/src/prisma/prisma.service.ts"
    click ResponseHelper "https://github.com/alad1n0/project-back/blob/main/src/helper/response.helper.ts"
    click Migrations "https://github.com/alad1n0/project-back/tree/main/prisma/migrations/**"
    click SchemaDefs "https://github.com/alad1n0/project-back/tree/main/prisma/schema/**"
    click SeedScripts "https://github.com/alad1n0/project-back/blob/main/prisma/seed/*.seed.ts"
    click AppMain "https://github.com/alad1n0/project-back/blob/main/src/main.ts"
    click AppModule "https://github.com/alad1n0/project-back/blob/main/src/app.module.ts"

    %% Styles
    classDef client fill:#E0FFFF,stroke:#333,stroke-width:1px
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef dto fill:#98FB98,stroke:#333,stroke-width:1px
    classDef data fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
