# vodangcmu/pizzaorderingbackend architecture

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

- Interactive diagram: https://gitdiagram.com/vodangcmu/pizzaorderingbackend
- Repository: https://github.com/vodangcmu/pizzaorderingbackend

## Overview

##### Project Type and Purpose
- This is a backend REST API built quickly with TypeScript aimed at managing pizza orders, user accounts, cart and invoice management, and providing functionalities around pizza customization (e.g., crusts, extras, sizes, etc.).
- The README indicates that it is meant for development as well as production deployment via Docker or PM2, confirming its intended use as a server-side application.

##### Analyzing the File Structure
- Top-level Files and Configurations:
- Files like Dockerfile, .dockerignore, nodemon.json, package.json, and tsconfig.json show that the project is container-ready and uses TypeScript.
- The README instructions and Docker workflows in the .github/workflows directory offer details on deployment.
- Main Source Directory – "src":
- The "src" folder contains all core logic including the entry point (src/index.ts), the database connection (src/data-source.ts), and environment configurations (src/env.ts).
- The "entity" folder lists the various data models (e.g., Pizza, Cart, Users, etc.) corresponding to data tables.
- The "routes" folder is structured into subfolders by domain (auth, cart, ingredient, invoice, pizza, etc.) that implement the REST endpoints.
- The "middlewares" folder contains various request interceptors to enforce security and test-only flows.
- The "migrations" folder includes all database schema transformations.
- Additional folders like "schemas", "runner", "types", etc., hint at custom validation, migration generation, and global custom types.

##### Essential Components
a. Main Components to Include:
- API Layer: The overall server exposed by src/index.ts.
- Business Logic Modules: Each domain (e.g., authentication, pizza, cart, ingredient, invoice, user, feedback) represented by their respective route and entity files.
- Middleware Services: Authorization and authentication, logging, injections, testing utilities.
- Database: Represent the underlying relational database which is manipulated via migrations and data-source definitions.
- Deployment/Operational Components: Docker container (with production Dockerfile and GitHub CI/CD workflows), and PM2 for process management.
- Utility Components: Logger, custom schemas, runner scripts for migration operations.

b. Relationships and Interactions:
- Incoming HTTP requests are received by the API server (src/index.ts) and then routed to appropriate domain routes (e.g., routes/auth, routes/pizza, etc.).
- Middlewares (isAuth, isAdmin, isStaff) intercept these requests to validate sessions and enforce permissions.
- Each route handler interacts with the database via the entities and underlying ORM or data-source (likely using TypeORM based on migrations and entity files).
- Responses are sent back to the client following data processing.
- Deployment infrastructure interacts with the application via Docker or PM2 commands, as specified in the README and GitHub workflows.

c. Architectural Patterns and Design Principles:
- Modularization: Clear separation of concerns with domain-based routing and isolated entities.
- Middleware Pattern: Handling authentication, admin checks, etc.
- Migration-based Database Evolution: Use of migration scripts for evolving schema versions.
- Containerization: Use of Docker for consistent deployment.
- Continuous Integration/Deployment: Through GitHub workflows configuration.

d. Relevant Technologies and Frameworks:
- TypeScript: Language of choice.
- Node.js: Execution environment.
- Likely usage of an ORM (potentially TypeORM, or a similar library) based on the migration and entity patterns.
- Docker and PM2: For deployment.
- Testing tools: Jest configurations suggest testing integration (multiple jest.config files).

