# santibalbiani/dh_grupo_02_slc architecture

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

- Interactive diagram: https://gitdiagram.com/santibalbiani/dh_grupo_02_slc
- Repository: https://github.com/santibalbiani/dh_grupo_02_slc

## Overview

1. **Repository shape**
   - This repo is centered on a **two-part application**:
     - an **Express-based store backend + server-rendered storefront** under `app/`
     - a separate **React dashboard/admin UI** under `app/dashboard/`
   - The rest of the repository is mostly project documentation: DB scripts, wireframes, design diagrams, and sprint retrospectives.

2. **Primary business domain**
   - The application is an **e-commerce site for electronic components / IoT solutions**.
   - The core user journeys are: browsing product categories, searching products, viewing product details, registering/logging in, managing a cart, and completing purchases.
   - There is also an administrative side for managing users, products, and sales metrics.

3. **Server entrypoint and web layer**
   - The main server app lives in `app/app.js` with the startup script in `app/bin/www`.
   - This is a classic **Express + EJS** structure: the server renders pages, serves static assets, and exposes JSON endpoints.
   - Page routes are separated from API routes, which keeps the storefront and machine-readable endpoints distinct.

4. **Route/controller split**
   - Domain routing is organized by feature:
     - `routes/products.js`, `routes/users.js`, `routes/transactions.js`
     - API routes in `routes/apiProducts.js`, `routes/apiUsers.js`, `routes/apiSells.js`
   - Controllers mirror those domains:
     - `productsController.js`, `userController.js`, `transactionController.js`
     - `searchBarController.js` for search behavior
     - `apiProdsByCategory.js`, `apiUserController.js`, `apiSellsController.js` for JSON responses
     - `mainController.js` for shared/homepage behavior
   - This indicates a **feature-oriented backend**, not a layered generic MVC split.

5. **Persistence layer**
   - Data access is handled through **Sequelize ORM** under `app/database/`.
   - The repo includes:
     - `config/config.js` for DB connection settings
     - `migrations/` for schema evolution
     - `models/` for relational entities
   - The model set suggests a commerce schema with:
     - `product`, `category`
     - `masteruser` / user-related models
     - cart and transaction entities: `aCart`, `acartitem`, `aTrx`, `atrxItem`
   - This points to a relational core with products, users, carts, and purchases as the main data flow.

6. **Request processing and shared middleware**
   - Cross-cutting request behavior is centralized in `middlewares/`:
     - user/session cookies
     - locals injection for templates
     - flash/messages handling
     - access control for buying and editing users
   - These middleware files act as the boundary between identity/session state and the page/API handlers.

7. **Storefront presentation layer**
   - Server-rendered views live in `app/views/` using **EJS templates**.
   - Reusable fragments are in `app/partials/` for layout elements like header, footer, nav, search bar, and error handling.
   - Static frontend assets are in `app/public/`:
     - CSS for product detail, cart, registration, and general layout
     - client-side JS for validation, cart loading, local storage, and multi-step flows
     - images for products and users
   - This frontend is tightly coupled to the Express controllers and is the primary UX for shoppers.

8. **User and commerce flows**
   - The structure shows distinct flows for:
     - browsing/searching products
     - product detail and add-to-cart
     - checkout/transaction completion
     - user registration, profile, and admin editing
   - The presence of `buyNotLogged` middleware and cart/transaction models suggests the checkout flow enforces authentication or special purchase rules.

9. **API surface**
   - The `api/*` routes expose backend data in JSON form, likely for:
     - dashboard charts and indicators
     - category/product listings
     - user/sales metrics
   - This separates internal data consumption from the HTML-rendering storefront and makes the backend usable by the dashboard SPA.

10. **React dashboard subsystem**
   - `app/dashboard/` is a standalone React app with its own `package.json`.
   - It contains chart components such as:
     - `BarGraph`, `LineGraph`, `Indicators`
     - UI navigation components like `NavBar`
   - `src/config/API.js` and `datesHandler.js` indicate the dashboard pulls remote data and formats it for reporting.
   - This is the repository’s **admin/analytics boundary**, consuming backend APIs rather than rendering server-side pages.

11. **Data and seed artifacts**
   - `app/data/products.json` and `app/data/users.json` appear to be seed/mock datasets or import sources.
   - The `Scripts/` folder contains DB creation and population documentation, reinforcing that database setup is part of the project workflow.
   - These assets are support material for bootstrapping and demonstrating the schema, not runtime dependencies.

