# guayamose/safebyte architecture

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

- Interactive diagram: https://gitdiagram.com/guayamose/safebyte
- Repository: https://github.com/guayamose/safebyte

## Overview

##### Project type and purpose
- It uses Entity Framework Core for data persistence (ApplicationDbContext and migrations), serves static assets (Bootstrap, jQuery, custom CSS/JS), and exposes controllers for authentication and general pages.

##### File structure
- Top-level directories:
– Backend1: ASP.NET Core MVC project
– node_modules, package.json, package-lock.json: likely used for client-side package management (Bootstrap, jQuery)
- Backend1/Controllers: Web API and page controllers (AuthController, HomeController)
- Backend1/Views: Razor view templates under Home and Shared
- Backend1/Data + Migrations: EF Core DbContext and migration snapshots
- Backend1/Models: Domain entities (User, Allergen, FileDatabase, UserAllergen, ErrorViewModel)
- Backend1/wwwroot: Static web assets (html pages, Bootstrap, jQuery, custom CSS/JS under src)

##### Main components and relationships
a. Components:
1. Client Browser
2. ASP.NET Core Web Host (Kestrel/IIS)
3. MVC Pipeline:
- Routing → Controllers (AuthController, HomeController) → Views (Razor)
4. Static Asset Server (wwwroot: Bootstrap, jQuery, custom JS, HTML pages under comidas.html, home.html, index.html)
5. Entity Framework Core Data Access (ApplicationDbContext)
6. Relational Database (SQL Server or SQLite configured via appsettings.json)
7. (Optional) External services or APIs (none explicit in file tree)

b. Interactions:
– Browser sends HTTP requests → Web Host
– Web Host routes to MVC Controller → controller executes business logic → interacts with DbContext → issues SQL queries to Database
– Controller returns a Razor View or JSON (AuthController)
– Browser fetches static files (CSS/JS) from the Static Asset Server
– Client-side scripts call backend endpoints (e.g., login form POST to AuthController)

c. Architectural patterns:
– MVC (Model-View-Controller)
– Repository/Unit of Work implicitly via EF Core DbContext
– Separation of concerns: Controllers (API/business logic), Models (domain objects), Views/static assets (presentation)

d. Key technologies:
– ASP.NET Core 8.0
– Entity Framework Core
– Razor Pages (Views)
– Bootstrap, jQuery for front end
– Node/NPM for front-end package management

