# ashutoshnegi880/role-based-access-control architecture

> Architecture diagram of the GitHub repository ashutoshnegi880/role-based-access-control, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashutoshnegi880/role-based-access-control
- Repository: https://github.com/ashutoshnegi880/role-based-access-control

## Overview

##### Project type and purpose
- This is a full-stack web application: a Role-Based Access Control (RBAC) Blog Platform.
- Purpose: allow users and admins to sign up, log in, view blogs; allow admins additionally to create and delete blogs.

##### File structure
- Top-level:
- app.js – the Express application entrypoint
- config/db.js – sets up the PostgreSQL connection
- controllers/ – definitions of request handlers (blogController.js, userController.js)
- services/ – business logic and data access abstractions (blogService.js, userService.js)
- routes/ – Express routers mapping URLs to controllers (blogRoutes.js, userRoutes.js, router.js)
- middleware/authMiddleware.js – JWT validation and role enforcement
- public/ – static frontend assets (HTML/CSS/JS for login, signup, blogs, admin)
- .env, package.json, etc. for configuration and dependencies
- Architecture implied:
- MVC-style layering (routes → controllers → services → database)
- Static asset delivery from the public folder
- Role-based JWT auth via middleware

##### README for additional insights
- Tech stack: Node.js + Express, PostgreSQL, JWT for auth, vanilla HTML/CSS/JS frontend
- Database schema: users and blogs tables, with foreign-key relationship on author_id
- Endpoints: /signup, /login, /blogs, /admin
- Dev workflow: npm scripts, .env for secrets, nodemon for hot reload

- Notes on middleware ordering: static → auth → routes → controllers → services → DB

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (Client)"
        direction TB
        Login["Login Page"]:::frontend
        Signup["Signup Page"]:::frontend
        BlogsList["Blogs List Page"]:::frontend
        AdminDash["Admin Dashboard Page"]:::frontend
        Styles["Shared Stylesheet"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express)"
        direction TB
        subgraph "Static File Server"
            StaticServ["Serve public assets"]:::static
        end
        subgraph "API Layer"
            direction TB
            App["Express App"]:::app
            RouterRoot["Root Router"]:::route
            AuthMid["Auth Middleware"]:::middleware
            UserRouter["User Routes"]:::route
            BlogRouter["Blog Routes"]:::route
            UserCtrl["User Controller"]:::controller
            BlogCtrl["Blog Controller"]:::controller
            UserSvc["User Service"]:::service
            BlogSvc["Blog Service"]:::service
            DBConn["DB Connector"]:::config
        end
    end

    %% Database and Config
    DB["PostgreSQL Database"]:::database
    Env["Environment Variables (.env)"]:::config
    Pkg["package.json"]:::config

    %% Frontend to Static
    Login -->|"GET HTML/CSS/JS"| StaticServ
    Signup -->|"GET HTML/CSS/JS"| StaticServ
    BlogsList -->|"GET HTML/CSS/JS"| StaticServ
    AdminDash -->|"GET HTML/CSS/JS"| StaticServ
    Styles --> StaticServ

    %% Frontend to API
    Login -->|"POST /login"| App
    Signup -->|"POST /signup"| App
    BlogsList -->|"GET /blogs"| App
    AdminDash -->|"GET /admin"| App

    %% API Flow
    App --> RouterRoot
    RouterRoot --> AuthMid
    AuthMid --> UserRouter
    AuthMid --> BlogRouter

    UserRouter --> UserCtrl
    BlogRouter --> BlogCtrl

    UserCtrl --> UserSvc
    BlogCtrl --> BlogSvc

    UserSvc --> DBConn
    BlogSvc --> DBConn

    DBConn --> DB

    %% Config injections
    Env --> App
    Env --> DBConn
    Pkg --> App

    %% Click Events
    click App "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/app.js"
    click DBConn "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/config/db.js"
    click AuthMid "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/middleware/authMiddleware.js"
    click UserCtrl "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/controllers/userController.js"
    click BlogCtrl "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/controllers/blogController.js"
    click UserSvc "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/services/userService.js"
    click BlogSvc "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/services/blogService.js"
    click BlogRouter "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/routes/blogRoutes.js"
    click UserRouter "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/routes/userRoutes.js"
    click RouterRoot "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/routes/router.js"
    click StaticServ "https://github.com/ashutoshnegi880/role-based-access-control/tree/master/public/"
    click Login "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/public/login.html"
    click Signup "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/public/signup.html"
    click BlogsList "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/public/blogs.html"
    click AdminDash "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/public/admin.html"
    click Styles "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/public/styles.css"
    click Env "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/.env"
    click Pkg "https://github.com/ashutoshnegi880/role-based-access-control/blob/master/package.json"

    %% Styles
    classDef frontend fill:#CCF,stroke:#339,stroke-width:1px
    classDef backend fill:#CFC,stroke:#393,stroke-width:1px
    classDef static fill:#EFF,stroke:#88,stroke-width:1px
    classDef app fill:#9F9,stroke:#393,stroke-width:1px
    classDef route fill:#FC9,stroke:#D60,stroke-width:1px
    classDef middleware fill:#F99,stroke:#933,stroke-width:1px
    classDef controller fill:#FDD,stroke:#D33,stroke-width:1px
    classDef service fill:#FFD,stroke:#996,stroke-width:1px
    classDef config fill:#DDD,stroke:#666,stroke-width:1px
    classDef database fill:#FFD,stroke:#F90,stroke-width:1px
```
