# snack-25/back architecture

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

- Interactive diagram: https://gitdiagram.com/snack-25/back
- Repository: https://github.com/snack-25/back

## Overview

##### Overall Project Type and Purpose
- SNACK25 is a backend service built with NestJS for a one-stop snack purchasing management solution. Its purpose is to manage snack-related transactions and data in an organized and secure manner.
- The README confirms that the back-end leverages NestJS with a robust modular design, integrates with a PostgreSQL database (via Prisma), includes authentication (with JWT and Argon2), and utilizes Swagger for API documentation.

##### Main Components
a. Application Entry Point & Core Infrastructure
- Main entry (main.ts) that bootstraps the NestJS application.
- Global configurations (nest-cli.json, tsconfig, etc.) which affect the overall behavior.

b. Modular Domain Components (as individual blocks)
- Auth Module: Contains controllers, services, DTOs, strategies (JWT, guards) for managing authentication and authorization.
- Budgets, Carts, Categories, Companies, Invitations, Order Requests, Orders, Products, Users, and Wishlists Modules: Each domain module has its own controller, service, DTOs, and entity definitions. Outline these as separate components to show separation of concerns.

c. Shared Infrastructure and Services
- Shared Module: Include general utilities, helper functions, middleware, decorators, and any shared constants.
- AWS S3 Integration: Within the shared/aws directory, highlight that there is a dedicated S3 service and controller for managing file uploads/storage.
- Prisma Module: Clearly mark the Prisma integration (from both the prisma directory and shared/prisma) used for database access, including migration management and seed operations.

d. External Interfaces and Tools
- Database: Represent PostgreSQL as the primary persistence layer. Connect Prisma’s ORM functionality to it.
- API Documentation: Include Swagger as an external API documentation tool available via the /api route.
- CI/CD / Deployment: Optionally note the presence of GitHub workflows and Husky hooks that manage coding standards and deployment tasks.

##### Relationships and Interactions
- Auth components (controllers, guards, JWT strategies) to other modules where secure endpoints require authentication.
- That the shared services (for JWT, AWS S3, etc.) are used by multiple modules, denoting cross-module dependencies.

##### Architectural Patterns and Design Principles
- Modular structure of NestJS. Label groups as individual domain “modules” and highlight the Separation of Concerns between controllers (handling incoming requests), services (business logic), and Prisma (data access).
- A “Presentation Layer” for API controllers.
- A “Business Logic Layer” for services.
- A “Data Access Layer” for Prisma and the PostgreSQL database.
- “Infrastructure/Integration Components” for shared utilities (AWS S3, authentication, Swagger).

