# dvirhayat/web-course-backend architecture

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

- Interactive diagram: https://gitdiagram.com/dvirhayat/web-course-backend
- Repository: https://github.com/dvirhayat/web-course-backend

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js application (React front end + serverless API) whose back end manages users, hobbies, and workplaces for the Social Network project. It uses Next.js’ app & pages folders to serve UI and API routes, Mongoose for ODM, and MongoDB (Atlas or self-hosted) as its data store.

##### File-Structure Analysis
- Top level:
- package.json / next.config.mjs / vercel.json – build, runtime, and deployment configs
- pages/api – Next.js API routes (login, register, userUtil, adminUtil, hobbiesUtil, workplaceUtil)
- src/app – Next.js 13+ React UI (globals.css, layout.js, page.js)
- lib – Data-access layer (mongodb connection, CRUD utilities for users/hobbies/workplaces)
- models – Mongoose schemas (User, Hobby, Workplace)
- Patterns:
- “Controller” layer in pages/api → “Service/DAO” layer in lib → “Model” definitions → MongoDB
- Separation of concerns: React (UI) vs. API endpoints (business logic) vs. DB utilities

##### Key Components
a. Client & Presentation Layer
- Browser / React UI components (src/app)
- Tailwind / CSS / static assets (public/, globals.css)
b. API Layer (Next.js Serverless Functions)
- pages/api/*.js endpoints (login, register, userUtil, adminUtil, hobbiesUtil, workplaceUtil)
c. Service/DAO Layer
- lib/mongodb.js (connection manager)
- lib/usersDB.js, hobbiesDB.js, workplaceDB.js (CRUD operations)
d. Data Models
- models/User.js, Hobby.js, Workplace.js (Mongoose schemas & validation)
e. Database
- MongoDB (Atlas or other), environment-driven URI
f. External Services & Infrastructure
- Vercel (hosting)
- Environment variables (.env.local → MONGODB_URI)

##### Relationships & Data Flows
- UI → HTTP call → API endpoint
- API endpoint → calls DAO functions in lib/*DB.js → interacts with Mongoose models
- Mongoose → issues queries to MongoDB → returns data to DAO → API → UI
- Admin endpoints perform DELETE/PATCH operations; Hobby and Workplace endpoints allow GET/PUT/DELETE
- next.config.mjs and vercel.json configure routing and rewrites between front end and API

##### Architectural Patterns & Principles
- Layered architecture (Presentation → Controller → Service/DAO → Data/Model → Persistence)
- Single responsibility per module: each API file handles one resource
- Reusable DB connection (caching via lib/mongodb.js)
- Convention-over-configuration (Next.js folder conventions)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client & Presentation"
        UIPage["page.js"]:::client
        UILayout["layout.js"]:::client
        UIGlobals["globals.css"]:::client
        UIPublic["public/"]:::client
    end

    subgraph "API Layer"
        LoginAPI["login.js"]:::api
        RegisterAPI["register.js"]:::api
        UserAPI["userUtil.js"]:::api
        AdminAPI["adminUtil.js"]:::api
        HobbiesAPI["hobbiesUtil.js"]:::api
        WorkplaceAPI["workplaceUtil.js"]:::api
    end

    subgraph "Service/DAO Layer"
        MongoMgr["mongodb.js"]:::dao
        UsersDAO["usersDB.js"]:::dao
        HobbiesDAO["hobbiesDB.js"]:::dao
        WorkplaceDAO["workplaceDB.js"]:::dao
    end

    subgraph "Data Models"
        UserModel["User.js"]:::model
        HobbyModel["Hobby.js"]:::model
        WorkplaceModel["Workplace.js"]:::model
    end

    DB["MongoDB"]:::db

    subgraph "Config & Deployment"
        NextConfig["next.config.mjs"]:::infra
        VercelConfig["vercel.json"]:::infra
        TailwindConfig["tailwind.config.js"]:::infra
        PostCSSConfig["postcss.config.mjs"]:::infra
        Package["package.json"]:::infra
    end

    UIPage -->|"calls"| LoginAPI
    UIPage -->|"calls"| RegisterAPI
    UIPage -->|"calls"| UserAPI
    UIPage -->|"calls"| AdminAPI
    UIPage -->|"calls"| HobbiesAPI
    UIPage -->|"calls"| WorkplaceAPI

    LoginAPI --> UsersDAO
    RegisterAPI --> UsersDAO
    UserAPI --> UsersDAO
    AdminAPI --> UsersDAO
    HobbiesAPI --> HobbiesDAO
    WorkplaceAPI --> WorkplaceDAO

    UsersDAO --> UserModel
    HobbiesDAO --> HobbyModel
    WorkplaceDAO --> WorkplaceModel

    UserModel --> DB
    HobbyModel --> DB
    WorkplaceModel --> DB
    MongoMgr --> DB

    NextConfig -.->|configures| LoginAPI
    NextConfig -.->|configures| RegisterAPI
    VercelConfig -.->|deploys| LoginAPI
    TailwindConfig -.->|styles| UIPage
    PostCSSConfig -.->|styles| UIPage
    Package -.->|defines deps| UIPage

    NextConfig -.-> MongoMgr

    classDef client fill:#cce5ff,stroke:#004085,stroke-width:1px
    classDef api fill:#d4edda,stroke:#155724,stroke-width:1px
    classDef dao fill:#fff3cd,stroke:#856404,stroke-width:1px
    classDef model fill:#ffe5b4,stroke:#ff8c00,stroke-width:1px
    classDef db fill:#d1ecf1,stroke:#0c5460,stroke-width:1px,shape:cylinder
    classDef infra fill:#e2e3e5,stroke:#6c757d,stroke-width:1px

    click UIPage "https://github.com/dvirhayat/web-course-backend/blob/master/src/app/page.js"
    click UILayout "https://github.com/dvirhayat/web-course-backend/blob/master/src/app/layout.js"
    click UIGlobals "https://github.com/dvirhayat/web-course-backend/blob/master/src/app/globals.css"
    click UIPublic "https://github.com/dvirhayat/web-course-backend/tree/master/public/"
    click LoginAPI "https://github.com/dvirhayat/web-course-backend/blob/master/pages/api/login.js"
    click RegisterAPI "https://github.com/dvirhayat/web-course-backend/blob/master/pages/api/register.js"
    click UserAPI "https://github.com/dvirhayat/web-course-backend/blob/master/pages/api/userUtil.js"
    click AdminAPI "https://github.com/dvirhayat/web-course-backend/blob/master/pages/api/adminUtil.js"
    click HobbiesAPI "https://github.com/dvirhayat/web-course-backend/blob/master/pages/api/hobbiesUtil.js"
    click WorkplaceAPI "https://github.com/dvirhayat/web-course-backend/blob/master/pages/api/workplaceUtil.js"
    click MongoMgr "https://github.com/dvirhayat/web-course-backend/blob/master/lib/mongodb.js"
    click UsersDAO "https://github.com/dvirhayat/web-course-backend/blob/master/lib/usersDB.js"
    click HobbiesDAO "https://github.com/dvirhayat/web-course-backend/blob/master/lib/hobbiesDB.js"
    click WorkplaceDAO "https://github.com/dvirhayat/web-course-backend/blob/master/lib/workplaceDB.js"
    click UserModel "https://github.com/dvirhayat/web-course-backend/blob/master/models/User.js"
    click HobbyModel "https://github.com/dvirhayat/web-course-backend/blob/master/models/Hobby.js"
    click WorkplaceModel "https://github.com/dvirhayat/web-course-backend/blob/master/models/Workplace.js"
    click NextConfig "https://github.com/dvirhayat/web-course-backend/blob/master/next.config.mjs"
    click VercelConfig "https://github.com/dvirhayat/web-course-backend/blob/master/vercel.json"
    click TailwindConfig "https://github.com/dvirhayat/web-course-backend/blob/master/tailwind.config.js"
    click PostCSSConfig "https://github.com/dvirhayat/web-course-backend/blob/master/postcss.config.mjs"
    click Package "https://github.com/dvirhayat/web-course-backend/blob/master/package.json"
```
