# willvillegas/proyecto-web architecture

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

- Interactive diagram: https://gitdiagram.com/willvillegas/proyecto-web
- Repository: https://github.com/willvillegas/proyecto-web

## Overview

##### Main Components Identification
a. Frontend (Angular):
- Angular application representing the user interface.
- Multiple feature areas such as movie pages, actor pages, login/signup components, and custom components (e.g., cards, filter components).
- Use of Angular Router for navigation and interceptors (JWT and auth error handling).
- Angular’s organization: core modules, shared components, and services that interact with the backend API.

b. Backend (Node.js/Express):
- Controllers (handling HTTP requests for movies, actors, and users).
- Services (business logic, e.g., movie.service, actor.service, user.service).
- Repositories (data access logic for models).
- Middlewares (auth, authorization, file upload handling with multer).
- Models and Interfaces (defining schema contracts for movies, actors, and users).
- Utilities (for authentication such as JWT, bcrypt, and database connections).
- That the backend is structured in two parts: a "src" folder (source code) and a "dist" folder for compiled JavaScript files.

c. Database (MongoDB):
- That the database stores documents for movies, actors, and users, with relationships (e.g., movies having casts of actors).

d. File Storage:
- “uploads” directory in the backend that stores images for movies and actors.

##### Relationships and Data Flow Between Components
- Backend middleware intercepting requests (authentication and authorization) before reaching controllers.
- Communication from the backend to the database (MongoDB) where schemas for movies, actors, and users are being managed.
- Optionally, show how the backend may serve static files (uploaded images) and API documentation endpoints (via Postman collection files available in the repository).

##### Important Architectural Patterns & Design Principles
- MVC-like pattern on the backend: separating controllers, services, repositories, and models.
- Clear separation of concerns in the frontend by organizing components (pages, dialogs, etc.) as Angular modules.
- Use of middleware in backend design for handling cross-cutting concerns like authentication and file uploads.
- RESTful API design for backend endpoints.
- Layered architecture that distinguishes between business logic (services), data access (repositories), and presentation logic (controllers).

##### Technologies, Frameworks, and Libraries
- Frontend: Angular, Angular Router, Tailwind CSS, and TypeScript.
- Backend: Node.js, Express, TypeScript, JWT for authentication, Bcrypt for password hashing, and Multer for file uploads.
- Database: MongoDB.
- Additional configuration tools and linters (e.g., ESLint for the backend).

##### Practical Steps
- Within the Backend block, create nested sub-components to indicate controllers, services, repositories, and middlewares.
- Within the Frontend block, detail significant Angular modules or feature areas (movies, actors, authentication).
- That the “uploads” folder and static file handling are represented as part of the backend’s responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A1["Angular Frontend"]:::frontend
        subgraph "Angular Modules"
            A2["Movies Module"]:::frontend
            A3["User Pages (Auth&Management)"]:::frontend
        end
        A4["Angular Interceptors"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1["Express API Server"]:::backend
        subgraph "Controllers"
            B2["Movie Controller"]:::backend
            B3["Actor Controller"]:::backend
            B4["User Controller"]:::backend
        end
        subgraph "Services"
            B5["Movie Service"]:::backend
            B6["Actor Service"]:::backend
            B7["User Service"]:::backend
        end
        subgraph "Repositories"
            B8["Movie Repository"]:::backend
            B9["Actor Repository"]:::backend
            B10["User Repository"]:::backend
        end
        subgraph "Models & Interfaces"
            B11["Models"]:::backend
            B12["Interfaces"]:::backend
        end
        subgraph "Middlewares"
            B13["Auth Middleware"]:::backend
            B14["Authorization Middleware"]:::backend
            B15["Multer Middleware"]:::backend
        end
        subgraph "Utilities"
            B16["JWT Utility"]:::backend
            B17["Bcrypt Utility"]:::backend
            B18["DB Connection Utility"]:::backend
        end
        subgraph "Uploads"
            B19["Actors Images"]:::backend
            B20["Movies Images"]:::backend
        end
        B21["Compiled Code"]:::backend
    end

    %% Database Layer
    subgraph "MongoDB Database"
        D1["MongoDB Collection"]:::database
    end

    %% Data Flow Connections
    A1 -->|"RESTful_API_calls"| B1
    B1 -->|"Routes_to"| B2
    B1 -->|"Routes_to"| B3
    B1 -->|"Routes_to"| B4

    B2 --> B5
    B3 --> B6
    B4 --> B7

    B5 --> B8
    B6 --> B9
    B7 --> B10

    %% Middleware Usage
    B1 -->|"uses"| B13
    B1 -->|"uses"| B14
    B1 -->|"uses"| B15

    %% Utilities
    B1 -->|"calls"| B16
    B1 --> B17
    B1 --> B18

    %% Repositories connected to Models & Interfaces
    B8 --> B11
    B9 --> B11
    B10 --> B11
    B8 --> B12
    B9 --> B12
    B10 --> B12

    %% Backend -> Database Communication
    B1 -->|"CRUD_operations"| D1

    %% Static File Handling
    B1 -->|"serves_static_files"| B19
    B1 -->|"serves_static_files"| B20

    %% Frontend internal structure
    A1 --> A2
    A1 --> A3

    %% Click Events for Frontend
    click A1 "https://github.com/willvillegas/proyecto-web/tree/main/frontend/src/app"
    click A2 "https://github.com/willvillegas/proyecto-web/tree/main/frontend/src/app/movies"
    click A3 "https://github.com/willvillegas/proyecto-web/tree/main/frontend/src/app/pages"
    click A4 "https://github.com/willvillegas/proyecto-web/tree/main/frontend/src/app/movies/interceptors"

    %% Click Events for Backend
    click B1 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/index.ts"
    click B2 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/controllers/movie.controller.ts"
    click B3 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/controllers/actor.controller.ts"
    click B4 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/controllers/user.controller.ts"
    click B5 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/services/movie.service.ts"
    click B6 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/services/actor.service.ts"
    click B7 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/services/user.service.ts"
    click B8 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/repositories/movie.repository.ts"
    click B9 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/repositories/actor.repository.ts"
    click B10 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/repositories/user.repository.ts"
    click B11 "https://github.com/willvillegas/proyecto-web/tree/main/backend/src/models"
    click B12 "https://github.com/willvillegas/proyecto-web/tree/main/backend/src/interfaces"
    click B13 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/middlewares/auth.middleware.ts"
    click B14 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/middlewares/authorize.middleware.ts"
    click B15 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/middlewares/multer.middleware.ts"
    click B16 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/utils/JWT.ts"
    click B17 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/utils/bcrypt.ts"
    click B18 "https://github.com/willvillegas/proyecto-web/blob/main/backend/src/utils/connectBD.ts"
    click B19 "https://github.com/willvillegas/proyecto-web/tree/main/backend/uploads/actors"
    click B20 "https://github.com/willvillegas/proyecto-web/tree/main/backend/uploads/movies"
    click B21 "https://github.com/willvillegas/proyecto-web/tree/main/backend/dist"

    %% Class Styles
    classDef frontend fill:#fefbd8,stroke:#f1c40f,stroke-width:2px;
    classDef backend fill:#d1f7c4,stroke:#27ae60,stroke-width:2px;
    classDef database fill:#ffe6e6,stroke:#e74c3c,stroke-width:2px;
```