12. **Project artifacts and legacy history**
   - `DER/`, `Wireframes/`, `old/`, and `retrospectivas/` contain design diagrams, earlier HTML/EJS versions, and sprint retrospectives.
   - These do not affect runtime architecture, but they help explain the evolution of the app and the intended UX.

13. **High-level system boundary**
   - The repo overall represents a **monolith with one backend and one separate frontend dashboard**:
     - Express/EJS storefront + JSON API + relational persistence
     - React dashboard consuming those APIs
   - The key architectural boundary is between **server-rendered commerce pages** and **API-driven analytics/admin UI**.

14. **What to draw in an architecture diagram**
   - A good diagram should show:
     - Browser shoppers talking to the Express app for HTML pages and cart/checkout actions
     - The Express app talking to Sequelize-backed relational tables
     - The React dashboard talking to the same backend via JSON APIs
     - Shared middleware sitting in front of controllers
     - Static assets and EJS partials as part of the storefront presentation layer

Main entry points: [`app/controllers/mainController.js`](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/controllers/mainController.js) (Controllers), [`app/database/models/index.js`](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/models/index.js) (Models), [`app/app.js`](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/app.js) (Express app), [`app/dashboard/src/App.js`](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/App.js) (Dashboard app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Storefront app"]
  node_appjs["Express app<br/>server entrypoint<br/>[app.js]"]
  node_www["WWW boot<br/>startup script"]
  node_webroutes["Web routes<br/>page routing<br/>[index.js]"]
  node_controllers["Controllers<br/>feature handlers<br/>[mainController.js]"]
  node_middlewares["Middleware<br/>request pipeline"]
  node_views["EJS views<br/>presentation<br/>[index.ejs]"]
  node_partials["Partials<br/>template fragments<br/>[nav.ejs]"]
  node_assets["Static assets<br/>frontend assets<br/>[style.css]"]
end

subgraph group_api["Backend API"]
  node_apiroutes["API routes<br/>json routing<br/>[apiProducts.js]"]
  node_apicontrollers["API controllers<br/>json handlers"]
end

subgraph group_data["Persistence"]
  node_dbconfig["DB config<br/>sequelize config<br/>[config.js]"]
  node_migrations["Migrations<br/>schema evolution"]
  node_models[("Models<br/>[index.js]")]
  node_seeddata["Seed data<br/>sample data<br/>[products.json]"]
end

subgraph group_dashboard["Admin dashboard"]
  node_dashboardapp["Dashboard app<br/>react spa<br/>[App.js]"]
  node_dashboardui["Dashboard UI<br/>components<br/>[BarGraph.js]"]
  node_dashboardcfg["Dashboard config<br/>client config<br/>[API.js]"]
end

node_www -->|"starts"| node_appjs
node_appjs -->|"uses"| node_middlewares
node_appjs -->|"mounts"| node_webroutes
node_appjs -->|"mounts"| node_apiroutes
node_webroutes -->|"delegates"| node_controllers
node_apiroutes -->|"delegates"| node_apicontrollers
node_controllers -->|"renders"| node_views
node_controllers -->|"composes"| node_partials
node_controllers -->|"serves"| node_assets
node_controllers -->|"reads/writes"| node_models
node_apicontrollers -->|"reads/writes"| node_models
node_dbconfig -->|"configures"| node_models
node_migrations -->|"shapes"| node_models
node_seeddata -.->|"seeds"| node_models
node_dashboardapp -->|"uses"| node_dashboardui
node_dashboardapp -->|"fetches"| node_dashboardcfg
node_dashboardapp -->|"consumes"| node_apiroutes
node_middlewares -->|"guards"| node_controllers

click node_appjs "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/app.js"
click node_www "https://github.com/santibalbiani/dh_grupo_02_slc/tree/master/app/bin/www"
click node_webroutes "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/routes/index.js"
click node_controllers "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/controllers/mainController.js"
click node_middlewares "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/middlewares/localsMiddleware.js"
click node_views "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/views/index.ejs"
click node_partials "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/partials/nav.ejs"
click node_assets "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/public/stylesheets/style.css"
click node_apiroutes "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/routes/apiProducts.js"
click node_apicontrollers "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/controllers/apiUserController.js"
click node_dashboardapp "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/App.js"
click node_dashboardui "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/components/BarGraph.js"
click node_dashboardcfg "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/config/API.js"
click node_dbconfig "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/config/config.js"
click node_migrations "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/migrations/20200210160609-create-user.js"
click node_models "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/models/index.js"
click node_seeddata "https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/data/products.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_appjs,node_www,node_webroutes,node_controllers,node_middlewares,node_views,node_partials,node_assets toneBlue
class node_apiroutes,node_apicontrollers toneAmber
class node_dbconfig,node_migrations,node_models,node_seeddata toneMint
class node_dashboardapp,node_dashboardui,node_dashboardcfg toneRose
```

## Components

### Storefront app

Express/EJS commerce experience for shoppers

- [Express app](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/app.js): server entrypoint · Bootstraps the storefront server and mounts web/API routes · `app/app.js`
- [WWW boot](https://github.com/santibalbiani/dh_grupo_02_slc/tree/master/app/bin/www): startup script · Starts the HTTP server and wires the Express app · `app/bin/www`
- [Web routes](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/routes/index.js): page routing · Feature routes for storefront pages and commerce actions · `app/routes/index.js`
- [Controllers](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/controllers/mainController.js): feature handlers · Page and domain controllers for products, users, search, and transactions · `app/controllers/mainController.js`
- [Middleware](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/middlewares/localsMiddleware.js): request pipeline · Session, locals, flash, and access-control middleware · `app/middlewares/localsMiddleware.js`
- [EJS views](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/views/index.ejs): presentation · Server-rendered storefront screens and forms · `app/views/index.ejs`
- [Partials](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/partials/nav.ejs): template fragments · Reusable layout fragments for head, nav, footer, search, and errors · `app/partials/nav.ejs`
- [Static assets](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/public/stylesheets/style.css): frontend assets · CSS and client-side JavaScript for storefront interactions · `app/public/stylesheets/style.css`

### Backend API

JSON surface used by the dashboard and internal clients

- [API routes](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/routes/apiProducts.js): json routing · JSON endpoints for products, users, and sales · `app/routes/apiProducts.js`
- [API controllers](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/controllers/apiUserController.js): json handlers · Controllers that shape data for API responses · `app/controllers/apiUserController.js`

### Persistence

Sequelize models and database schema

- [DB config](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/config/config.js): sequelize config · Connection settings for the relational database · `app/database/config/config.js`
- [Migrations](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/migrations/20200210160609-create-user.js): schema evolution · Database schema definition and versioned changes · `app/database/migrations/20200210160609-create-user.js`
- [Models](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/database/models/index.js): sequelize models · Relational entities for products, categories, users, carts, and transactions · `app/database/models/index.js`
- [Seed data](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/data/products.json): sample data · JSON datasets used for bootstrap or reference content · `app/data/products.json`

### Admin dashboard

React reporting UI for metrics and management

- [Dashboard app](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/App.js): react spa · Standalone React admin and analytics UI · `app/dashboard/src/App.js`
- [Dashboard UI](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/components/BarGraph.js): components · Graphs, indicators, and navigation for admin reporting · `app/dashboard/src/components/BarGraph.js`
- [Dashboard config](https://github.com/santibalbiani/dh_grupo_02_slc/blob/master/app/dashboard/src/config/API.js): client config · API configuration and date formatting for dashboard data · `app/dashboard/src/config/API.js`

## Connections

- WWW boot → Express app: starts · HTTP bootstrap loads the Express application
- Express app → Middleware: uses · Requests pass through shared middleware first
- Express app → Web routes: mounts · Express mounts storefront page routes
- Express app → API routes: mounts · Express mounts JSON API routes
- Web routes → Controllers: delegates · Feature routes hand off to page/domain controllers
- API routes → API controllers: delegates · API routes hand off to JSON controllers
- Controllers → EJS views: renders · Controllers return EJS pages for shoppers
- Controllers → Partials: composes · Views reuse shared template fragments
- Controllers → Static assets: serves · Controllers and views rely on static CSS and client scripts
- Controllers → Models: reads/writes · Commerce flows persist and query relational data
- API controllers → Models: reads/writes · API responses are built from Sequelize models
- DB config → Models: configures · Database connection settings are consumed by the ORM layer
- Migrations → Models: shapes · Schema migrations define the tables the models map to
- Seed data → Models: seeds · Sample product and user data support the commerce domain
- Dashboard app → Dashboard UI: uses · React app composes charts and navigation components
- Dashboard app → Dashboard config: fetches · Dashboard config points to backend API endpoints
- Dashboard app → API routes: consumes · Analytics UI consumes the backend JSON surface
- Middleware → Controllers: guards · Session and access control wrap page and commerce handlers
