# hamx05/the-recipe-spot architecture

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

- Interactive diagram: https://gitdiagram.com/hamx05/the-recipe-spot
- Repository: https://github.com/hamx05/the-recipe-spot

## Overview

##### Project type and purpose
- This is a monolithic full-stack web application (“The Recipe Spot”) that allows users to register, post, like, comment, search, and upload images for recipes.
- Frontend: static HTML (views/*.html), CSS (public/styles), and page-specific JavaScript.
- Backend: Node.js + Express (scripts/server.js + route modules).
- Persistence: SQLite databases in data/*.db.

##### File structure
- Top-level:
- data/ → SQLite files (recipes.db, users.db, backup_recipes.db)
- public/ → static assets (images/, styles/)
- views/ → HTML templates for each page
- scripts/ → Express entrypoint (server.js) and route/controller files (auth.js, signup.js, create-recipe.js, etc.)
- package.json / .env → configuration and dependencies
- Pattern: MVC-style separation—views/ = V, scripts/*.js = C + route definitions, data/*.db = M. Static assets served from public/.

##### README for architectural insights
- Tech stack confirms HTML/CSS/JS frontend, Node/Express backend, SQLite DB.
- Features imply RESTful endpoints for authentication, recipe CRUD, search, likes/comments, image uploads.

##### Main components & interactions (to represent
a. Client (Browser)
- UI Layer: views/*.html + CSS
- Front-end JS: public-served scripts (index.js, create-recipe.js, etc.) that call backend APIs via fetch/AJAX
b. Web Server (Express App)
- Entry: scripts/server.js
- Routing/Controllers: scripts/auth.js, create-recipe.js, dashboard.js, recipe-detail.js, user-profile.js, etc.
- Static middleware to serve public/ and views/
- Middleware for parsing form data, file uploads (images → public/images)
c. Database (SQLite)
- data/recipes.db (recipes, comments, likes)
- data/users.db (user accounts, sessions)
- data/backup_recipes.db (optional backups)
d. File Storage
- public/images (uploaded recipe images)
e. (Optional) Environment & Config
- .env for secrets (session keys, DB paths)

##### Relationships & data flows
- Browser requests HTML pages (GET /, /signin, /create-recipe, etc.) → Express serves views/*.html
- Browser loads CSS/JS (GET /styles/*.css, GET /scripts/*.js) → Express serves public/
- Front-end JS issues AJAX calls (e.g., POST /api/signup, GET /api/recipes?page=1) → Express route handlers → DB queries → JSON response
- File upload POST /api/recipes/image → Express file-upload middleware → save to public/images → return image URL
- All DB read/write flows: Express ↔ SQLite

##### Architectural patterns & design principles
- MVC-inspired: views (presentation), controllers/routes (business logic), models (SQLite tables accessed via simple SQL in controllers)
- Separation of concerns: static assets vs dynamic API, dedicated route modules for each feature
- Monolithic, single‐process server for simplicity—no microservices

##### Essential elements
- Component names (Browser, Express Server, SQLite DB, Image Store)
- Sub‐components (views/, public/, scripts/)
- Data flows (HTTP GET/POST, JSON, file upload)
- Config (.env) and dependency management (package.json)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        Browser["Browser"]:::client
        subgraph "Views (HTML Templates)"
            direction TB
            CR_HTML["create-recipe.html"]:::client
            DB_HTML["dashboard.html"]:::client
            H_HTML["home.html"]:::client
            I_HTML["index.html"]:::client
            RD_HTML["recipe-detail.html"]:::client
            S_HTML["signin.html"]:::client
            SU_HTML["signup.html"]:::client
            UP_HTML["user-profile.html"]:::client
        end
        subgraph "Styles (CSS)"
            direction TB
            CR_CSS["create-recipe.css"]:::client
            DB_CSS["dashboard.css"]:::client
            H_CSS["home.css"]:::client
            I_CSS["index.css"]:::client
            RD_CSS["recipe-detail.css"]:::client
            S_CSS["signin.css"]:::client
            SU_CSS["signup.css"]:::client
            UP_CSS["user-profile.css"]:::client
        end
    end

    %% Server Layer
    subgraph "Server (Express App)"
        direction TB
        Env[".env"]:::server
        PKG["package.json"]:::server
        PKG_LOCK["package-lock.json"]:::server

        ServerJS["server.js"]:::server

        subgraph "Middleware"
            direction TB
            Static["Static Middleware"]:::server
            Parser["Body-Parser"]:::server
            Upload["File Upload Middleware"]:::server
        end

        subgraph "Controllers / Routing"
            direction TB
            subgraph "Auth"
                Auth_JS["auth.js"]:::server
                Signin_JS["signin.js"]:::server
                Signup_JS["signup.js"]:::server
            end
            subgraph "Home/Index"
                Home_JS["home.js"]:::server
                Index_JS["index.js"]:::server
            end
            Dashboard_JS["dashboard.js"]:::server
            subgraph "Recipe Management"
                Create_JS["create-recipe.js"]:::server
                Detail_JS["recipe-detail.js"]:::server
            end
            Profile_JS["user-profile.js"]:::server
        end
    end

    %% Persistence Layer
    subgraph "Persistence & Storage"
        direction TB
        subgraph "SQLite Databases"
            direction TB
            RecipesDB["recipes.db"]:::storage
            UsersDB["users.db"]:::storage
            BackupDB["backup_recipes.db"]:::storage
        end
        ImageStore["public/images/"]:::storage
    end

    %% Connections
    Browser -->|"GET HTML"| ServerJS
    ServerJS -->|uses| Static
    ServerJS -->|loads config| Env
    ServerJS -->|loads deps| PKG
    Static -->|serves HTML| CR_HTML
    Static -->|serves HTML| DB_HTML
    Static -->|serves HTML| H_HTML
    Static -->|serves HTML| I_HTML
    Static -->|serves HTML| RD_HTML
    Static -->|serves HTML| S_HTML
    Static -->|serves HTML| SU_HTML
    Static -->|serves HTML| UP_HTML
    Static -->|serves CSS| CR_CSS
    Static -->|serves CSS| DB_CSS
    Static -->|serves CSS| H_CSS
    Static -->|serves CSS| I_CSS
    Static -->|serves CSS| RD_CSS
    Static -->|serves CSS| S_CSS
    Static -->|serves CSS| SU_CSS
    Static -->|serves CSS| UP_CSS

    Browser -->|"AJAX /api/... "| Auth_JS
    Browser -->|"AJAX /api/... "| Create_JS
    Browser -->|"AJAX /api/... "| Detail_JS
    Browser -->|"AJAX /api/... "| Dashboard_JS
    Browser -->|"AJAX /api/... "| Profile_JS
    Browser -->|"AJAX /api/... "| Home_JS

    Auth_JS -->|reads/writes| UsersDB
    Create_JS -->|reads/writes| RecipesDB
    Detail_JS -->|reads| RecipesDB
    Dashboard_JS -->|reads| RecipesDB
    Profile_JS -->|reads| UsersDB
    Home_JS -->|reads| RecipesDB

    Upload -->|saves image| ImageStore
    Create_JS -->|"POST /api/recipes/image"| Upload
    Upload -->|returns URL| Create_JS

    %% Click Events
    click Env "https://github.com/hamx05/the-recipe-spot/blob/main/.env"
    click PKG "https://github.com/hamx05/the-recipe-spot/blob/main/package.json"
    click PKG_LOCK "https://github.com/hamx05/the-recipe-spot/blob/main/package-lock.json"
    click ServerJS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/server.js"
    click Auth_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/auth.js"
    click Signin_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/signin.js"
    click Signup_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/signup.js"
    click Create_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/create-recipe.js"
    click Detail_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/recipe-detail.js"
    click Dashboard_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/dashboard.js"
    click Home_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/home.js"
    click Index_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/index.js"
    click Profile_JS "https://github.com/hamx05/the-recipe-spot/blob/main/scripts/user-profile.js"
    click CR_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/create-recipe.html"
    click DB_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/dashboard.html"
    click H_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/home.html"
    click I_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/index.html"
    click RD_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/recipe-detail.html"
    click S_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/signin.html"
    click SU_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/signup.html"
    click UP_HTML "https://github.com/hamx05/the-recipe-spot/blob/main/views/user-profile.html"
    click CR_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/create-recipe.css"
    click DB_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/dashboard.css"
    click H_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/home.css"
    click I_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/index.css"
    click RD_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/recipe-detail.css"
    click S_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/signin.css"
    click SU_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/signup.css"
    click UP_CSS "https://github.com/hamx05/the-recipe-spot/blob/main/public/styles/user-profile.css"
    click ImageStore "https://github.com/hamx05/the-recipe-spot/tree/main/public/images/"

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef storage fill:#fff3cd,stroke:#333,stroke-width:1px
```
