# vmesteban/react-de-cero-a-experto-hooks-y-mern- architecture

> Architecture diagram of the GitHub repository vmesteban/react-de-cero-a-experto-hooks-y-mern-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-
- Repository: https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-

## Overview

##### Project type and purpose
- This is a *monorepo* containing:
– A series of incremental React/JavaScript tutorials and Hooks demos (01-intro-react up through 19-journal-app).
– A full-stack Calendar application built with React on the client, Express/Node on the server, and MongoDB (MERN stack).
- The README title “React-De-cero-a-experto-Hooks-y-MERN” confirms that the end goal is a MERN-stack calendar app.

##### File structure
- Top-level folders 01- through 21- contain isolated front-end demo apps, each with its own index.html, src/, public/, vite.config.js or CRA config.
- Folders 22-calendar-mern (likely the client), and 23-/24-calendar-Backend-mern contain the MERN-stack:
– **Frontend** (22-calendar-mern): React components, hooks, styles, routing, build config (vite.config.js).
– **Backend** (23-calendar-Backend-mern & 24-calendar-Backend-mern): Node.js/Express app with controllers/, routes/, middlewares/, models/, database config, JWT helper.
– **Shared**: public/index.html served to client; .env for secrets; package.json scripts for starting server & client.

##### README
- The top-level README is minimal, but each sub-folder (especially 23- and 24-) contains its own README.md describing endpoints and setup.

##### Main components
a. **Client (Browser)** – the React single-page application (22-calendar-mern):
- UI components, routes, hooks for form handling and data fetching.
- Calls REST endpoints via fetch/Axios.
b. **Server (Node/Express API)** – (23-calendar-Backend-mern & 24-calendar-Backend-mern):
- Entry point index.js → configures Express, connects to MongoDB.
- Middlewares: request body parsing, CORS, JWT validation (validar-jwt.js), field validation (validar-campos.js).
- Controllers: auth.js (login, register), events.js (CRUD for calendar events).
- Routes: /api/auth, /api/events.
- Helpers: JWT token generation/verification, date validation.
- Models: Mongoose schemas for Usuario and Evento.
c. **Database (MongoDB)** – stores users and events; accessed via Mongoose.
d. **External Services** – none (all self-hosted).
e. **Static Hosting** – Express serves built React assets in production (public folder).

##### Relationships & data flows
1. User hits the React app in their browser.
2. React router displays login/register or calendar pages.
3. On login, React sends POST /api/auth to Express.
4. Express authenticates, returns a JWT.
5. React stores JWT (localStorage).
6. Subsequent requests to /api/events include Authorization header.
7. Express middleware validar-jwt verifies token, attaches user info.
8. Controller performs CRUD on Evento model in MongoDB.
9. Express returns JSON to React, which updates the UI.

##### Architectural patterns & technologies
- **Client**: SPA built with React + Vite, uses custom React hooks for form & fetch.
- **Server**: MVC-like layering (routes → controllers → models).
- **Auth**: JWT-based stateless authentication.
- **Data**: RESTful endpoints serving JSON.
- **Build**: Vite for front end, npm scripts for back end.

##### Essential elements checklist
- Annotations for key middleware (JWT, validation).
- Tech stack callouts (React/Vite, Node/Express, MongoDB/Mongoose).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Learning Modules
    subgraph "Learning Modules"
        LM["Demos 01-19"]
    end

    %% Client Layer
    subgraph "Client (React SPA)" 
        direction TB
        ClientHTML["index.html"]:::frontend
        ClientVite["vite.config.js"]:::frontend
        ClientPublic["public/"]:::frontend
        ClientSrc["src/"]:::frontend
    end

    %% Server Layer
    subgraph "Server (Express API)"
        direction TB
        Entry["index.js"]:::backend
        Env[".env"]:::backend
        Package["package.json"]:::backend

        subgraph "Middlewares"
            direction TB
            ValCampos["validar-campos.js"]:::middleware
            ValJWT["validar-jwt.js"]:::middleware
        end

        subgraph "Routes"
            direction TB
            AuthRoutes["auth.js"]:::backend
            EventsRoutes["events.js"]:::backend
        end

        subgraph "Controllers"
            direction TB
            AuthCtrl["auth.js"]:::controller
            EventsCtrl["events.js"]:::controller
        end

        subgraph "Models"
            direction TB
            UserModel["Usuario.js"]:::model
            EventModel["Evento.js"]:::model
        end

        subgraph "Helpers"
            direction TB
            JWTHelper["jwt.js"]:::helper
            DateHelper["isDate.js"]:::helper
        end

        subgraph "Static Hosting"
            direction TB
            ServerPublicHTML["public/index.html"]:::backend
            ServerStyles["public/styles.css"]:::backend
        end
    end

    %% Database
    DB["MongoDB (Mongoose)"]:::db

    %% Connections
    LM -->|includes monorepo| ClientHTML
    ClientHTML -->|"serves SPA"| ClientSrc
    ClientSrc -->|"build via Vite"| ClientPublic
    ClientPublic -->|"static assets"| ClientHTML
    ClientSrc -->|"fetch POST /api/auth"| Entry
    ClientSrc -->|"fetch CRUD /api/events"| Entry

    Entry -->|"uses env"| Env
    Entry -->|"loads middlewares"| ValCampos
    Entry -->|"loads middlewares"| ValJWT
    Entry -->|"registers routes"| AuthRoutes
    Entry -->|"registers routes"| EventsRoutes

    AuthRoutes -->|"calls"| AuthCtrl
    EventsRoutes -->|"calls"| EventsCtrl

    AuthCtrl -->|"accesses"| UserModel
    EventsCtrl -->|"accesses"| EventModel

    Entry -->|"connects via config"| DB
    JWTHelper -->|"used in"| ValJWT
    DateHelper -->|"used in"| EventsCtrl

    ServerPublicHTML -->|"served by Express"| ClientHTML

    %% Click Events
    click ClientHTML "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/22-calendar-mern/index.html"
    click ClientVite "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/22-calendar-mern/vite.config.js"
    click ClientPublic "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/tree/main/22-calendar-mern/public/"
    click ClientSrc "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/tree/main/22-calendar-mern/src/"
    click Entry "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/index.js"
    click Env "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/.env"
    click Package "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/package.json"
    click DB "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/database/config.js"
    click AuthCtrl "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/controllers/auth.js"
    click EventsCtrl "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/controllers/events.js"
    click AuthRoutes "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/routes/auth.js"
    click EventsRoutes "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/routes/events.js"
    click ValJWT "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/middlewares/validar-jwt.js"
    click ValCampos "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/middlewares/validar-campos.js"
    click UserModel "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/models/Usuario.js"
    click EventModel "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/models/Evento.js"
    click JWTHelper "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/helpers/jwt.js"
    click DateHelper "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/helpers/isDate.js"
    click ServerPublicHTML "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/public/index.html"
    click ServerStyles "https://github.com/vmesteban/react-de-cero-a-experto-hooks-y-mern-/blob/main/24-calendar-Backend-mern/public/styles.css"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef backend fill:#D0FFD6,stroke:#333,stroke-width:1px
    classDef db fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef middleware fill:#C8FDCA,stroke:#333,stroke-width:1px
    classDef controller fill:#A8E6CF,stroke:#333,stroke-width:1px
    classDef model fill:#FFD3B6,stroke:#333,stroke-width:1px
    classDef helper fill:#E0FFFF,stroke:#333,stroke-width:1px
```
