# mugilan-codes/dev-book architecture

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

- Interactive diagram: https://gitdiagram.com/mugilan-codes/dev-book
- Repository: https://github.com/mugilan-codes/dev-book

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node) web application called “DevBook.”
- Purpose: a developer social network where users can register/login, create profiles (with education, experience, GitHub integration), make posts, comment, and view other profiles.

##### File structure
Top-level:
- client/ – React single-page app (SPA) with Redux for state management
- server.js, config/, models/, routes/, middleware/ – Node/Express REST API
- _resources/ – legacy/static HTML/CSS theme (optional)
- package.json, package-lock.json – root dependencies
Inside client/:
- public/ – static HTML shell (index.html, manifest.json)
- src/ – React code
– actions/, reducers/, store.js – Redux
– components/ – UI broken down by feature (auth, dashboard, posts, profiles, layout)
– utils/api.js – HTTP client wrapper
– utils/setAuthToken.js – attach JWT to requests
– App.js, index.js – entry points
Inside server:
- config/db.js – MongoDB connection
- middleware/auth.js – JWT verification
- models/ – Mongoose schemas (User, Profile, Post)
- routes/api/ – Express routers (auth, users, profile, posts)

##### Extract insights from the README
- Tech stack: MongoDB, ExpressJS, ReactJS, NodeJS
- Planned features (GitHub repos integration, logging)

##### Components
a. Frontend (React SPA)
– Redux store
– UI components grouped by feature (Auth, Dashboard, Profile, Posts)
– HTTP Client (utils/api.js)
b. Backend (Node/Express API)
– API Gateway (server.js → routes)
– Controllers (inside routes handlers)
– Authentication middleware (JWT in auth.js)
– Business logic interacting with Mongoose models
c. Database
– MongoDB cluster or instance
– Collections: users, profiles, posts
d. External Services
– GitHub REST API calls (ProfileGithub component → fetch repos)
– (Optional) any logging/analytics service
e. Static assets
– client/public
– _resources/html_css_theme (if used in fallback or theming)

##### Relationships and interactions
1. User interacts with React UI
2. React dispatches Redux actions → utils/api.js makes HTTP requests
3. Express routes receive requests → auth middleware validates JWT
4. Route handlers call Mongoose models → read/write MongoDB
5. Response flows back to React → Redux updates store → UI re-renders
6. ProfileGithub component triggers external GitHub API calls (server-side or client-side)
7. Errors pass through alert handling (Redux alerts)