##### Instructing the Principal Software Engineer
- A section for Database, indicating migrations and entities (list of files under src/entity and src/migrations).
- A middleware component layer that intercepts requests (isAuth, isAdmin, etc.).
- An external deployment infrastructure block (Docker, GitHub workflows, PM2) to show how the app is built, containerized, and deployed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("HTTP Request"):::external
    B("API Server"):::api
    A --> B

    subgraph "Middleware Layer"
        M1("isAuth"):::middleware
        M2("isAdmin"):::middleware
        M3("isStaff"):::middleware
        M4("isOnTesting"):::middleware
        M5("injectCoreServices"):::middleware
    end

    B --> M1

    subgraph "Auth Module"
        AAuth("Auth Router"):::module
        ALogin("Login"):::module
        ARegister("Register"):::module
    end

    subgraph "Pizza Module"
        PPizza("Pizza Router"):::module
        PCreate("Create Pizza"):::module
        PGet("Get Pizza"):::module
    end

    subgraph "Cart Module"
        CRouter("Cart Router"):::module
        CAdd("Add Item To Cart"):::module
        CCreate("Create Cart"):::module
    end

    subgraph "Invoice Module"
        IRouter("Invoice Router"):::module
        ICreate("Create Invoice"):::module
        IGet("Get Invoice"):::module
    end

    FE("Feedback Router"):::module

    subgraph "Ingredient Module"
        InRouter("Ingredient Router"):::module
        InCreate("Create Ingredient"):::module
    end

    subgraph "User Module"
        URouter("User Router"):::module
        UGet("Get User By Id"):::module
    end

    M1 --> AAuth
    M1 --> PPizza
    M1 --> CRouter
    M1 --> IRouter
    M1 --> FE
    M1 --> InRouter
    M1 --> URouter

    subgraph "Persistence Layer"
        DB("DB Config"):::database
        EN("Entities"):::database
        MIG("Migrations"):::database
    end

    AAuth --> DB
    PPizza --> DB
    CRouter --> DB
    IRouter --> DB
    FE --> DB
    InRouter --> DB
    URouter --> DB

    DB --> EN
    DB --> MIG

    subgraph "Utilities"
        L("Logger"):::utility
        RSR("Runner Scripts"):::utility
        CS("Custom Schemas"):::utility
        GT("Global Types"):::utility
    end

    B --> L
    B --> RSR
    B --> CS
    B --> GT

    subgraph "Deployment/Operational"
        Docker("Docker Config"):::deploy
        CI("CI/CD Workflows"):::deploy
        PM2("Process Management"):::deploy
    end

    B --> Docker
    B --> CI
    B --> PM2

    %% Click Events
    click B "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/index.ts"
    click DB "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/data-source.ts"
    click EN "https://github.com/vodangcmu/pizzaorderingbackend/tree/master/src/entity"
    click MIG "https://github.com/vodangcmu/pizzaorderingbackend/tree/master/src/migrations"
    click AAuth "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/auth/auth.router.ts"
    click ALogin "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/auth/login.ts"
    click ARegister "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/auth/register.ts"
    click PPizza "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/pizza/pizza.router.ts"
    click PCreate "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/pizza/createPizza.ts"
    click PGet "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/pizza/getPizza.ts"
    click CRouter "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/cart/cart.router.ts"
    click CAdd "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/cart/addItemToCart.ts"
    click CCreate "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/cart/createCart.ts"
    click IRouter "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/invoice/invoice.router.ts"
    click ICreate "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/invoice/createInvoice.ts"
    click IGet "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/invoice/getInvoice.ts"
    click FE "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/feedback/feedback.router.ts"
    click InRouter "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/ingredient/ingredient.router.ts"
    click InCreate "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/ingredient/createIngredient.ts"
    click URouter "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/user/user.router.ts"
    click UGet "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/routes/user/getUserById.ts"
    click M1 "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/middlewares/isAuth.ts"
    click M2 "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/middlewares/isAdmin.ts"
    click M3 "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/middlewares/isStaff.ts"
    click M4 "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/middlewares/isOnTesting.ts"
    click M5 "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/middlewares/injectCoreServices.ts"
    click L "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/logger.ts"
    click RSR "https://github.com/vodangcmu/pizzaorderingbackend/tree/master/src/runner"
    click CS "https://github.com/vodangcmu/pizzaorderingbackend/tree/master/src/schemas"
    click GT "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/src/types/global-express.d.ts"
    click Docker "https://github.com/vodangcmu/pizzaorderingbackend/tree/master/Dockerfile"
    click CI "https://github.com/vodangcmu/pizzaorderingbackend/tree/master/.github/workflows"
    click PM2 "https://github.com/vodangcmu/pizzaorderingbackend/blob/master/nodemon.json"

    %% Styles
    classDef external fill:#F0F4C3,stroke:#333,stroke-width:2px;
    classDef api fill:#E3F2FD,stroke:#333,stroke-width:2px;
    classDef middleware fill:#FFECB3,stroke:#333,stroke-width:2px;
    classDef module fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef database fill:#FFCDD2,stroke:#333,stroke-width:2px;
    classDef deploy fill:#D1C4E9,stroke:#333,stroke-width:2px;
    classDef utility fill:#B3E5FC,stroke:#333,stroke-width:2px;
```
