# dan-marinescu/bezeq architecture

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

- Interactive diagram: https://gitdiagram.com/dan-marinescu/bezeq
- Repository: https://github.com/dan-marinescu/bezeq

## Overview

##### Project type and purpose
- This is a small full-stack web application built with Node.js and Express.
- Purpose: provide signup and login pages, authenticate users, and grant access to a protected “secret” page.
- It follows an MVC-style pattern (Models, Views, Controllers in app.js) and uses MongoDB/Mongoose for persistence and cookies for session handling.

##### File structure
- app.js: the main Express server file where routes, middleware, and database connection are defined.
- Models/user.js: Mongoose schema and data-access logic for user accounts.
- views/*.ejs: Express view templates for login, signup, and secret pages (the presentation layer).
- css/*.css: static stylesheets served to the client.
- package.json/lock and .gitignore: dependency management and exclusions.
- No separate “controllers” folder—route handlers live in app.js.

##### README for additional insights
- Technology stack: HTML5, CSS, JavaScript, NodeJS, Express, MongoDB, Mongoose, Cookies.
- No mention of external services beyond a local MongoDB instance.
- No client-side JS frameworks—the front end is server-rendered EJS.

a. Main components
– Browser (client)
– HTTP Server (Express in Node.js)
– Authentication layer (cookie-based auth middleware in app.js)
– Mongoose-based Data Access (Models/user.js)
– MongoDB database
– Static-assets server (CSS files under /css)
b. Relationships and interactions
– Browser sends HTTP requests for /signup, /login, /secret, static CSS.
– Express routes in app.js handle each request, call Mongoose (Models/user.js) to read/write user data.
– On login/signup success, Express sets an authentication cookie.
– Subsequent requests to /secret pass through auth middleware before rendering secret.ejs.
– Static CSS files are served by Express’s static-file middleware.
c. Architectural patterns and design principles
– MVC-style separation: Models folder for data schemas, Views folder for presentation, Controllers embedded in app.js.
– Single-process Node.js server handling both API and page rendering.
– Cookie-based session management, minimal external dependencies.
d. Key technologies/frameworks
– Node.js and Express for HTTP handling and routing
– EJS for server-side templating
– MongoDB as document store, Mongoose as ORM/ODM
– Cookie middleware for authentication
– Static CSS delivery

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Browser"]:::presentation
        SignupView["signup.ejs"]:::presentation
        LoginView["login.ejs"]:::presentation
        SecretView["secret.ejs"]:::presentation
        CSSAssets["CSS Files"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Express["Express Server"]:::application
        AuthMiddleware["Auth Middleware"]:::application
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        UserModel["User Model (user.js)"]:::data
        MongoDB["MongoDB"]:::data
    end

    %% Meta Layer
    subgraph "Project Meta"
        direction TB
        PackageJSON["package.json"]:::meta
        PackageLock["package-lock.json"]:::meta
        Readme["README.md"]:::meta
        Gitignore[".gitignore"]:::meta
    end

    %% Connections
    Browser -->|GET /signup| Express
    Browser -->|POST /signup| Express
    Browser -->|GET /login| Express
    Browser -->|POST /login| Express
    Browser -->|GET /secret| Express
    Browser -->|GET /css/*| Express

    Express -->|uses| AuthMiddleware
    AuthMiddleware -->|verifies cookie| Express

    Express -->|create/read user| UserModel
    UserModel -->|read/write| MongoDB

    Express -->|renders| SignupView
    Express -->|renders| LoginView
    Express -->|renders| SecretView
    Express -->|serves| CSSAssets

    Express -->|Set-Cookie| Browser
    Browser -->|Cookie header| Express

    %% Click Events
    click Express "https://github.com/dan-marinescu/bezeq/blob/master/app.js"
    click AuthMiddleware "https://github.com/dan-marinescu/bezeq/blob/master/app.js"
    click UserModel "https://github.com/dan-marinescu/bezeq/blob/master/Models/user.js"
    click SignupView "https://github.com/dan-marinescu/bezeq/blob/master/views/signup.ejs"
    click LoginView "https://github.com/dan-marinescu/bezeq/blob/master/views/login.ejs"
    click SecretView "https://github.com/dan-marinescu/bezeq/blob/master/views/secret.ejs"
    click CSSAssets "https://github.com/dan-marinescu/bezeq/tree/master/css/"
    click PackageJSON "https://github.com/dan-marinescu/bezeq/blob/master/package.json"
    click PackageLock "https://github.com/dan-marinescu/bezeq/blob/master/package-lock.json"
    click Readme "https://github.com/dan-marinescu/bezeq/blob/master/README.md"
    click Gitignore "https://github.com/dan-marinescu/bezeq/blob/master/.gitignore"

    %% Styles
    classDef presentation fill:#f9f,stroke:#333,stroke-width:1px
    classDef application fill:#bbf,stroke:#333,stroke-width:1px
    classDef data fill:#bfb,stroke:#333,stroke-width:1px
    classDef meta fill:#eee,stroke:#333,stroke-width:1px
```
