# bishalspkt/share-my-desk architecture

> Architecture diagram of the GitHub repository bishalspkt/share-my-desk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bishalspkt/share-my-desk
- Repository: https://github.com/bishalspkt/share-my-desk

## Overview

##### Main Components Identification

a) API Layer
- Entry point (index.js and lib/server.js)
- Routes layer (routes/*.js files)
- Authentication middleware (JWT/Passport.js)

b) Service Layer
- AuthService
- DeskService
- OfficeLocationsService

c) Data Layer
- MongoDB (via Mongoose)
- Models (User, Desk)
- Static Data (officeLocations.json)

**[Client Applications]**
- ↓
**[API Gateway/Load Balancer]**
- ↓
**[Express.js Server]**
- ↙     ↓     ↘
**[Routes Layer]**
- ↙     ↓     ↘
**[Services Layer]**
- ↙     ↓     ↘
**[Data Layer]**

##### Specific Component Details

API Layer (Blue):
- Three main route handlers: AuthWs, DeskWs, OfficeLocationsWs
- JWT authentication flow
- Connection to Passport.js

Service Layer (Green):
- Three services: AuthService, DeskService, OfficeLocationsService
- Their interactions with models and static data

Data Layer (Yellow):
- MongoDB connection through Mongoose
- Two main models: User and Desk
- Static JSON data for office locations

##### Additional Elements

Supporting components:
- Logger utility (lib/logger.js)
- Constants configuration
- Utility functions (lib/utils.js, lib/webUtils.js)

##### Flow Representations

Key flows:
- Authentication flow (JWT token generation and verification)
- Desk sharing operations (listing, booking)
- Office location queries

##### Technical Details

Technical annotations:
- Express.js as the main framework
- Passport.js for authentication
- Mongoose for MongoDB ORM
- RAML for API documentation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CL[Client Applications]
    end

    subgraph "API Gateway"
        API[Express.js Server]:::api
        click API "https://github.com/bishalspkt/share-my-desk/blob/master/lib/server.js"
        MAIN[Main Entry Point]:::api
        click MAIN "https://github.com/bishalspkt/share-my-desk/blob/master/index.js"
    end

    subgraph "Route Handlers"
        AUTH_ROUTE[Authentication Routes]:::route
        click AUTH_ROUTE "https://github.com/bishalspkt/share-my-desk/blob/master/routes/AuthWs.js"
        DESK_ROUTE[Desk Routes]:::route
        click DESK_ROUTE "https://github.com/bishalspkt/share-my-desk/blob/master/routes/DeskWs.js"
        OFFICE_ROUTE[Office Location Routes]:::route
        click OFFICE_ROUTE "https://github.com/bishalspkt/share-my-desk/blob/master/routes/OfficeLocationsWs.js"
    end

    subgraph "Service Layer"
        AUTH_SVC[Auth Service]:::service
        click AUTH_SVC "https://github.com/bishalspkt/share-my-desk/blob/master/services/AuthService.js"
        DESK_SVC[Desk Service]:::service
        click DESK_SVC "https://github.com/bishalspkt/share-my-desk/blob/master/services/DeskService.js"
        OFFICE_SVC[Office Locations Service]:::service
        click OFFICE_SVC "https://github.com/bishalspkt/share-my-desk/blob/master/services/OfficeLocationsService.js"
    end

    subgraph "Data Layer"
        DB_CONFIG[Database Config]:::data
        click DB_CONFIG "https://github.com/bishalspkt/share-my-desk/blob/master/lib/db.js"
        USER_MODEL[User Model]:::model
        click USER_MODEL "https://github.com/bishalspkt/share-my-desk/blob/master/models/User.js"
        DESK_MODEL[Desk Model]:::model
        click DESK_MODEL "https://github.com/bishalspkt/share-my-desk/blob/master/models/Desk.js"
    end

    subgraph "Supporting Infrastructure"
        LOGGER[Logger]:::support
        click LOGGER "https://github.com/bishalspkt/share-my-desk/blob/master/lib/logger.js"
        CONSTANTS[Constants]:::support
        click CONSTANTS "https://github.com/bishalspkt/share-my-desk/blob/master/lib/constants.js"
        UTILS[Utilities]:::support
        click UTILS "https://github.com/bishalspkt/share-my-desk/blob/master/lib/utils.js"
        WEB_UTILS[Web Utilities]:::support
        click WEB_UTILS "https://github.com/bishalspkt/share-my-desk/blob/master/lib/webUtils.js"
    end

    subgraph "External Systems"
        MONGODB[(MongoDB)]:::database
        STATIC_JSON[Office Locations JSON]:::file
        click STATIC_JSON "https://github.com/bishalspkt/share-my-desk/blob/master/services/datafiles/officeLocations.json"
    end

    subgraph "Documentation & Testing"
        RAML[RAML API Docs]:::doc
        click RAML "https://github.com/bishalspkt/share-my-desk/blob/master/raml/api.raml"
        TESTS[Service Tests]:::test
        click TESTS "https://github.com/bishalspkt/share-my-desk/tree/master/tests"
        MOCKS[Mock Models]:::test
        click MOCKS "https://github.com/bishalspkt/share-my-desk/tree/master/tests/mocks"
    end

    subgraph "CI/CD"
        CIRCLE[CircleCI]:::cicd
        click CIRCLE "https://github.com/bishalspkt/share-my-desk/blob/master/.circleci/config.yml"
        TRAVIS[Travis CI]:::cicd
        click TRAVIS "https://github.com/bishalspkt/share-my-desk/blob/master/.travis.yml"
        GITHUB[GitHub Actions]:::cicd
        click GITHUB "https://github.com/bishalspkt/share-my-desk/blob/master/.github/workflows/npm-publish.yml"
    end

    %% Relationships
    CL --> API
    API --> MAIN
    MAIN --> |Routes| AUTH_ROUTE & DESK_ROUTE & OFFICE_ROUTE
    AUTH_ROUTE --> AUTH_SVC
    DESK_ROUTE --> DESK_SVC
    OFFICE_ROUTE --> OFFICE_SVC
    AUTH_SVC & DESK_SVC & OFFICE_SVC --> DB_CONFIG
    DB_CONFIG --> USER_MODEL & DESK_MODEL
    USER_MODEL & DESK_MODEL --> MONGODB
    OFFICE_SVC --> STATIC_JSON

    %% Styling
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef route fill:#42A5F5,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef model fill:#FDD835,stroke:#F9A825,color:black
    classDef data fill:#FFB300,stroke:#FB8C00,color:black
    classDef database fill:#FF7043,stroke:#E64A19,color:white
    classDef support fill:#78909C,stroke:#546E7A,color:white
    classDef file fill:#90A4AE,stroke:#607D8B,color:white
    classDef doc fill:#CE93D8,stroke:#AB47BC,color:white
    classDef test fill:#81C784,stroke:#43A047,color:white
    classDef cicd fill:#FF8A65,stroke:#F4511E,color:white
```
