# ccb16/peli_backend architecture

> Architecture diagram of the GitHub repository ccb16/peli_backend, 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/ccb16/peli_backend
- Repository: https://github.com/ccb16/peli_backend

## Overview

##### Project Components
- Server Layer: This is comprised of the main entry points (server.js and app.js) that initialize and run the Express application.
- Routing: The routes (found in routes/authRoutes.js) define endpoints for user authentication, mapping HTTP requests to controller actions.
- Controllers: The business logic is encapsulated in controllers (e.g., controllers/authController.js), which process requests, handle validation, and interact with the database.
- Database Access: The database connection module (db/connection.js) manages MySQL connectivity and defines how queries are executed.
- Environment/Configuration: The .env file holds configuration values (database connection details, JWT secret, etc.). This is critical for parameterizing the application.
- Testing: The __tests__ directory contains unit tests (e.g., auth.test.js) with Jest and supertest, which simulate API interactions ensuring proper behavior.

##### Relationships and Interactions
- Incoming HTTP requests hit the Express server where the defined routes (authRoutes.js) are invoked.
- Routes pass requests onto the appropriate controller methods (such as the authController.js) that encapsulate the authentication logic.
- Controllers interact with the database by using the connection module in db/connection.js to query or update the MySQL database.
- Responses are sent back to the client while JWT tokens are created and validated as part of the security process.
- Additionally, environment configuration (dotenv) is used at start-up to load .env variables, and tests run separately to validate the functionality.

##### Architectural Patterns & Design Principles
- Modular Design: The project separates concerns into distinct modules (controllers, routes, database access) which enhances maintainability.
- MVC-like Approach: Although simple and focused on authentication, the separation between routes (as a lightweight view or interface), controllers (logic), and database (model) follows the MVC mindset.
- Test Driven/Testing Integration: The inclusion of Jest and supertest suggests that tests are essential to validate the core features.
- Security Practices: Use of JWT and bcrypt highlights that secure practices are embedded in the system design.

##### Final Checklist
- Client ---> Server ---> Routes ---> Controllers ---> Database.
- Environment feeds configuration into Server and Database.
- Testing simulates client requests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client"):::client

    subgraph "Server Layer"
        s1("server.js"):::server
        s2("app.js"):::server
    end

    Routes("Routes (authRoutes.js)"):::routes
    Controller("Controller (authController.js)"):::controller
    Security("Security (JWT & bcrypt)"):::security
    Database("DB Connection (connection.js)"):::database
    Env("Env Configuration (.env)"):::config
    Testing("Testing (auth.test.js)"):::testing

    Client -->|"sends HTTP request"| s1
    s1 -->|"initializes Express"| s2
    s1 -->|"routes request"| Routes
    Routes -->|"calls"| Controller
    Controller -->|"queries/updates"| Database
    Controller -->|"handles auth"| Security
    Env -->|"configures"| s1
    Env -->|"configures"| Database
    Testing -->|"simulates API calls"| s1

    click s1 "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/server.js"
    click s2 "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/app.js"
    click Routes "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/routes/authRoutes.js"
    click Controller "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/controllers/authController.js"
    click Database "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/db/connection.js"
    click Env "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/.env"
    click Testing "https://github.com/ccb16/peli_backend/blob/main/Peli_Back/__tests__/auth.test.js"

    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef server fill:#ccf,stroke:#333,stroke-width:2px;
    classDef routes fill:#fc9,stroke:#333,stroke-width:2px;
    classDef controller fill:#cfc,stroke:#333,stroke-width:2px;
    classDef security fill:#fcc,stroke:#333,stroke-width:2px;
    classDef database fill:#9cf,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;
    classDef testing fill:#ffc,stroke:#333,stroke-width:2px;
```
