# valentincasas/laterne_web architecture

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

- Interactive diagram: https://gitdiagram.com/valentincasas/laterne_web
- Repository: https://github.com/valentincasas/laterne_web

## Overview

##### Project type and purpose
- This is a full-stack Node.js/Express web application (laterne_web) with server-side rendering (Jade templates) and client-side dynamic behaviors (fetch-based CRUD).
- It provides CRUD endpoints for resources like users, products, categories, events, testimonials, businessInfo, openingHours, and uses JWT for authentication.

##### File structure
- Top-level:
- app.js / index.js: Express server entrypoints
- config.js / db.js: configuration and database connection
- routes/: HTTP route definitions
- controllers/: request handlers that invoke business logic
- models/: ORM models and associations (MySQL schema via laterne.sql)
- middlewares/: auth checks (JWT validation)
- libs/jwt.js: JWT creation/verification
- views/: Jade templates for each page
- public/: static assets (CSS, JS, images, fetch scripts)
- Patterns:
- MVC: routes → controllers → models → DB
- RESTful endpoints under routes/*
- Server-side rendering + client-side fetch for dynamic UI

##### README
- Minimal description (“web laterne gino vale”) – no explicit architecture section.
- We infer stack: Node.js, Express, Jade (Pug), MySQL, JWT, Tailwind/PostCSS, Bootstrap/swiper.

##### Detailed capture of essential elements
- Break the server into sub-components matching the file tree:
- app.js/index.js (entry)
- config.js + db.js (setup)
- routes/ (10+ resource routes)
- controllers/ (CRUD + auth business logic)
- models/ (entities + associations)
- middlewares/authMiddleware.js
- libs/jwt.js
- public/ (static assets)
- Which controllers use JWT auth middleware.
- How dynamic fetch interactions bypass standard page rendering and hit JSON endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Browser"
    Templates["Jade Templates"]:::frontend
    CSS["CSS (Bootstrap/Tailwind)"]:::frontend
    JS["Client JS"]:::frontend
    Fetch["Fetch Scripts"]:::frontend
    Images["Images"]:::frontend
  end

  subgraph "Express Server"
    subgraph "Entry"
      AppJS["app.js"]:::backend
      IndexJS["index.js"]:::backend
    end
    subgraph "Configuration"
      Config["config.js"]:::backend
      DBSetup["db.js"]:::backend
      SQL["laterne.sql"]:::backend
    end
    subgraph "Routes"
      IndexRoutes["index.routes.js"]:::backend
      AuthRoutes["auth.routes.js"]:::backend
      UserRoutes["user.routes.js"]:::backend
      ProductRoutes["product.routes.js"]:::backend
      CategoryRoutes["category.routes.js"]:::backend
      EventRoutes["event.routes.js"]:::backend
      TestimonialRoutes["testimonial.routes.js"]:::backend
      BusinessRoutes["businessInfo.routes.js"]:::backend
      OpeningRoutes["openingHour.routes.js"]:::backend
      AsociationRoutes["asociation.routes.js"]:::backend
    end
    subgraph "Controllers"
      IndexCtrl["index.controller.js"]:::backend
      AuthCtrl["auth.controller.js"]:::backend
      UserCtrl["user.controller.js"]:::backend
      ProductCtrl["product.controller.js"]:::backend
      CategoryCtrl["category.controller.js"]:::backend
      EventCtrl["event.controller.js"]:::backend
      TestimonialCtrl["testimonial.controller.js"]:::backend
      BusinessCtrl["businessInfo.controller.js"]:::backend
      OpeningCtrl["openingHour.controller.js"]:::backend
      AsociationCtrl["asociation.controller.js"]:::backend
    end
    subgraph "Middleware"
      AuthMw["authMiddleware.js"]:::backend
    end
    subgraph "Libraries"
      JWTLib["jwt.js"]:::backend
    end
    subgraph "Models"
      AssocModel["associations.js"]:::backend
      UserModel["user.model.js"]:::backend
      ProductModel["product.model.js"]:::backend
      CategoryModel["category.model.js"]:::backend
      ProdCatModel["productCategory.model.js"]:::backend
      EventModel["event.model.js"]:::backend
      TestimonialModel["testimonial.model.js"]:::backend
      BusinessModel["businessInfo.model.js"]:::backend
      OpeningModel["openingHour.model.js"]:::backend
    end
  end

  Database["MySQL Database"]:::database

  Templates -->|renders via| AppJS
  CSS -->|served by| AppJS
  JS -->|served by| AppJS
  Fetch -->|API calls| AppJS
  Images -->|served by| AppJS
  AppJS -->|loads| Config
  AppJS -->|connects| DBSetup
  DBSetup -->|initializes| SQL
  AppJS -->|uses| IndexRoutes
  AppJS -->|uses| AuthRoutes
  AppJS -->|uses| UserRoutes
  AppJS -->|uses| ProductRoutes
  AppJS -->|uses| CategoryRoutes
  AppJS -->|uses| EventRoutes
  AppJS -->|uses| TestimonialRoutes
  AppJS -->|uses| BusinessRoutes
  AppJS -->|uses| OpeningRoutes
  AppJS -->|uses| AsociationRoutes
  IndexRoutes -->|calls| AuthMw
  AuthRoutes -->|protection| AuthMw
  IndexRoutes -->|invokes| IndexCtrl
  AuthRoutes -->|invokes| AuthCtrl
  UserRoutes -->|invokes| UserCtrl
  ProductRoutes -->|invokes| ProductCtrl
  CategoryRoutes -->|invokes| CategoryCtrl
  EventRoutes -->|invokes| EventCtrl
  TestimonialRoutes -->|invokes| TestimonialCtrl
  BusinessRoutes -->|invokes| BusinessCtrl
  OpeningRoutes -->|invokes| OpeningCtrl
  AsociationRoutes -->|invokes| AsociationCtrl
  AuthCtrl -->|uses| JWTLib
  IndexCtrl -->|queries| AssocModel
  UserCtrl -->|queries| UserModel
  ProductCtrl -->|queries| ProductModel
  CategoryCtrl -->|queries| CategoryModel
  ProductCtrl -->|queries| ProdCatModel
  EventCtrl -->|queries| EventModel
  TestimonialCtrl -->|queries| TestimonialModel
  BusinessCtrl -->|queries| BusinessModel
  OpeningCtrl -->|queries| OpeningModel
  AsociationCtrl -->|queries| AssocModel
  AssocModel -->|CRUD| Database
  UserModel -->|CRUD| Database
  ProductModel -->|CRUD| Database
  CategoryModel -->|CRUD| Database
  ProdCatModel -->|CRUD| Database
  EventModel -->|CRUD| Database
  TestimonialModel -->|CRUD| Database
  BusinessModel -->|CRUD| Database
  OpeningModel -->|CRUD| Database

  click AppJS "https://github.com/valentincasas/laterne_web/blob/main/app.js"
  click IndexJS "https://github.com/valentincasas/laterne_web/blob/main/index.js"
  click Config "https://github.com/valentincasas/laterne_web/blob/main/config.js"
  click DBSetup "https://github.com/valentincasas/laterne_web/blob/main/db.js"
  click SQL "https://github.com/valentincasas/laterne_web/blob/main/laterne.sql"
  click IndexRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/index.routes.js"
  click AuthRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/auth.routes.js"
  click UserRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/user.routes.js"
  click ProductRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/product.routes.js"
  click CategoryRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/category.routes.js"
  click EventRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/event.routes.js"
  click TestimonialRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/testimonial.routes.js"
  click BusinessRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/businessInfo.routes.js"
  click OpeningRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/openingHour.routes.js"
  click AsociationRoutes "https://github.com/valentincasas/laterne_web/blob/main/routes/asociation.routes.js"
  click IndexCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/index.controller.js"
  click AuthCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/auth.controller.js"
  click UserCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/user.controller.js"
  click ProductCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/product.controller.js"
  click CategoryCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/category.controller.js"
  click EventCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/event.controller.js"
  click TestimonialCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/testimonial.controller.js"
  click BusinessCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/businessInfo.controller.js"
  click OpeningCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/openingHour.controller.js"
  click AsociationCtrl "https://github.com/valentincasas/laterne_web/blob/main/controllers/asociation.controller.js"
  click AuthMw "https://github.com/valentincasas/laterne_web/blob/main/middlewares/authMiddleware.js"
  click JWTLib "https://github.com/valentincasas/laterne_web/blob/main/libs/jwt.js"
  click AssocModel "https://github.com/valentincasas/laterne_web/blob/main/models/associations.js"
  click UserModel "https://github.com/valentincasas/laterne_web/blob/main/models/user.model.js"
  click ProductModel "https://github.com/valentincasas/laterne_web/blob/main/models/product.model.js"
  click CategoryModel "https://github.com/valentincasas/laterne_web/blob/main/models/category.model.js"
  click ProdCatModel "https://github.com/valentincasas/laterne_web/blob/main/models/productCategory.model.js"
  click EventModel "https://github.com/valentincasas/laterne_web/blob/main/models/event.model.js"
  click TestimonialModel "https://github.com/valentincasas/laterne_web/blob/main/models/testimonial.model.js"
  click BusinessModel "https://github.com/valentincasas/laterne_web/blob/main/models/businessInfo.model.js"
  click OpeningModel "https://github.com/valentincasas/laterne_web/blob/main/models/openingHour.model.js"
  click Templates "https://github.com/valentincasas/laterne_web/blob/main/views/index.jade"
  click CSS "https://github.com/valentincasas/laterne_web/tree/main/public/stylesheets/"
  click JS "https://github.com/valentincasas/laterne_web/tree/main/public/javascripts/"
  click Fetch "https://github.com/valentincasas/laterne_web/tree/main/public/fetch/"
  click Images "https://github.com/valentincasas/laterne_web/tree/main/public/images/"

  classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6
  classDef backend fill:#E2F0D9,stroke:#238636,color:#238636
  classDef database fill:#FFEBCD,stroke:#d2691e,color:#d2691e
```