– MVC Pipeline → Controllers (AuthController, HomeController)
– Static File Middleware → wwwroot
– ApplicationDbContext (in Data Access layer)
– Views (Razor templates in Views folder)
7. Important config files (appsettings.json → Database connection) and the migrations folder as part of the Data Access layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Client Browser"]:::client

    %% Server Host
    Browser -->|"HTTP GET/POST"| WebHost
    subgraph "Web Host (ASP.NET Core)" 
        direction TB
        ControllersLayer["MVC Pipeline"]:::server
        StaticLayer["Static File Middleware (wwwroot)"]:::fs
        DataAccessLayer["Data Access (EF Core)"]:::server

        ControllersLayer --> |"calls"| ApplicationDbContext
        ControllersLayer --> |"returns View/JSON"| Views
        ApplicationDbContext -->|"SQL Queries"| Database
        StaticLayer -->|"serve HTML/CSS/JS"| Browser
    end

    WebHost --> ControllersLayer
    WebHost --> StaticLayer
    WebHost --> DataAccessLayer

    %% Controllers
    subgraph "Controllers Layer"
        direction TB
        AuthController["AuthController"]:::server
        HomeController["HomeController"]:::server
    end
    ControllersLayer --> AuthController
    ControllersLayer --> HomeController

    %% Views
    subgraph "Views (Razor Templates)"
        direction TB
        IndexCshtml["Index.cshtml"]:::fs
        PrivacyCshtml["Privacy.cshtml"]:::fs
        LayoutCshtml["_Layout.cshtml"]:::fs
        ErrorCshtml["Error.cshtml"]:::fs
        ValidationPartial["_ValidationScriptsPartial.cshtml"]:::fs
        ViewImports["_ViewImports.cshtml"]:::fs
        ViewStart["_ViewStart.cshtml"]:::fs
    end
    Views["Views"]:::fs
    Views --> IndexCshtml
    Views --> PrivacyCshtml
    Views --> LayoutCshtml
    Views --> ErrorCshtml
    Views --> ValidationPartial
    Views --> ViewImports
    Views --> ViewStart

    ControllersLayer --> Views

    %% Static Files
    subgraph "Static Assets (wwwroot)"
        direction TB
        HTMLIndex["index.html"]:::fs
        HTMLHome["home.html"]:::fs
        HTMLComidas["comidas.html"]:::fs
        subgraph "Lib Libraries"
            direction TB
            BootstrapLib["bootstrap/"]:::fs
            JQueryLib["jquery/"]:::fs
            JQueryVal["jquery-validation/"]:::fs
            JQueryUno["jquery-validation-unobtrusive/"]:::fs
        end
        subgraph "Custom Scripts & Styles"
            direction TB
            CSSFolder["css/"]:::fs
            LoginJS["formulariologin.js"]:::fs
            VentanasFolder["ventanas/"]:::fs
        end
    end
    StaticLayer --> HTMLIndex
    StaticLayer --> HTMLHome
    StaticLayer --> HTMLComidas
    StaticLayer --> BootstrapLib
    StaticLayer --> JQueryLib
    StaticLayer --> JQueryVal
    StaticLayer --> JQueryUno
    StaticLayer --> CSSFolder
    StaticLayer --> LoginJS
    StaticLayer --> VentanasFolder

    %% Data Access & Domain Models
    subgraph "Data Access Layer"
        direction TB
        ApplicationDbContext["ApplicationDbContext"]:::server
        subgraph "Migrations"
            direction TB
            MigrationInitial["20250505212645_InitialCreate.cs"]:::server
            MigrationDesigner["20250505212645_InitialCreate.Designer.cs"]:::server
            ModelSnapshot["ApplicationDbContextModelSnapshot.cs"]:::server
        end
        subgraph "Domain Models"
            direction TB
            UserModel["User.cs"]:::server
            AllergenModel["Allergen.cs"]:::server
            FileDbModel["FileDatabase.cs"]:::server
            UserAllergenModel["UserAllergen.cs"]:::server
            ErrorViewModel["ErrorViewModel.cs"]:::server
        end
    end
    DataAccessLayer --> ApplicationDbContext
    ApplicationDbContext --> MigrationInitial
    ApplicationDbContext --> MigrationDesigner
    ApplicationDbContext --> ModelSnapshot
    ApplicationDbContext --> UserModel
    ApplicationDbContext --> AllergenModel
    ApplicationDbContext --> FileDbModel
    ApplicationDbContext --> UserAllergenModel
    ApplicationDbContext --> ErrorViewModel

    %% Database
    Database["Relational Database"]:::db

    %% Solution & Config
    subgraph "Configuration & Startup"
        direction TB
        AppSettings["appsettings.json"]:::config
        DevSettings["appsettings.Development.json"]:::config
        ProgramCS["Program.cs"]:::config
        LaunchSettings["launchSettings.json"]:::config
        Solution["SafeByte.sln"]:::config
        PackageJSON["package.json"]:::config
        PackageLock["package-lock.json"]:::config
        NodeModules["node_modules/"]:::config
    end

    WebHost --> AppSettings
    WebHost --> DevSettings
    WebHost --> ProgramCS
    WebHost --> LaunchSettings
    Solution --> WebHost
    Browser --> PackageJSON
    Browser --> PackageLock
    Browser --> NodeModules

    %% Click Events
    click HTMLIndex "https://github.com/guayamose/safebyte/blob/main/Backend1/wwwroot/index.html"
    click HTMLHome "https://github.com/guayamose/safebyte/blob/main/Backend1/wwwroot/home.html"
    click HTMLComidas "https://github.com/guayamose/safebyte/blob/main/Backend1/wwwroot/comidas.html"
    click BootstrapLib "https://github.com/guayamose/safebyte/tree/main/Backend1/wwwroot/lib/bootstrap/"
    click JQueryLib "https://github.com/guayamose/safebyte/tree/main/Backend1/wwwroot/lib/jquery/"
    click JQueryVal "https://github.com/guayamose/safebyte/tree/main/Backend1/wwwroot/lib/jquery-validation/"
    click JQueryUno "https://github.com/guayamose/safebyte/tree/main/Backend1/wwwroot/lib/jquery-validation-unobtrusive/"
    click CSSFolder "https://github.com/guayamose/safebyte/tree/main/Backend1/wwwroot/src/css/"
    click LoginJS "https://github.com/guayamose/safebyte/blob/main/Backend1/wwwroot/src/elementos/formulariologin.js"
    click VentanasFolder "https://github.com/guayamose/safebyte/tree/main/Backend1/wwwroot/src/ventanas/"
    click ProgramCS "https://github.com/guayamose/safebyte/blob/main/Backend1/Program.cs"
    click LaunchSettings "https://github.com/guayamose/safebyte/blob/main/Backend1/Properties/launchSettings.json"
    click AuthController "https://github.com/guayamose/safebyte/blob/main/Backend1/Controllers/AuthController.cs"
    click HomeController "https://github.com/guayamose/safebyte/blob/main/Backend1/Controllers/HomeController.cs"
    click IndexCshtml "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/Home/Index.cshtml"
    click PrivacyCshtml "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/Home/Privacy.cshtml"
    click LayoutCshtml "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/Shared/_Layout.cshtml"
    click ErrorCshtml "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/Shared/Error.cshtml"
    click ValidationPartial "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/Shared/_ValidationScriptsPartial.cshtml"
    click ViewImports "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/_ViewImports.cshtml"
    click ViewStart "https://github.com/guayamose/safebyte/blob/main/Backend1/Views/_ViewStart.cshtml"
    click ApplicationDbContext "https://github.com/guayamose/safebyte/blob/main/Backend1/Data/ApplicationDbContext.cs"
    click MigrationInitial "https://github.com/guayamose/safebyte/blob/main/Backend1/Migrations/20250505212645_InitialCreate.cs"
    click MigrationDesigner "https://github.com/guayamose/safebyte/blob/main/Backend1/Migrations/20250505212645_InitialCreate.Designer.cs"
    click ModelSnapshot "https://github.com/guayamose/safebyte/blob/main/Backend1/Migrations/ApplicationDbContextModelSnapshot.cs"
    click UserModel "https://github.com/guayamose/safebyte/blob/main/Backend1/Models/User.cs"
    click AllergenModel "https://github.com/guayamose/safebyte/blob/main/Backend1/Models/Allergen.cs"
    click FileDbModel "https://github.com/guayamose/safebyte/blob/main/Backend1/Models/FileDatabase.cs"
    click UserAllergenModel "https://github.com/guayamose/safebyte/blob/main/Backend1/Models/UserAllergen.cs"
    click ErrorViewModel "https://github.com/guayamose/safebyte/blob/main/Backend1/Models/ErrorViewModel.cs"
    click AppSettings "https://github.com/guayamose/safebyte/blob/main/Backend1/appsettings.json"
    click DevSettings "https://github.com/guayamose/safebyte/blob/main/Backend1/appsettings.Development.json"
    click Solution "https://github.com/guayamose/safebyte/blob/main/SafeByte.sln"
    click PackageJSON "https://github.com/guayamose/safebyte/blob/main/package.json"
    click PackageLock "https://github.com/guayamose/safebyte/blob/main/package-lock.json"
    click NodeModules "https://github.com/guayamose/safebyte/tree/main/node_modules/"

    %% Styles
    classDef client fill:#e2f7e2,stroke:#333,stroke-width:1px
    classDef server fill:#e2e8f6,stroke:#333,stroke-width:1px
    classDef db fill:#f7e2e2,stroke:#333,stroke-width:1px
    classDef fs fill:#f9f2e2,stroke:#333,stroke-width:1px
    classDef config fill:#f0e0f7,stroke:#333,stroke-width:1px
```
