# relydda20/bulletinboardbackend architecture

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

- Interactive diagram: https://gitdiagram.com/relydda20/bulletinboardbackend
- Repository: https://github.com/relydda20/bulletinboardbackend

## Overview

##### Project type and purpose
- This is a backend‐only RESTful API service for a bulletin board application.
- Built with Express.js (server.js, src/app.js), MongoDB Atlas (via Mongoose models), and supports authentication (username/password + Google OAuth), email (password reset), and CRUD for posts/comments.

##### File structure
- Top level
- server.js & src/app.js: entrypoints (loadEnv, Express app setup).
- config/: DB connection, JWT setup, mailer, Passport strategies.
- controllers/: HTTP handlers per resource (auth, posts, comments, users, password resets).
- routes/: maps HTTP endpoints to controllers.
- middleware/: request validation, auth enforcement.
- models/: Mongoose schemas for User, Post, Comment.
- utils/: JWT token issuance/verification, sendEmail abstraction.
- scripts/seed.js + seeders/: CLI scripts to populate the database.

##### README
- Confirms technologies: Express.js, MongoDB Atlas.
- Features: Authentication, CRUD Post, CRUD Comment, Google login, password reset email flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Clients (Web/Mobile)"]:::external

    subgraph "API Server"
        subgraph "Entrypoints"
            LoadEnv["loadEnv.js"]:::internal
            Server["server.js"]:::internal
            App["src/app.js"]:::internal
        end

        subgraph "Configuration"
            DBConfig["db.js"]:::internal
            JWTConfig["jwtConfig.js"]:::internal
            MailerConfig["mailer.js"]:::internal
            PassportConfig["passport.js"]:::internal
        end

        subgraph "Routing Layer"
            AuthRoutes["authRoutes.js"]:::internal
            PassResetRoutes["passwordResetRoutes.js"]:::internal
            PostRoutes["postRoutes.js"]:::internal
            UserRoutes["userRoutes.js"]:::internal
        end

        subgraph "Middleware"
            ValidateMW["validateMiddleware.js"]:::internal
            AuthMW["authMiddleware.js"]:::internal
            PostValMW["postValidation.js"]:::internal
        end

        subgraph "Controllers"
            AuthCtrl["authController.js"]:::internal
            PassResetCtrl["passwordResetController.js"]:::internal
            PostCtrl["postController.js"]:::internal
            CommentCtrl["commentController.js"]:::internal
            UserCtrl["userController.js"]:::internal
        end

        subgraph "Models"
            UserModel["User.js"]:::internal
            PostModel["Post.js"]:::internal
            CommentModel["Comment.js"]:::internal
            ShortId["shortid.js"]:::internal
        end

        subgraph "Utilities/Services"
            JWTUtils["jwtUtils.js"]:::internal
            SendEmail["sendEmail.js"]:::internal
        end
    end

    DB[(MongoDB Atlas)]:::database
    SMTP["SMTP/Email Provider"]:::external
    GoogleOAuth["OAuth Provider (Google)"]:::external

    subgraph "CLI/Dev Tools"
        SeedScript["seed.js"]:::cli
        DBSeeder["databaseSeeder.js"]:::cli
        UserSeeder["userSeeder.js"]:::cli
        PostSeeder["postSeeder.js"]:::cli
        CommentSeeder["commentSeeder.js"]:::cli
    end

    Client -->|"HTTP Request"| App
    LoadEnv --> Server --> App
    App --> AuthRoutes
    App --> PassResetRoutes
    App --> PostRoutes
    App --> UserRoutes

    AuthRoutes --> ValidateMW --> AuthMW --> AuthCtrl
    PassResetRoutes --> ValidateMW --> AuthMW --> PassResetCtrl
    PostRoutes --> ValidateMW --> AuthMW --> PostValMW --> PostCtrl
    PostCtrl --> CommentCtrl
    UserRoutes --> ValidateMW --> AuthMW --> UserCtrl

    AuthCtrl -->|uses| JWTUtils
    AuthCtrl -->|uses| PassportConfig
    PassportConfig -->|calls| GoogleOAuth

    PassResetCtrl -->|uses| SendEmail --> SMTP

    AuthCtrl --> UserModel
    PostCtrl --> PostModel
    CommentCtrl --> CommentModel
    UserCtrl --> UserModel

    UserModel --> DB
    PostModel --> DB
    CommentModel --> DB
    ShortId --> DB

    SeedScript --> DBSeeder --> UserSeeder --> DB
    DBSeeder --> PostSeeder --> DB
    DBSeeder --> CommentSeeder --> DB

    click LoadEnv "https://github.com/relydda20/bulletinboardbackend/blob/main/loadEnv.js"
    click Server "https://github.com/relydda20/bulletinboardbackend/blob/main/server.js"
    click App "https://github.com/relydda20/bulletinboardbackend/blob/main/src/app.js"
    click DBConfig "https://github.com/relydda20/bulletinboardbackend/blob/main/src/config/db.js"
    click JWTConfig "https://github.com/relydda20/bulletinboardbackend/blob/main/src/config/jwtConfig.js"
    click MailerConfig "https://github.com/relydda20/bulletinboardbackend/blob/main/src/config/mailer.js"
    click PassportConfig "https://github.com/relydda20/bulletinboardbackend/blob/main/src/config/passport.js"
    click AuthRoutes "https://github.com/relydda20/bulletinboardbackend/blob/main/src/routes/authRoutes.js"
    click PassResetRoutes "https://github.com/relydda20/bulletinboardbackend/blob/main/src/routes/passwordResetRoutes.js"
    click PostRoutes "https://github.com/relydda20/bulletinboardbackend/blob/main/src/routes/postRoutes.js"
    click UserRoutes "https://github.com/relydda20/bulletinboardbackend/blob/main/src/routes/userRoutes.js"
    click AuthCtrl "https://github.com/relydda20/bulletinboardbackend/blob/main/src/controllers/authController.js"
    click PassResetCtrl "https://github.com/relydda20/bulletinboardbackend/blob/main/src/controllers/passwordResetController.js"
    click PostCtrl "https://github.com/relydda20/bulletinboardbackend/blob/main/src/controllers/postController.js"
    click CommentCtrl "https://github.com/relydda20/bulletinboardbackend/blob/main/src/controllers/commentController.js"
    click UserCtrl "https://github.com/relydda20/bulletinboardbackend/blob/main/src/controllers/userController.js"
    click AuthMW "https://github.com/relydda20/bulletinboardbackend/blob/main/src/middleware/authMiddleware.js"
    click ValidateMW "https://github.com/relydda20/bulletinboardbackend/blob/main/src/middleware/validateMiddleware.js"
    click PostValMW "https://github.com/relydda20/bulletinboardbackend/blob/main/src/middleware/postValidation.js"
    click UserModel "https://github.com/relydda20/bulletinboardbackend/blob/main/src/models/User.js"
    click PostModel "https://github.com/relydda20/bulletinboardbackend/blob/main/src/models/Post.js"
    click CommentModel "https://github.com/relydda20/bulletinboardbackend/blob/main/src/models/Comment.js"
    click ShortId "https://github.com/relydda20/bulletinboardbackend/blob/main/src/models/types/shortid.js"
    click JWTUtils "https://github.com/relydda20/bulletinboardbackend/blob/main/src/utils/jwtUtils.js"
    click SendEmail "https://github.com/relydda20/bulletinboardbackend/blob/main/src/utils/sendEmail.js"
    click SeedScript "https://github.com/relydda20/bulletinboardbackend/blob/main/src/scripts/seed.js"
    click DBSeeder "https://github.com/relydda20/bulletinboardbackend/blob/main/src/seeders/databaseSeeder.js"
    click UserSeeder "https://github.com/relydda20/bulletinboardbackend/blob/main/src/seeders/userSeeder.js"
    click PostSeeder "https://github.com/relydda20/bulletinboardbackend/blob/main/src/seeders/postSeeder.js"
    click CommentSeeder "https://github.com/relydda20/bulletinboardbackend/blob/main/src/seeders/commentSeeder.js"

    classDef internal fill:#BBE1FA,stroke:#1E88E5,color:#000
    classDef database fill:#95E1D3,stroke:#2E7D32,color:#000
    classDef external fill:#FFC75F,stroke:#F57C00,color:#000
    classDef cli fill:#E0E0E0,stroke:#616161,color:#000
```
