# nievas2/tech-library architecture

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

- Interactive diagram: https://gitdiagram.com/nievas2/tech-library
- Repository: https://github.com/nievas2/tech-library

## Overview

##### Project Overview
- The backend (in the “back” directory) is built with Node.js/TypeScript and follows a modular structure. It’s organized by domains (e.g., auth, library, like, tag, user) and contains components such as controllers, services, entities, routes, strategies (for authentication with JWT, GitHub, Google, local login), and shared utilities (for error handling, middlewares, configuration, etc.).
- The frontend (in the “front” directory) is a React-based application bootstrapped by Vite. It is organized into pages, components, hooks, contexts, services, and utilities, supporting features like authentication, library management, tag handling, and user dashboards.
- Docker files and a docker-compose configuration in the “back” folder indicate containerization for deployment and development. The “back/mysql/init.sql” file shows that MySQL is used as the primary database.

##### Main Components
a. Frontend:
- Frontend Application (React/Vite) – include major directories like pages, components, contexts, hooks, and API service connectors (e.g., axiosInstance).
- Features/components: Authentication pages (login, register), Dashboard pages (admin and user), Home and Landing pages, and UI components.
b. Backend:
- API Server (main entry point: back/src/server.ts) – encapsulates the business logic.
- Authentication Module – handling user authentication with various strategies, controllers, and routes.
- Library Module – managing library resources (entities, controllers, service, and middleware for libraries).
- Like Module – operations related to “likes” with its own service and error handling.
- Tag Module – managing tags through its controllers, services, and middleware.
- User Module – for user management (controllers, services, entities) and role definitions.
- Shared Utilities – common error handling routines, middlewares, response formats, and utility functions.
- Configuration & Environment Management – all the configuration files and environment variables loaded for different environments.
c. Database & Infrastructure:
- MySQL Database – represented as its own component (with initialization via back/mysql/init.sql).
- Docker & Deployment – Dockerfile(s) and docker-compose setups that orchestrate container-based deployment.

##### Relationships and Interactions
- Within the Backend, illustrate how the API server routes requests to the appropriate modules. For example, requests that hit “auth.router” delegate to authentication controllers which, in turn, use strategies (like JWT, GitHub, etc.) and services.
- How shared middlewares (e.g., error handling, request validation) are used by each module to process incoming requests.
- Connection between the Backend and the MySQL database to show data persistence.
- Optionally, show that Docker is used to containerize the backend and database: a container for Node.js and a container for the MySQL instance.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Each domain/module in the backend encapsulates its own controllers, services, entities, exceptions, and middlewares.
- Modular Architecture: Clear segmentation of functionalities (auth, library, like, tag, user) enables maintainability and scalability.
- API Layer: The server layer (with a clear routing mechanism) manages the API requests and delegates functionality to the business logic.
- Containerization: Docker is used for consistency across environments with environmental variables and docker-compose for multi-container orchestration.
- On the frontend, component-based design (React with contexts and hooks) promotes reusability and a clean separation between UI components and business logic/service calls.

##### Extra Details
- API Gateway/LB (if applicable) – although not explicitly defined, you might want to note that the Node.js server could be handling incoming requests.

– The overall separation between frontend and backend,
– Modular domain-specific architecture in the backend,
– Infrastructure elements (like MySQL and Docker) used in deployment,
– Clear flow of data and interactions between the distinct components of the application.

This level of detail will provide clarity to both technical and non-technical stakeholders and serve as a solid blueprint for understanding the system’s architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "React Frontend (Vite)"
        F1["Frontend Application (React/Vite)"]:::frontend
        F2["Pages"]:::frontend
        F3["Components"]:::frontend
        F4["Contexts"]:::frontend
        F5["Hooks"]:::frontend
        F6["API Service Connector"]:::frontend
        F1 --> F2
        F2 --> F3
        F3 --> F4
        F4 --> F5
        F5 --> F6
    end

    subgraph "Node.js Backend (TypeScript)"
        B1["API Server (Entry Point)"]:::backend

        subgraph "Authentication Module"
            A1["Auth Router"]:::backend
            A2["Auth Controllers"]:::backend
            A3["Auth Services"]:::backend
            A4["Auth Strategies"]:::backend
            A5["Passport Utility & Token Interface"]:::backend
        end

        subgraph "Library Module"
            L1["Library Router"]:::backend
            L2["Library Controllers"]:::backend
            L3["Library Entities & DTOs"]:::backend
            L4["Library Middlewares"]:::backend
            L5["Library Exception Handlers"]:::backend
        end

        subgraph "Like Module"
            LI1["Like Service"]:::backend
            LI2["Like Entities"]:::backend
            LI3["Like Exceptions"]:::backend
        end

        subgraph "Tag Module"
            T1["Tag Router"]:::backend
            T2["Tag Controllers"]:::backend
            T3["Tag Entities & DTOs"]:::backend
            T4["Tag Middlewares"]:::backend
            T5["Tag Exceptions"]:::backend
        end

        subgraph "User Module"
            U1["User Router"]:::backend
            U2["User Controllers"]:::backend
            U3["User Entities, DTOs & Roles"]:::backend
            U4["User Middlewares"]:::backend
            U5["User Exceptions"]:::backend
        end

        subgraph "Shared Utilities & Global Components"
            S1["Global Exception Handling"]:::backend
            S2["Shared Middlewares"]:::backend
            S3["Shared Response Helpers"]:::backend
            S4["Shared Router"]:::backend
            S5["Shared Utils"]:::backend
        end

        B2["Configuration & Env Management"]:::backend

        B1 -->|"routes"| A1
        B1 -->|"routes"| L1
        B1 -->|"routes"| LI1
        B1 -->|"routes"| T1
        B1 -->|"routes"| U1
    end

    D["MySQL Database"]:::database

    subgraph "Docker & Deployment"
        DCK1["Dockerfile"]:::docker
        DCK2["Docker Compose"]:::docker
    end

    F1 -->|"API_Call"| B1
    A2 -->|"DB_Query"| D
    L2 -->|"DB_Query"| D
    LI2 -->|"DB_Query"| D
    T3 -->|"DB_Query"| D
    U3 -->|"DB_Query"| D

    DCK1 -->|"Containerizes"| B1
    DCK1 -->|"Containerizes"| D
    DCK2 -->|"Orchestrates"| B1
    DCK2 -->|"Orchestrates"| D

    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px,color:#000;
    classDef backend fill:#cfc,stroke:#333,stroke-width:2px,color:#000;
    classDef database fill:#faa,stroke:#333,stroke-width:2px,color:#000;
    classDef docker fill:#ffc,stroke:#333,stroke-width:2px,color:#000;