##### Final Assembly
- Start at the top with the application’s entry point, cascade into the separate modules, and finally point the modules’ interactions with both the PostgreSQL (via Prisma) and external integration services (AWS, Swagger).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Core
    subgraph "Application Core"
        EP["Application Entry / Configurations"]:::appCore
    end

    %% Domain Modules
    subgraph "Domain Modules"
        AM["Auth Module"]:::domain
        BM["Budgets Module"]:::domain
        CM["Carts Module"]:::domain
        CAT["Categories Module"]:::domain
        CO["Companies Module"]:::domain
        IN["Invitations Module"]:::domain
        ORQ["Order Requests Module"]:::domain
        ORD["Orders Module"]:::domain
        PMOD["Products Module"]:::domain
        UM["Users Module"]:::domain
        WM["Wishlists Module"]:::domain
    end

    %% Shared Infrastructure and Services
    subgraph "Shared Infrastructure"
        SU["Shared Utilities"]:::shared
        AWS["AWS S3 Integration"]:::shared
        SWAG["Swagger API Docs"]:::shared
        JWT["JWT Service"]:::shared
    end

    %% Prisma Integration
    subgraph "Prisma Integration"
        PRM["Prisma Module"]:::prisma
        PRMI["Prisma Migrations & Seeding"]:::prisma
    end

    %% External Interfaces / CI/CD
    subgraph "External Interfaces / CI/CD"
        EXT1["GitHub Workflows"]:::external
        EXT2["Husky Hooks"]:::external
    end

    %% Database
    DB(["PostgreSQL Database"]):::database

    %% Connections from Application Core to Domain Modules
    EP -->|"bootstraps"| AM
    EP -->|"bootstraps"| BM
    EP -->|"bootstraps"| CM
    EP -->|"bootstraps"| CAT
    EP -->|"bootstraps"| CO
    EP -->|"bootstraps"| IN
    EP -->|"bootstraps"| ORQ
    EP -->|"bootstraps"| ORD
    EP -->|"bootstraps"| PMOD
    EP -->|"bootstraps"| UM
    EP -->|"bootstraps"| WM

    %% Connections from Domain Modules to Prisma Integration
    AM -->|"uses"| PRM
    BM -->|"uses"| PRM
    CM -->|"uses"| PRM
    CAT -->|"uses"| PRM
    CO -->|"uses"| PRM
    IN -->|"uses"| PRM
    ORQ -->|"uses"| PRM
    ORD -->|"uses"| PRM
    PMOD -->|"uses"| PRM
    UM -->|"uses"| PRM
    WM -->|"uses"| PRM

    %% Auth Module specific connection to JWT Service
    AM -->|"authenticates_with"| JWT

    %% Products Module uses AWS S3 Integration for media/storage
    PMOD -->|"integrates_with"| AWS

    %% Application Entry also provides API Documentation via Swagger
    EP -->|"documents"| SWAG

    %% Prisma Integration internal connection and connection to Database
    PRM -->|"manages"| PRMI
    PRMI -->|"applies_to"| DB

    %% External Interfaces connections to Application Core (CI/CD triggers)
    EXT1 -.->|"deploys"| EP
    EXT2 -.->|"checks"| EP

    %% Classes and styles
    classDef appCore fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef domain fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef shared fill:#ffff99,stroke:#000,stroke-width:1px;
    classDef prisma fill:#ffb6c1,stroke:#000,stroke-width:1px;
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef database fill:#f08080,stroke:#000,stroke-width:1px;

    %% Click Events for Application Core
    click EP "https://github.com/snack-25/back/blob/main/src/main.ts"

    %% Click Events for Domain Modules
    click AM "https://github.com/snack-25/back/tree/main/src/auth"
    click BM "https://github.com/snack-25/back/tree/main/src/budgets"
    click CM "https://github.com/snack-25/back/tree/main/src/carts"
    click CAT "https://github.com/snack-25/back/tree/main/src/categories"
    click CO "https://github.com/snack-25/back/tree/main/src/companies"
    click IN "https://github.com/snack-25/back/tree/main/src/invitations"
    click ORQ "https://github.com/snack-25/back/tree/main/src/order-requests"
    click ORD "https://github.com/snack-25/back/tree/main/src/orders"
    click PMOD "https://github.com/snack-25/back/tree/main/src/products"
    click UM "https://github.com/snack-25/back/tree/main/src/users"
    click WM "https://github.com/snack-25/back/tree/main/src/wishlists"

    %% Click Events for Shared Infrastructure and Services
    click SU "https://github.com/snack-25/back/tree/main/src/shared"
    click AWS "https://github.com/snack-25/back/tree/main/src/shared/aws"
    click SWAG "https://github.com/snack-25/back/tree/main/src/shared/swagger"
    click JWT "https://github.com/snack-25/back/blob/main/src/shared/services/jwt.service.ts"

    %% Click Events for Prisma Integration
    click PRM "https://github.com/snack-25/back/tree/main/src/shared/prisma"
    click PRMI "https://github.com/snack-25/back/tree/main/prisma"

    %% Click Events for External Interfaces / CI/CD
    click EXT1 "https://github.com/snack-25/back/tree/main/.github/workflows"
    click EXT2 "https://github.com/snack-25/back/blob/main/.husky"
```