##### Architectural patterns & design principles
- Layered architecture: UI → application (Redux) → API (Express) → persistence (MongoDB)
- MVC-style on the server: Routes = controllers, Models = Mongoose schemas
- Flux pattern on the client: Redux actions, reducers, store
- JWT-based stateless authentication
- Separation of concerns: components by feature, utils for shared logic

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Client (Browser)"
    direction TB
    Index["index.js"]:::frontend
    App["App.js"]:::frontend
    Store["Redux Store\nstore.js"]:::frontend
    APIUtil["HTTP Client\napi.js"]:::frontend
    AuthUtil["JWT Helper\nsetAuthToken.js"]:::frontend
    subgraph "Components"
      direction TB
      AuthComp["Auth Components"]:::frontend
      DashComp["Dashboard Components"]:::frontend
      ProfileComp["Profile Components"]:::frontend
      ProfileFormComp["Profile Form Components"]:::frontend
      PostsComp["Posts Components"]:::frontend
      SinglePostComp["Single Post Components"]:::frontend
      LayoutComp["Layout Components"]:::frontend
      PrivateRoute["PrivateRoute"]:::frontend
    end
    PublicAssets["Public Assets\npublic/"]:::static
  end

  subgraph "Server"
    direction TB
    ServerEntry["server.js"]:::backend
    DBConfig["db.js"]:::backend
    AuthMiddleware["auth.js\nMiddleware"]:::backend
    subgraph "Models"
      direction TB
      UserModel["User Model"]:::database
      ProfileModel["Profile Model"]:::database
      PostModel["Post Model"]:::database
    end
    subgraph "API Routes"
      direction TB
      AuthRoute["routes/api/auth.js"]:::backend
      UsersRoute["routes/api/users.js"]:::backend
      ProfileRoute["routes/api/profile.js"]:::backend
      PostsRoute["routes/api/posts.js"]:::backend
    end
  end

  Mongo["MongoDB"]:::database
  GitHub["GitHub REST API"]:::external
  StaticTheme["Legacy Theme\n_resources/html_css_theme"]:::static

  Index --> App
  App --> Store
  App --> APIUtil
  App --> AuthUtil
  App --> AuthComp
  App --> DashComp
  App --> ProfileComp
  App --> PostsComp
  AuthComp --> Store
  DashComp --> Store
  ProfileComp --> Store
  ProfileComp --> GitHub
  ProfileFormComp --> Store
  PostsComp --> Store
  SinglePostComp --> Store
  LayoutComp --> Store
  PrivateRoute --> Store

  APIUtil --> ServerEntry
  ServerEntry --> AuthMiddleware
  AuthMiddleware --> AuthRoute
  ServerEntry --> UsersRoute
  ServerEntry --> ProfileRoute
  ServerEntry --> PostsRoute
  AuthRoute --> UserModel
  UsersRoute --> UserModel
  ProfileRoute --> ProfileModel
  ProfileRoute --> GitHub
  PostsRoute --> PostModel
  AuthRoute --> Mongo
  UsersRoute --> Mongo
  ProfileRoute --> Mongo
  PostsRoute --> Mongo

  ServerEntry --> DBConfig
  DBConfig --> Mongo

  StaticTheme --> App

  click Index "https://github.com/mugilan-codes/dev-book/blob/master/client/src/index.js"
  click App "https://github.com/mugilan-codes/dev-book/blob/master/client/src/App.js"
  click Store "https://github.com/mugilan-codes/dev-book/blob/master/client/src/store.js"
  click APIUtil "https://github.com/mugilan-codes/dev-book/blob/master/client/src/utils/api.js"
  click AuthUtil "https://github.com/mugilan-codes/dev-book/blob/master/client/src/utils/setAuthToken.js"
  click AuthComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/auth"
  click DashComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/dashboard"
  click ProfileComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/profile"
  click ProfileFormComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/profile-form"
  click PostsComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/posts"
  click SinglePostComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/post"
  click LayoutComp "https://github.com/mugilan-codes/dev-book/tree/master/client/src/components/layout"
  click PrivateRoute "https://github.com/mugilan-codes/dev-book/blob/master/client/src/components/routing/PrivateRoute.js"
  click PublicAssets "https://github.com/mugilan-codes/dev-book/tree/master/client/public"
  click ServerEntry "https://github.com/mugilan-codes/dev-book/blob/master/server.js"
  click DBConfig "https://github.com/mugilan-codes/dev-book/blob/master/config/db.js"
  click AuthMiddleware "https://github.com/mugilan-codes/dev-book/blob/master/middleware/auth.js"
  click UserModel "https://github.com/mugilan-codes/dev-book/blob/master/models/User.js"
  click ProfileModel "https://github.com/mugilan-codes/dev-book/blob/master/models/Profile.js"
  click PostModel "https://github.com/mugilan-codes/dev-book/blob/master/models/Post.js"
  click AuthRoute "https://github.com/mugilan-codes/dev-book/blob/master/routes/api/auth.js"
  click UsersRoute "https://github.com/mugilan-codes/dev-book/blob/master/routes/api/users.js"
  click ProfileRoute "https://github.com/mugilan-codes/dev-book/blob/master/routes/api/profile.js"
  click PostsRoute "https://github.com/mugilan-codes/dev-book/blob/master/routes/api/posts.js"
  click StaticTheme "https://github.com/mugilan-codes/dev-book/tree/master/_resources/html_css_theme"

  classDef frontend fill:#e0ffe0,stroke:#006600
  classDef backend fill:#e0f0ff,stroke:#0066cc
  classDef database fill:#fff0e0,stroke:#cc6600
  classDef external fill:#f0e0ff,stroke:#6600cc
  classDef static fill:#f0f0f0,stroke:#888888
```
