# ceurrutia/login-register-auth architecture

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

- Interactive diagram: https://gitdiagram.com/ceurrutia/login-register-auth
- Repository: https://github.com/ceurrutia/login-register-auth

## Overview

##### Project type and purpose
- This is a full-stack web application providing user authentication (login/register) and museum management.
- The frontend is a React single-page application; the backend is a Node.js/Express REST API using Bcrypt for password hashing, JWT for stateless auth, and MongoDB (via Mongoose) for persistence.

##### File structure
- Top-level:
- client/ – the React front-end
- src/ – the Node/Express back-end
- client/ contains:
- src/components, src/pages – UI components and views (Home, Admin, Login, Register, Profile, CreateMuseum)
- src/api – axios instance and auth API wrappers
- src/context/AuthContext.jsx – client-side auth state and JWT management
- src/ contains (backend):
- index.js/app.js – Express app entrypoint, middleware registration
- routes/ – REST routes (auth.routes.js, museum.routes.js)
- controllers/ – request handlers implementing business logic
- models/ – Mongoose schemas (user.model.js, museum.model.js)
- middlewares/ – token validation & request payload validation
- libs/jwt.js – JWT creation/verification utilities
- db.js/config.js – database connection and environment config
- schemas/ – validation schemas for incoming payloads

##### README
- Confirms core technologies: Node.js, Express, Bcrypt, JWT.
- Project focus: login/register authentication flow plus protected museum-related CRUD functionality.

