# zeuhz-droid/capstone-project architecture

> Architecture diagram of the GitHub repository zeuhz-droid/capstone-project, 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/zeuhz-droid/capstone-project
- Repository: https://github.com/zeuhz-droid/capstone-project

## Overview

##### Project and Its Purpose
- Project Type: This is a full-stack web application that provides URL shortening, custom URL creation, QR code generation, analytics, and link history functionalities.
- Purpose: The app shortens long URLs (referred to as “limo” in the code), allows customization, generates QR codes via an external API, and provides analytics and history tracking for users.

##### File Structure
- Entry Points:
- app.js and server.js serve as the main entry scripts to initialize the application and the Node.js server.
- MVC Separation:
- controllers/: Houses the logic for handling requests (e.g., authController.js handles authentication, limoController.js handles URL shortening functionality).
- models/: Contains data models (limoModel.js and userModel.js) defining the structure and constraints of the data (for example, link attributes and user details).
- views/: Contains EJS templates (index.ejs, login.ejs, signup.ejs) to render HTML and deliver UI to clients.
- routes/: Defines the API endpoints (like limoRouter.js) that map HTTP requests to controller methods.
- public/: Serves static assets (images, JavaScript file, CSS styles) needed for the frontend.
- utils/: Contains helper functions (utils.js) to encapsulate reusable logic.
- tests/: Contains test scripts (limo.test.js) for unit or integration testing.

- Support Files:
- package.json and package-lock.json provide dependency and configuration management.
- .gitignore indicates version control configurations.

##### README for Additional Details
- The README clearly explains the feature set (URL shortening, analytics, QR code generation), API endpoints for key functionalities, and a data schema for the link model.
- It also provides information on the required deployment environment (Node.js, MongoDB) and usage instructions.
- The documentation gives clarity on how routes are used (e.g., /api/v1/shorten for POST requests, /api/v1/:shortID for redirection).

a. Main Components:
- Client/User Interface:
- Web Browser/UI interacting via forms and rendered pages.
- EJS templates from the views/ folder.
- Static assets loaded from public/ (script.js, styles.css, imgs).
- API Gateway / Routing Layer:
- Express routing specified in routes/ (limoRouter.js) that maps URLs to controllers.
- Controllers:
- authController.js: handles login and signup operations.
- limoController.js: handles URL shortening, link redirection logic.
- Models/Database Layer:
- Models representing users and links (limoModel.js, userModel.js) that interface with MongoDB.
- External Services:
- A third-party QR Code generation API (integrated within the limoController logic).
- Utilities:
- Helper functions in utils/utils.js which support business logic.
- Testing:
- Automated tests in tests/ ensuring functionality and correctness.

b. Relationships and Interactions:
- A user submits a URL via the web UI. The request travels to the API layer (routes) then to the corresponding controller.
- Controller processes the request: uses the model to insert or retrieve data in MongoDB, calls external API if QR generation is needed.
- The controller renders a view (via EJS) which is sent back to the client, or redirects to the original URL.
- The static assets in public/ are served directly to support UI interactivity.
- Authentication flows (signup, login) follow a similar pattern with the authController directing to respective views.

c. Architectural Patterns and Design Principles:
- MVC-Inspired Separation: Clear separation between controllers, models, and views to enhance maintainability.
- RESTful API Design: Routes exposed under /api/v1/ reflect common REST principles.
- Modular Design: Directory segmentation (controllers, routes, models, etc.) signals modularity and easier scalability.
- Emphasis on reusability: Utilization of utility functions and dedicated testing directory.

d. Technologies, Frameworks, and Libraries:
- Node.js for the backend.
- Express (implicit via routes/controllers) for server-side routing and middleware management.
- EJS for templating.
- MongoDB (as suggested in the README) for data persistence.
- Third-party APIs for QR code generation.
- Testing frameworks/libraries (likely Jest or Mocha, inferred from tests/ folder).

##### Putting It Together
- Controller interactions with the data models connecting to MongoDB.
- External API interaction for QR code generation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Points
    subgraph "Entry Points"
        APP("app.js"):::entry
        SRV("server.js"):::entry
    end

    %% Client/User Interface
    subgraph "Client/User Interface"
        EJS("EJS Templates"):::ui
        STATIC("Static Assets"):::ui
    end

    %% API Gateway / Routing Layer
    ROUTER("API Gateway (routes/limoRouter.js)"):::backend

    %% Controllers
    subgraph "Controllers"
        AUTH("Authentication Controller"):::backend
        LIMO("Limo Controller"):::backend
    end

    %% Models/Database Layer
    subgraph "Models/Database"
        LIMOM("Limo Model"):::database
        USERM("User Model"):::database
    end

    %% External Services
    EXT("External Service (QR Code API)"):::external

    %% Utilities
    UTIL("Utilities (utils/utils.js)"):::utils

    %% Testing Suite
    TEST("Testing Suite (tests/)"):::testing

    %% Flows
    APP -->|"initializes"| SRV
    SRV -->|"starts"| ROUTER
    ROUTER -->|"routes requests to"| AUTH
    ROUTER -->|"routes requests to"| LIMO
    AUTH -->|"interacts with"| LIMOM
    AUTH -->|"interacts with"| USERM
    LIMO -->|"interacts with"| LIMOM
    LIMO -->|"calls"| EXT
    LIMO -->|"uses"| UTIL
    AUTH -->|"renders"| EJS
    LIMO -->|"renders"| EJS
    EJS -->|"loads"| STATIC
    TEST -->|"validates"| AUTH
    TEST -->|"validates"| LIMO

    %% Click Events for Entry Points
    click APP "https://github.com/zeuhz-droid/capstone-project/blob/main/app.js"
    click SRV "https://github.com/zeuhz-droid/capstone-project/blob/main/server.js"

    %% Click Events for Client/User Interface
    click EJS "https://github.com/zeuhz-droid/capstone-project/tree/main/views/"
    click STATIC "https://github.com/zeuhz-droid/capstone-project/tree/main/public/"

    %% Click Event for API Gateway / Routing Layer
    click ROUTER "https://github.com/zeuhz-droid/capstone-project/blob/main/routes/limoRouter.js"

    %% Click Events for Controllers
    click AUTH "https://github.com/zeuhz-droid/capstone-project/blob/main/controllers/authController.js"
    click LIMO "https://github.com/zeuhz-droid/capstone-project/blob/main/controllers/limoController.js"

    %% Click Events for Models/Database Layer
    click LIMOM "https://github.com/zeuhz-droid/capstone-project/blob/main/models/limoModel.js"
    click USERM "https://github.com/zeuhz-droid/capstone-project/blob/main/models/userModel.js"

    %% Click Event for Utilities
    click UTIL "https://github.com/zeuhz-droid/capstone-project/blob/main/utils/utils.js"

    %% Click Events for Testing Suite
    click TEST "https://github.com/zeuhz-droid/capstone-project/blob/main/tests/limo.test.js"

    %% Styling
    classDef entry fill:#ffcccb,stroke:#000,stroke-width:1px;
    classDef ui fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90ee90,stroke:#000,stroke-width:1px;
    classDef database fill:#ffd700,stroke:#000,stroke-width:1px;
    classDef external fill:#f08080,stroke:#000,stroke-width:1px;
    classDef utils fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef testing fill:#dda0dd,stroke:#000,stroke-width:1px;
```
