# edgardortega/proyecto_ejtech architecture

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

- Interactive diagram: https://gitdiagram.com/edgardortega/proyecto_ejtech
- Repository: https://github.com/edgardortega/proyecto_ejtech

## Overview

##### Project Type & Purpose
- This is a full-stack web application (a Marketplace named EJtech) that allows users (Clientes and Administradores) to browse, purchase, and manage technology products.
- The README details separate flows for user authentication, product browsing, shopping cart operations, and administrative tasks like managing products and users.

##### Main Components
a. Frontend Client:
- Built with ReactJS (using React Router for navigation).
- Responsible for rendering views (Home, Galeria, Carrito, Login, Register, Profile, etc.) and interacting with the backend via HTTP calls (Axios).
- Organized into components, view pages, and context providers (AuthContext, CartContext, HistoryContext).
- Uses Vite for development and React-Bootstrap/Bootstrap for UI styling.
b. Backend Server:
- Built on Node.js with Express.js.
- Entry point: index.js which sets up the server and integrates middleware (authentication with authMiddleware, logger, etc.).
- Defines multiple route modules (authRoutes, productRoutes, userRoutes, orderRoutes, etc.) to handle RESTful API endpoints.
- Uses JWT for authentication and bcrypt for password encryption.
- Has an SQL script (script.sql) for PostgreSQL database setup.
- Contains test directories for API testing (using jest & supertest).
c. Database:
- PostgreSQL is used as the database.
- The provided SQL script sets up tables (usuario, rol, categoria, producto, carrito, orden, detalle_orden) capturing the application’s relational model.
d. External/Supporting Elements:
- Environment configuration files (the .env files for both backend and frontend).
- Deployment details (Render deploy link, PGAdmin for managing the database).
- Tools like nodemon for hot reloading and ESLint for code quality.

##### Relationships & Interactions
- The Frontend communicates with the Backend via HTTP/REST API calls (managed by Axios).
- The Backend handles these requests by interfacing with the PostgreSQL database to perform CRUD operations.
- Authentication is managed at the backend with JWT tokens which are provided to the frontend during login.
- Middleware processes (logging, authentication) ensure data integrity and security across requests.
- There are clear role-based flows: Admins can access additional endpoints to manage products and users while clients have different route accesses.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Clear division between presentation (React frontend) and logic (Express backend).
- Layered Architecture: The backend segregates routing, middleware, and database access.
- RESTful API design: Distinct routes for each resource (users, products, orders) promoting modularity.
- Use of context providers in React promotes state management (for user authentication, cart data, and history).

##### Final Assembly
1. Client Layer: Frontend (React, context, components).
2. Application Layer: Backend (Express server, middleware, RESTful endpoints).
3. Data Layer: PostgreSQL (table schema as shown in the SQL script).
- Use annotations around “Role-based Access Control” to denote routes/views available for Administrators and Clients.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Client Layer (Frontend)"
        FE["Frontend (React/Vite)"]:::frontend
        FE_View["View Pages"]:::views
        FE_Context["State Management (Context Providers)"]:::context
        FE_Route["Routing & Components"]:::components
    end

    %% Backend Layer
    subgraph "Application Layer (Backend)"
        BE["Backend API Server (Node.js/Express)"]:::backend
        BE_Index["Server Setup (index.js)"]:::backendEntry
        BE_Routes["API Routes"]:::backendRoutes
        BE_Middleware["Middlewares (auth & logger)"]:::middleware
        BE_Test["API Testing"]:::testing
    end

    %% Database Layer
    subgraph "Data Layer"
        DB["PostgreSQL Database"]:::database
        DB_Script["Database Setup Script (script.sql)"]:::databaseScript
        DB_Tables["Tables: usuario, rol, categoria, producto, carrito, orden, detalle_orden"]:::tables
    end

    %% Relationships and Data Flow
    FE -->|"APICalls"| BE
    BE -->|"DBQueries"| DB

    %% Additional relationships
    FE_View --> FE
    FE_Context --> FE
    FE_Route --> FE

    BE_Index --> BE
    BE_Routes --> BE
    BE_Middleware --> BE
    BE_Test --> BE

    DB_Script --> DB
    DB_Tables --> DB

    %% Click Events
    click FE "https://github.com/edgardortega/proyecto_ejtech/tree/main/frontend/src"
    click FE_View "https://github.com/edgardortega/proyecto_ejtech/tree/main/frontend/src/view"
    click FE_Context "https://github.com/edgardortega/proyecto_ejtech/tree/main/frontend/src/context"
    click FE_Route "https://github.com/edgardortega/proyecto_ejtech/tree/main/frontend/src/components"
    click BE_Index "https://github.com/edgardortega/proyecto_ejtech/blob/main/backend/index.js"
    click BE_Routes "https://github.com/edgardortega/proyecto_ejtech/tree/main/backend/routes"
    click BE_Middleware "https://github.com/edgardortega/proyecto_ejtech/tree/main/backend/middlewares"
    click DB_Script "https://github.com/edgardortega/proyecto_ejtech/blob/main/backend/script.sql"
    click BE_Test "https://github.com/edgardortega/proyecto_ejtech/tree/main/backend/test"

    %% Class Definitions for Coloring
    classDef frontend fill:#A8E6CF,stroke:#05668D,stroke-width:2px;
    classDef views fill:#F3D250,stroke:#F1C40F,stroke-width:2px;
    classDef context fill:#B5EAD7,stroke:#27AE60,stroke-width:2px;
    classDef components fill:#C9BBCF,stroke:#7F8C8D,stroke-width:2px;
    classDef backend fill:#FFD3B6,stroke:#FF6F69,stroke-width:2px;
    classDef backendEntry fill:#FF6F69,stroke:#F15B2A,stroke-width:2px;
    classDef backendRoutes fill:#FFD3B6,stroke:#FB6D3A,stroke-width:2px;
    classDef middleware fill:#E1B07E,stroke:#FF9F1C,stroke-width:2px;
    classDef testing fill:#FFDB58,stroke:#E37702,stroke-width:2px;
    classDef database fill:#FFAAA7,stroke:#D7263D,stroke-width:2px;
    classDef databaseScript fill:#FF8C94,stroke:#C72C41,stroke-width:2px;
    classDef tables fill:#F28482,stroke:#FF8C94,stroke-width:2px;
```