##### Detail and clarity
- Both happy-path (valid token, CRUD operations) and error-paths (invalid token, validation errors).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)"
        direction TB
        ClientApp["Client Application"]:::frontend
        MainEntry["main.jsx"]:::frontend
        AppComp["App.jsx"]:::frontend
        ProtectedRoute["ProtectedRoute.jsx"]:::frontend
        subgraph "Pages" 
            direction TB
            HomePage["HomePage.jsx"]:::frontend
            AdminPage["Admin.jsx"]:::frontend
            LoginPage["LoginPage.jsx"]:::frontend
            RegisterPage["RegisterPage.jsx"]:::frontend
            ProfilePage["ProfilePage.jsx"]:::frontend
            CreateMuseumPage["CreateMuseum.jsx"]:::frontend
        end
        subgraph "Components"
            direction TB
            MuseumList["Museum_list.jsx"]:::frontend
            Navigation["Navigation.jsx"]:::frontend
        end
        subgraph "API & Context"
            direction TB
            AxiosConfig["axios.js"]:::external
            AuthAPI["auth.js"]:::external
            AuthContext["AuthContext.jsx"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend (Express API)"
        direction TB
        EntryPoint["index.js"]:::backend
        AppConfig["app.js"]:::backend
        subgraph "Config & DB"
            direction TB
            EnvConfig["config.js"]:::backend
            DBConn["db.js"]:::backend
        end
        subgraph "Routes"
            direction TB
            AuthRoutes["auth.routes.js"]:::backend
            MuseumRoutes["museum.routes.js"]:::backend
        end
        subgraph "Middlewares"
            direction TB
            JWTMiddleware["validateToken.js"]:::backend
            ValidationMiddleware["validator.middleware.js"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthController["auth.controller.js"]:::backend
            MuseumController["museum.controller.js"]:::backend
        end
        subgraph "Models"
            direction TB
            UserModel["user.model.js"]:::backend
            MuseumModel["museum.model.js"]:::backend
        end
        subgraph "Libs & Schemas"
            direction TB
            JWTLib["jwt.js"]:::external
            subgraph "Schemas"
                direction TB
                AuthSchemas["auth.schema.js"]:::backend
                MuseumSchemas["museum.schema.js"]:::backend
            end
        end
    end

    %% Database
    MongoDB[(MongoDB)]:::database

    %% Data Flows
    ClientApp -->|"renders via"| MainEntry
    MainEntry --> AppComp
    AppComp --> ProtectedRoute
    AppComp --> Navigation
    AppComp --> MuseumList
    AppComp --> HomePage
    AppComp --> AdminPage
    AppComp --> LoginPage
    AppComp --> RegisterPage
    AppComp --> ProfilePage
    AppComp --> CreateMuseumPage
    AppComp --> AuthContext
    AuthContext -->|provides JWT| AppComp
    AppComp -->|calls| AxiosConfig
    AxiosConfig -->|HTTP request| AuthAPI
    AuthAPI -->|POST /auth| EntryPoint
    AuthAPI -->|GET/POST /museums| EntryPoint

    EntryPoint --> AppConfig
    AppConfig --> EnvConfig
    AppConfig --> DBConn
    AppConfig --> AuthRoutes
    AppConfig --> MuseumRoutes

    AuthRoutes -->|use| JWTMiddleware
    MuseumRoutes -->|use| JWTMiddleware
    AuthRoutes --> ValidationMiddleware
    MuseumRoutes --> ValidationMiddleware

    AuthRoutes --> AuthController
    MuseumRoutes --> MuseumController

    AuthController --> JWTLib
    AuthController --> UserModel
    AuthController --> MuseumModel
    MuseumController --> MuseumModel
    MuseumController --> UserModel

    UserModel -->|CRUD| MongoDB
    MuseumModel -->|CRUD| MongoDB

    %% Response flows
    MongoDB --> UserModel
    MongoDB --> MuseumModel
    AuthController -->|response| AxiosConfig
    MuseumController -->|response| AxiosConfig

    %% Click Events - Frontend
    click ClientApp "https://github.com/ceurrutia/login-register-auth/tree/main/client/src"
    click MainEntry "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/main.jsx"
    click AppComp "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/App.jsx"
    click ProtectedRoute "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/ProtectedRoute.jsx"
    click MuseumList "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/components/Museum_list.jsx"
    click Navigation "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/components/Navigation.jsx"
    click HomePage "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/pages/HomePage.jsx"
    click AdminPage "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/pages/Admin.jsx"
    click LoginPage "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/pages/LoginPage.jsx"
    click RegisterPage "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/pages/RegisterPage.jsx"
    click ProfilePage "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/pages/ProfilePage.jsx"
    click CreateMuseumPage "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/pages/CreateMuseum.jsx"
    click AxiosConfig "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/api/axios.js"
    click AuthAPI "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/api/auth.js"
    click AuthContext "https://github.com/ceurrutia/login-register-auth/blob/main/client/src/context/AuthContext.jsx"

    %% Click Events - Backend
    click EntryPoint "https://github.com/ceurrutia/login-register-auth/blob/main/src/index.js"
    click AppConfig "https://github.com/ceurrutia/login-register-auth/blob/main/src/app.js"
    click EnvConfig "https://github.com/ceurrutia/login-register-auth/blob/main/src/config.js"
    click DBConn "https://github.com/ceurrutia/login-register-auth/blob/main/src/db.js"
    click AuthRoutes "https://github.com/ceurrutia/login-register-auth/blob/main/src/routes/auth.routes.js"
    click MuseumRoutes "https://github.com/ceurrutia/login-register-auth/blob/main/src/routes/museum.routes.js"
    click AuthController "https://github.com/ceurrutia/login-register-auth/blob/main/src/controllers/auth.controller.js"
    click MuseumController "https://github.com/ceurrutia/login-register-auth/blob/main/src/controllers/museum.controller.js"
    click UserModel "https://github.com/ceurrutia/login-register-auth/blob/main/src/models/user.model.js"
    click MuseumModel "https://github.com/ceurrutia/login-register-auth/blob/main/src/models/museum.model.js"
    click JWTMiddleware "https://github.com/ceurrutia/login-register-auth/blob/main/src/middlewares/validateToken.js"
    click ValidationMiddleware "https://github.com/ceurrutia/login-register-auth/blob/main/src/middlewares/validator.middleware.js"
    click JWTLib "https://github.com/ceurrutia/login-register-auth/blob/main/src/libs/jwt.js"
    click AuthSchemas "https://github.com/ceurrutia/login-register-auth/blob/main/src/schemas/auth.schema.js"
    click MuseumSchemas "https://github.com/ceurrutia/login-register-auth/blob/main/src/schemas/museum.schema.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef external fill:#ffeeba,stroke:#856404,color:#856404
    classDef database fill:#f5c6cb,stroke:#721c24,color:#721c24,stroke-dasharray: 5 5
```
