# arnoldcuriano/phase-1-web-development-bge-application architecture

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

- Interactive diagram: https://gitdiagram.com/arnoldcuriano/phase-1-web-development-bge-application
- Repository: https://github.com/arnoldcuriano/phase-1-web-development-bge-application

## Overview

##### Project Type and Purpose
- The project is an internal web application built primarily for BGE employees and administrators.
- It’s a full-stack web application built on Node.js, employing a typical MVC pattern using ExpressJS, with MongoDB as the database.
- The project supports various business functions (e.g., handling announcements, projects, departments, members, services, categories, etc.) through dedicated controllers, models, and views.

##### File Structure
- Key top-level directories:
- “controllers”: Contains business logic for different data entities (e.g., category, client, department, etc.).
- “models”: Defines Mongoose schema-based models for the database, which maps well with MongoDB.
- “routes”: Contains ExpressJS routes that map URL endpoints to controllers.
- “views”: Holds EJS templates (and some Pug templates for emails) which render the frontend.
- “public”: Contains static assets such as fonts, images, and uploads.
- “config”: Contains configuration files including authentication settings (passport) and possibly keys.
- “middleware”: Contains custom middleware (like auth.js) that handles authentication or other request processing.
- Other supporting files include package configuration files (package.json, ecosystem.config.js), deployment scripts (start_pm2.sh), and environment-related files.

##### README for Additional Insights
- The README confirms that this project is built using Node.js and MongoDB, and lists other important packages such as Express, Mongoose, EJS, Multer, Passport, etc.
- It briefly outlines the installation and basic steps but also hints at a Phase I development status, showing that the architecture should account for potential future scaling and improvement.
- The README highlights the use of both EJS and Pug, meaning parts of the application (likely differing sections or email templates) might use different templating engines.

a. Main Components:
- Client/Browser: This is where the frontend interacts via EJS templates for rendering webpages.
- Web Server (Express/Node.js): Acts as the central processing unit responding to HTTP requests. Inside this, you have:
- Routes: Handle incoming HTTP requests and dispatch them to appropriate controllers.
- Controllers: Implement core business logic for different functionalities.
- Middleware: Manage authentication (using Passport and custom auth middleware) and possibly other request/response processing.
- Views: The presentation layer using EJS and Pug templates.
- Database (MongoDB): This stores all persistent data for models such as announcements, projects, departments, etc.
- External Services/Dependencies:
- Multer: For file/image uploads.
- Sharp: For image processing.
- Nodemailer (mailer) with Pug: For sending emails.
- Authentication (Passport).
- PM2 Ecosystem: For production process management.

b. Relationships and Interactions:
- Within the Server, routes map to controllers which then interact with models (via Mongoose) to query or update MongoDB.
- The middleware is positioned between routes and controllers (or as an integral part of the route processing) to handle authentication and validations.
- The views are dynamically rendered in response to requests from the controllers.
- External libraries like Multer and Sharp integrate for file handling, and services like the mailer are invoked from within the controllers when required.
- Configuration files and environment variables ensure that sensitive details (like keys and passport settings) are centrally managed and injected where needed.

c. Architectural Patterns and Design Principles:
- MVC (Model-View-Controller): Clear separation of responsibilities across models, views, and controllers.
- Modular Design: Different concerns (routes, controllers, middleware, models) are separated into distinct directories.
- Separation of Static and Dynamic Assets: “public” holds static resources, while dynamic content is rendered in the “views” layer.
- Utilization of Environment Configurations: The “config” directory ensures that global settings (like keys, passport setup) follow environment-specific adjustments.
- Scalability and Maintainability: PM2 configuration and modularity in design ease scaling and maintenance.

d. Relevant Technologies and Frameworks:
- Node.js and ExpressJS for the server.
- MongoDB as the database with Mongoose ODM.
- EJS and Pug templating engines.
- Passport for authentication.
- Multer for file uploads and Sharp for image processing.
- Session management (Express Session) and various middleware components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        A["Client/Browser"]:::frontend
    end

    %% Web Server Layer
    subgraph "Web Server Layer"
        S["Server Entry (Express/Node.js)"]:::backend
        R["Routes"]:::backend
        M["Middleware"]:::backend
        C["Controllers"]:::backend
        V["Views (EJS & Pug)"]:::frontend
    end

    %% Database Layer
    subgraph "Database Layer"
        D["MongoDB Database"]:::database
    end

    %% Configuration & Process Management
    subgraph "Configuration & Process"
        CONFIG["Configuration Management"]:::config
        PM1["PM2 Ecosystem Config"]:::external
        PM2["PM2 Start Script"]:::external
    end

    %% Static Assets & External Services
    subgraph "Static & External Services"
        STATIC["Static Assets"]:::frontend
        U["Uploads"]:::frontend
        EMAIL["Email Service (Nodemailer/Pug)"]:::external
        FILES["File Upload & Image Processing (Multer & Sharp)"]:::external
        AUTH["Authentication (Passport)"]:::external
    end

    %% Connections
    A -->|"HTTPRequest"| S
    S -->|"initialize"| R
    R -->|"routes"| M
    M -->|"validate"| C
    C -->|"accessData"| D
    C -->|"renderPage"| V
    S -->|"serveStatic"| STATIC
    S -->|"serveUploads"| U
    C -->|"triggerEmail"| EMAIL
    C -->|"uploadFiles"| FILES
    M -->|"useAuth"| AUTH
    CONFIG -->|"configure"| S
    CONFIG -->|"configure"| M
    PM1 -->|"monitor"| S
    PM2 -->|"monitor"| S

    %% Click Events
    click V "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/views"
    click S "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/blob/main/server.js"
    click R "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/routes"
    click C "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/controllers"
    click D "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/models"
    click M "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/blob/main/middleware/auth.js"
    click CONFIG "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/config"
    click STATIC "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/public"
    click U "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/uploads"
    click EMAIL "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/tree/main/views/emails"
    click PM1 "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/blob/main/ecosystem.config.js"
    click PM2 "https://github.com/arnoldcuriano/phase-1-web-development-bge-application/blob/main/start_pm2.sh"

    %% Styles
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backend fill:#bfb,stroke:#333,stroke-width:2px;
    classDef database fill:#ffb,stroke:#333,stroke-width:2px;
    classDef external fill:#fbb,stroke:#333,stroke-width:2px;
    classDef config fill:#d9b3ff,stroke:#333,stroke-width:2px;
```
