# fernandofedora/warehouse-link architecture

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

- Interactive diagram: https://gitdiagram.com/fernandofedora/warehouse-link
- Repository: https://github.com/fernandofedora/warehouse-link

## Overview

##### Project type and purpose
- Apoco Links is a full-stack web application for securely storing and managing user links.
- It uses Node.js/Express on the backend, MySQL for persistence, Handlebars/Bootstrap on the frontend, and Passport for authentication.

##### File structure
- Top-level entry: src/index.js initializes the Express server, loads middleware, and mounts routes.
- src/config.js, src/keys.js, src/database.js handle configuration and MySQL connection.
- src/lib contains utility modules: authentication logic (auth.js, passport.js), Handlebars helpers, generic helpers.
- src/routes holds the MVC-style controllers: index.js (home), authentication.js (signin/signup), links.js (CRUD operations).
- src/views has Handlebars templates (layouts, partials, auth, links pages).
- src/public serves static assets (CSS, images).
- database/db.sql defines the schema, express-mysql-session uses a dedicated session table.
- vercel.json and package.json hold deployment and dependency configs.

##### Extract insights from the README
- Core features: user authentication, CRUD for links, flash messages, session-based persistence.
- Middleware stack: express-session + express-mysql-session, connect-flash, morgan logger.
- Tech stack reinforcement: Node.js, Express, MySQL, Handlebars, Passport.js, Bootstrap.

a. Main components
– Client (Browser)
– Web Server (Node.js + Express)
- Middleware layer (sessions, flash, logging)
- Routing layer (src/routes)
- Service / business logic (src/lib/auth, helpers)
– Template Engine (Handlebars views + static assets)
– Database (MySQL)
– Session Store (express-mysql-session tables)
– External Library (Passport.js for authentication)

b. Relationships and interactions
1. Browser sends HTTP request (GET/POST/DELETE) →
2. Express middleware chain (logging, session loader, flash) →
3. Router resolves endpoint →
4. Controller calls service logic →
5. Service layer queries MySQL (via src/database.js) →
6. Results return to controller →
7. Controller renders Handlebars view or returns JSON →
8. Response sent back to Browser; static assets (CSS/JS/images) served from /public

c. Architectural patterns and design principles
- Layered architecture: client, presentation (views), application (routes + lib), data access (database.js).
- MVC-style separation between routes (controllers), views, and data.
- Middleware pipeline for cross-cutting concerns (authentication, sessions, logging).

d. Key technologies/frameworks
- Node.js & Express (server, routing, middleware)
- MySQL + express-mysql-session (data persistence & session store)
- Handlebars (templating)
- Passport.js (authentication strategy)
- -flash (flash messages)
- Morgan (HTTP request logging)
- Bootstrap (UI styling)

##### Detail and essential elements
- Every layer: from HTTP listener through middleware to DB queries.
- Integration points (e.g., where Passport hooks in, where sessions are persisted).
- Configuration files (config.js, keys.js) if they influence component behavior (e.g., DB credentials, session secret).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["Browser"]:::frontend
        Handlebars["Handlebars Templates"]:::frontend
        StaticAssets["Static Assets (CSS/JS/images)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        ExpressServer["Express Server"]:::backend
        click ExpressServer "https://github.com/fernandofedora/warehouse-link/blob/master/src/index.js"

        subgraph "Middleware Layer"
            MorganLogger["Morgan Logger"]:::backend
            click MorganLogger "https://github.com/fernandofedora/warehouse-link/blob/master/src/index.js"
            SessionFlash["Session & Flash"]:::backend
            click SessionFlash "https://github.com/fernandofedora/warehouse-link/blob/master/src/index.js"
            PassportJS["Passport.js"]:::external
            click PassportJS "https://github.com/fernandofedora/warehouse-link/blob/master/src/lib/passport.js"
        end

        subgraph "Routing Layer"
            IndexRoutes["Express Router - Home"]:::backend
            click IndexRoutes "https://github.com/fernandofedora/warehouse-link/blob/master/src/routes/index.js"
            AuthRoutes["Express Router - Auth"]:::backend
            click AuthRoutes "https://github.com/fernandofedora/warehouse-link/blob/master/src/routes/authentication.js"
            LinksRoutes["Express Router - Links"]:::backend
            click LinksRoutes "https://github.com/fernandofedora/warehouse-link/blob/master/src/routes/links.js"
        end

        subgraph "Business Logic Layer"
            AuthHelpers["Auth Helpers"]:::backend
            click AuthHelpers "https://github.com/fernandofedora/warehouse-link/blob/master/src/lib/auth.js"
            HandlebarsHelpers["Handlebars Helpers"]:::backend
            click HandlebarsHelpers "https://github.com/fernandofedora/warehouse-link/blob/master/src/lib/handlebars.js"
            GenericHelpers["Generic Helpers"]:::backend
            click GenericHelpers "https://github.com/fernandofedora/warehouse-link/blob/master/src/lib/helpers.js"
        end

        subgraph "Data Access & Config"
            DBConnection["Database Connection"]:::backend
            click DBConnection "https://github.com/fernandofedora/warehouse-link/blob/master/src/database.js"
            Config["Configuration"]:::backend
            click Config "https://github.com/fernandofedora/warehouse-link/blob/master/src/config.js"
            Keys["Environment Keys"]:::backend
            click Keys "https://github.com/fernandofedora/warehouse-link/blob/master/src/keys.js"
        end
    end

    %% Data Stores
    subgraph "Data Stores"
        MySQL["MySQL Server"]:::datastore
        SessionTable["Session Store Table"]:::datastore
        SQLSchema["Schema Definition"]:::datastore
        click SQLSchema "https://github.com/fernandofedora/warehouse-link/blob/master/database/db.sql"
    end

    %% Deployment Config
    PackageJSON["package.json"]:::backend
    click PackageJSON "https://github.com/fernandofedora/warehouse-link/blob/master/package.json"
    VercelJSON["vercel.json"]:::backend
    click VercelJSON "https://github.com/fernandofedora/warehouse-link/blob/master/vercel.json"

    %% Request/Response Flow
    Browser -->|"HTTP Request"| ExpressServer
    ExpressServer --> MorganLogger
    ExpressServer --> SessionFlash
    ExpressServer --> PassportJS
    ExpressServer --> IndexRoutes
    ExpressServer --> AuthRoutes
    ExpressServer --> LinksRoutes

    IndexRoutes --> AuthHelpers
    AuthRoutes --> AuthHelpers
    LinksRoutes --> GenericHelpers

    AuthHelpers --> PassportJS
    AuthHelpers --> DBConnection
    GenericHelpers --> DBConnection

    DBConnection --> MySQL
    SessionFlash --> SessionTable
    SessionTable --> MySQL
    SQLSchema --> MySQL

    IndexRoutes --> Handlebars
    AuthRoutes --> Handlebars
    LinksRoutes --> Handlebars

    ExpressServer --> StaticAssets

    Handlebars --> Browser
    StaticAssets --> Browser

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef datastore fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