click F1 "https://github.com/nievas2/tech-library/tree/developer/front/src"
click F2 "https://github.com/nievas2/tech-library/tree/developer/front/src/pages"
click F3 "https://github.com/nievas2/tech-library/tree/developer/front/src/components"
click F4 "https://github.com/nievas2/tech-library/tree/developer/front/src/contexts"
click F5 "https://github.com/nievas2/tech-library/tree/developer/front/src/hooks"
click F6 "https://github.com/nievas2/tech-library/blob/developer/front/src/api/axiosInstance.tsx"

click B1 "https://github.com/nievas2/tech-library/blob/developer/back/src/server.ts"
click A1 "https://github.com/nievas2/tech-library/blob/developer/back/src/auth/auth.routher.ts"
click A2 "https://github.com/nievas2/tech-library/blob/developer/back/src/auth/controllers/auth.controller.ts"
click A3 "https://github.com/nievas2/tech-library/blob/developer/back/src/auth/services/auth.services.ts"
click A4 "https://github.com/nievas2/tech-library/tree/developer/back/src/auth/strategies"
click A5 "https://github.com/nievas2/tech-library/tree/developer/back/src/auth/utils"
click L1 "https://github.com/nievas2/tech-library/blob/developer/back/src/library/library.router.ts"
click L2 "https://github.com/nievas2/tech-library/blob/developer/back/src/library/controllers/library.controller.ts"
click L3 "https://github.com/nievas2/tech-library/tree/developer/back/src/library/entities"
click L4 "https://github.com/nievas2/tech-library/blob/developer/back/src/library/middlewares/library.middleware.ts"
click L5 "https://github.com/nievas2/tech-library/tree/developer/back/src/library/exception"
click LI1 "https://github.com/nievas2/tech-library/blob/developer/back/src/like/service/like.service.ts"
click LI2 "https://github.com/nievas2/tech-library/blob/developer/back/src/like/entities/like.entity.ts"
click LI3 "https://github.com/nievas2/tech-library/tree/developer/back/src/like/exception"
click T1 "https://github.com/nievas2/tech-library/blob/developer/back/src/tag/tag.router.ts"
click T2 "https://github.com/nievas2/tech-library/blob/developer/back/src/tag/controllers/tag.controller.ts"
click T3 "https://github.com/nievas2/tech-library/tree/developer/back/src/tag/entities"
click T4 "https://github.com/nievas2/tech-library/blob/developer/back/src/tag/middlewares/tag.middleware.ts"
click T5 "https://github.com/nievas2/tech-library/tree/developer/back/src/tag/exceptions"
click U1 "https://github.com/nievas2/tech-library/blob/developer/back/src/user/user.router.ts"
click U2 "https://github.com/nievas2/tech-library/blob/developer/back/src/user/controllers/user.controller.ts"
click U3 "https://github.com/nievas2/tech-library/tree/developer/back/src/user/entities"
click U4 "https://github.com/nievas2/tech-library/blob/developer/back/src/user/middlewares/user.middleware.ts"
click U5 "https://github.com/nievas2/tech-library/tree/developer/back/src/user/exceptions"
click S1 "https://github.com/nievas2/tech-library/tree/developer/back/src/shared/exception"
click S2 "https://github.com/nievas2/tech-library/tree/developer/back/src/shared/middlewares"
click S3 "https://github.com/nievas2/tech-library/tree/developer/back/src/shared/response"
click S4 "https://github.com/nievas2/tech-library/blob/developer/back/src/shared/router/router.ts"
click S5 "https://github.com/nievas2/tech-library/blob/developer/back/src/shared/utils/utils.ts"
click B2 "https://github.com/nievas2/tech-library/tree/developer/back/src/config"
click D "https://github.com/nievas2/tech-library/blob/developer/back/mysql/init.sql"
click DCK1 "https://github.com/nievas2/tech-library/tree/developer/back/Dockerfile"
click DCK2 "https://github.com/nievas2/tech-library/blob/developer/back/docker-compose.yml"
```
