# mahylanv/secret-santa architecture

> Architecture diagram of the GitHub repository mahylanv/secret-santa, 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/mahylanv/secret-santa
- Repository: https://github.com/mahylanv/secret-santa

## Overview

##### Project type and purpose
- This is a backend RESTful service written in Node.js/Express, using MongoDB for persistence.

##### File structure
- Top level:
- app.js: entry point, configures Express and routes
- .env.sample, package.json: configuration and dependencies
- Directories:
- routes/: maps HTTP endpoints to controller functions
- controllers/: implements request handling and orchestration
- middleware/: JWT authentication guard
- models/: Mongoose schemas for User and Group
- Supporting files:
- package-lock.json: exact dependency tree
- .gitignore: files excluded from source control

##### README for insights
- Confirms tech stack: Express, Mongoose, bcrypt, jsonwebtoken, validator, dotenv, nodemon
- Requires MongoDB
- Usage: install dependencies, start MongoDB service, then run the server

##### Main components and interactions
a. Components
- Client (e.g., Postman, frontend UI)
- Express API server
– Routing layer (routes/*.js)
– JWT authentication middleware
– Controllers (controllers/*.js)
- MongoDB (models/*.js via Mongoose)
- Environment/config (.env)
b. Relationships
- Client → HTTP request → Express router
- Router → JWT middleware → Controller
- Controller ↔ Mongoose models → MongoDB
c. Architectural patterns
- Layered architecture (routing → middleware → controller → data)
- MVC-influenced separation: models, controllers, routes
- Single-service monolith with clear module boundaries
d. Key technologies
- Node.js, Express.js
- Mongoose for ODM
- JSON Web Tokens for auth
- bcrypt for password hashing
- dotenv for configuration

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (Postman/Frontend)"]:::external

    subgraph "Express API Server"
        subgraph "Routing Layer"
            UserRoute["userRoute.js"]:::api
            GroupRoute["groupRoute.js"]:::api
        end
        AuthMiddleware["JWT Middleware"]:::api
        subgraph "Controllers"
            UserController["UserController"]:::business
            GroupController["GroupController"]:::business
        end
        DrawService["Draw Service"]:::business
        subgraph "Data Access Layer"
            UserModel["UserModel"]:::data
            GroupModel["GroupModel"]:::data
        end
        subgraph "Configuration"
            Env[".env.sample"]:::config
            Package["package.json"]:::config
        end
    end

    MongoDB["MongoDB\n(users, groups)"]:::db

    Client -->|"HTTP Request"| UserRoute
    Client -->|"HTTP Request"| GroupRoute
    UserRoute -->|"authorize"| AuthMiddleware
    GroupRoute -->|"authorize"| AuthMiddleware
    AuthMiddleware -->|"verified request"| UserController
    AuthMiddleware -->|"verified request"| GroupController
    UserController -->|"reads/writes"| UserModel
    GroupController -->|"reads/writes"| GroupModel
    UserModel -->|"persist data"| MongoDB
    GroupModel -->|"persist data"| MongoDB
    GroupController -->|"invoke draw"| DrawService
    DrawService -->|"update group pairs"| GroupModel

    click UserRoute "https://github.com/mahylanv/secret-santa/blob/main/routes/userRoute.js"
    click GroupRoute "https://github.com/mahylanv/secret-santa/blob/main/routes/groupRoute.js"
    click AuthMiddleware "https://github.com/mahylanv/secret-santa/blob/main/middleware/jwtMiddleware.js"
    click UserController "https://github.com/mahylanv/secret-santa/blob/main/controllers/userController.js"
    click GroupController "https://github.com/mahylanv/secret-santa/blob/main/controllers/groupController.js"
    click DrawService "https://github.com/mahylanv/secret-santa/blob/main/draw.js"
    click UserModel "https://github.com/mahylanv/secret-santa/blob/main/models/userModel.js"
    click GroupModel "https://github.com/mahylanv/secret-santa/blob/main/models/groupModel.js"
    click Env "https://github.com/mahylanv/secret-santa/blob/main/.env.sample"
    click Package "https://github.com/mahylanv/secret-santa/blob/main/package.json"

    classDef external fill:#87CEEB,stroke:#333,stroke-width:1px
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef business fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#FFA500,stroke:#333,stroke-width:1px
    classDef db fill:#FF8C00,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
```
