# bathlaneffi/codeial_new architecture

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

- Interactive diagram: https://gitdiagram.com/bathlaneffi/codeial_new
- Repository: https://github.com/bathlaneffi/codeial_new

## Overview

##### Project type and purpose
- From the file tree and README, this is a full-stack, monolithic web application (“Codeial_new”), built with Node.js and Express.
- It offers social-network-style features: user signup/sign-in (local, JWT, Google OAuth2), posting, commenting, likes, real-time chat, email notifications (comment alerts, password resets), plus a versioned JSON API (v1 & v2).

##### File structure
- Top-level “index.js” launches an Express server.
- config/ holds environment setup, DB connection (Mongoose), mailer (Nodemailer), Passport strategies (local, JWT, Google), socket config, Kue job-queue config, middleware, and view helpers.
- routes/ and controller/ implement an MVC pattern: HTTP routes → controller logic → Mongoose models → MongoDB.
- assets/ + gulpfile.js manage frontend assets (SCSS→CSS, JS bundling, cache-busting rev-manifests). Compiled assets live in public/assets/.
- views/ contains EJS templates, including partials (_header, _footer, _chat_box) and mailer templates.
- worker/ runs a separate Kue worker process to process email jobs.
- controller/api/v1 and v2 expose JSON APIs.
- uploads/ stores user avatars.

##### Additional insights from README
- Although minimal, the README confirms the web app’s URL and name.

a. Main components
- Web Client (Browser)
- Express Application Server
- Routing Layer
- Controllers (MVC)
- Models (Mongoose)
- Views (EJS)
- Asset Pipeline (Gulp + SCSS/JS)
- Database (MongoDB)
- Job Queue (Kue + Redis)
- Worker Process (comment_email_worker)
- Authentication Services (Passport Local/JWT/Google OAuth2)
- External Services
- SMTP Mail Server
- Google OAuth2 Gateway
- Real-Time Chat (Socket.io)
b. Relationships & interactions
- Browser ←→ HTTP(S) → Express Server (routes → controllers → render views or return JSON)
- Browser ←→ WebSocket → Express Server (chat_socket)
- Express → MongoDB via Mongoose models
- Controllers enqueue jobs into Kue (Redis) → Worker consumes jobs → sends email via SMTP
- Express uses Passport strategies for auth, contacting Google’s OAuth2 endpoint when needed
- Gulp builds assets; Express serves them from public/assets
- API clients consume versioned JSON endpoints (/api/v1, /api/v2)
c. Architectural patterns & design principles
- MVC pattern (models/controllers/views)
- Layered architecture: Presentation (views, assets), Application (controllers, services), Data (models, DB)
- API versioning (v1, v2) for backward compatibility
- Background processing via job queue (Kue + worker)
- Real-time pub/sub for chat (Socket.io)
- Authentication middleware pluggable via Passport strategies
- Asset pipeline for performance (fingerprinted CSS/JS)
d. Key technologies & frameworks
- Node.js, Express
- MongoDB, Mongoose
- Passport (local, JWT, Google OAuth2)
- Socket.io for chat
- Kue + Redis for job queuing
- Nodemailer for email
- Gulp, SCSS, ES6 JavaScript
- EJS templating
- Multer or direct filesystem for file uploads (avatars)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        Browser["Web Client (Browser)"]:::client
        Assets["Frontend Assets"]:::client
    end

    %% Server Layer
    subgraph "Server Layer"
        direction TB
        ExpressServer["Express Application Server"]:::server
        
        subgraph "Configuration Layer"
            direction TB
            Env["Environment & Globals"]:::server
            MongooseConfig["MongoDB Config"]:::server
            MailerConfig["Mailer Config"]:::server
            KueConfig["Job Queue Config"]:::server
            ChatConfig["Socket.io Config"]:::server
            PassportLocal["Passport Local Strategy"]:::server
            PassportJWT["Passport JWT Strategy"]:::server
            PassportGoogle["Passport Google OAuth2 Strategy"]:::server
            Middleware["Middleware Hooks"]:::server
            ViewHelpers["View Helpers"]:::server
        end

        subgraph "Routing Layer"
            direction TB
            HTMLRoutes["HTML Routes"]:::server
            APIRoutesV1["API Routes v1"]:::server
            APIRoutesV2["API Routes v2"]:::server
        end

        subgraph "Controller Layer"
            direction TB
            HTMLControllers["HTML Controllers"]:::server
            APIControllersV1["API Controllers v1"]:::server
            APIControllersV2["API Controllers v2"]:::server
        end

        subgraph "Model Layer"
            direction TB
            Models["Mongoose Models"]:::server
        end

        subgraph "View Layer"
            direction TB
            Views["EJS Templates"]:::server
            MailerTemplates["Mailer Templates"]:::server
        end

        AssetPipeline["Asset Pipeline (Gulp)"]:::server
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MongoDB["MongoDB"]:::datastore
        Redis["Redis (Kue Queue)"]:::datastore
    end

    %% Worker
    subgraph "Worker Process"
        direction TB
        EmailWorker["Comment Email Worker"]:::server
    end

    %% External Services
    subgraph "External Services"
        direction TB
        GoogleOAuth["Google OAuth2 Gateway"]:::external
        SMTP["SMTP Mail Server"]:::external
    end

    %% Connections
    Browser -->|"HTTP/HTTPS"| ExpressServer
    Browser ---|"WebSocket"| ChatConfig
    Browser -->|"Fetch Assets"| Assets
    Assets -->|Served by| AssetPipeline
    ExpressServer -->|Uses config| Env
    ExpressServer -->|Uses config| MongooseConfig
    ExpressServer -->|Uses config| MailerConfig
    ExpressServer -->|Uses config| KueConfig
    ExpressServer -->|Uses config| ChatConfig
    ExpressServer -->|Uses config| PassportLocal
    ExpressServer -->|Uses config| PassportJWT
    ExpressServer -->|Uses config| PassportGoogle
    ExpressServer -->|Uses config| Middleware
    ExpressServer -->|Uses config| ViewHelpers
    ExpressServer -->|Routes requests to| HTMLRoutes
    ExpressServer -->|Routes API calls to| APIRoutesV1
    ExpressServer -->|Routes API calls to| APIRoutesV2
    HTMLRoutes -->|Invoke| HTMLControllers
    APIRoutesV1 -->|Invoke| APIControllersV1
    APIRoutesV2 -->|Invoke| APIControllersV2
    HTMLControllers -->|CRUD| Models
    APIControllersV1 -->|CRUD| Models
    APIControllersV2 -->|CRUD| Models
    Models -->|Persist data to| MongoDB
    HTMLControllers -->|Render| Views
    HTMLControllers -->|Send emails via| MailerConfig
    HTMLControllers -.->|Enqueue jobs| Redis
    APIControllersV1 -.->|Enqueue jobs| Redis
    EmailWorker -->|Fetch jobs from| Redis
    EmailWorker -->|Send emails via| SMTP
    ExpressServer -.->|OAuth calls| GoogleOAuth

    %% Click Events
    click Browser "https://github.com/bathlaneffi/codeial_new/tree/master/assets/"
    click Assets "https://github.com/bathlaneffi/codeial_new/tree/master/assets/"
    click ExpressServer "https://github.com/bathlaneffi/codeial_new/blob/master/index.js"
    click Env "https://github.com/bathlaneffi/codeial_new/blob/master/config/environment.js"
    click MongooseConfig "https://github.com/bathlaneffi/codeial_new/blob/master/config/mongoose.js"
    click MailerConfig "https://github.com/bathlaneffi/codeial_new/blob/master/config/nodemailer.js"
    click KueConfig "https://github.com/bathlaneffi/codeial_new/blob/master/config/kue.js"
    click ChatConfig "https://github.com/bathlaneffi/codeial_new/blob/master/config/chat_socket.js"
    click PassportLocal "https://github.com/bathlaneffi/codeial_new/blob/master/config/passport-local-startegy.js"
    click PassportJWT "https://github.com/bathlaneffi/codeial_new/blob/master/config/passport-jwt-strategy.js"
    click PassportGoogle "https://github.com/bathlaneffi/codeial_new/blob/master/config/passport-google-oauth2-strategy.js"
    click Middleware "https://github.com/bathlaneffi/codeial_new/blob/master/config/middleware.js"
    click ViewHelpers "https://github.com/bathlaneffi/codeial_new/blob/master/config/view_helpers.js"
    click HTMLRoutes "https://github.com/bathlaneffi/codeial_new/blob/master/routes/index.js"
    click HTMLRoutes "https://github.com/bathlaneffi/codeial_new/blob/master/routes/users.js"
    click HTMLRoutes "https://github.com/bathlaneffi/codeial_new/blob/master/routes/posts.js"
    click HTMLRoutes "https://github.com/bathlaneffi/codeial_new/blob/master/routes/comments.js"
    click HTMLRoutes "https://github.com/bathlaneffi/codeial_new/blob/master/routes/likes.js"
    click APIRoutesV1 "https://github.com/bathlaneffi/codeial_new/blob/master/routes/api/v1/index.js"
    click APIRoutesV1 "https://github.com/bathlaneffi/codeial_new/blob/master/routes/api/v1/users.js"
    click APIRoutesV1 "https://github.com/bathlaneffi/codeial_new/blob/master/routes/api/v1/posts.js"
    click APIRoutesV2 "https://github.com/bathlaneffi/codeial_new/blob/master/routes/api/v2/index.js"
    click APIRoutesV2 "https://github.com/bathlaneffi/codeial_new/blob/master/routes/api/v2/posts.js"
    click HTMLControllers "https://github.com/bathlaneffi/codeial_new/blob/master/controller/home_controller.js"
    click HTMLControllers "https://github.com/bathlaneffi/codeial_new/blob/master/controller/users_controller.js"
    click HTMLControllers "https://github.com/bathlaneffi/codeial_new/blob/master/controller/post_controller.js"
    click HTMLControllers "https://github.com/bathlaneffi/codeial_new/blob/master/controller/comments_controller.js"
    click HTMLControllers "https://github.com/bathlaneffi/codeial_new/blob/master/controller/likes_controller.js"
    click APIControllersV1 "https://github.com/bathlaneffi/codeial_new/blob/master/controller/api/v1/users_api.js"
    click APIControllersV1 "https://github.com/bathlaneffi/codeial_new/blob/master/controller/api/v1/posts_api.js"
    click APIControllersV2 "https://github.com/bathlaneffi/codeial_new/blob/master/controller/api/v2/posts_api.js"
    click Models "https://github.com/bathlaneffi/codeial_new/blob/master/models/user.js"
    click Models "https://github.com/bathlaneffi/codeial_new/blob/master/models/post.js"
    click Models "https://github.com/bathlaneffi/codeial_new/blob/master/models/comment.js"
    click Models "https://github.com/bathlaneffi/codeial_new/blob/master/models/like.js"
    click Models "https://github.com/bathlaneffi/codeial_new/blob/master/models/resetPassword.js"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/layout.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/_header.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/_footer.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/_chat_box.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/_comment.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/_post.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/home.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/user_sign_in.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/user_sign_up.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/user_profile.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/user_forgot_password.ejs"
    click Views "https://github.com/bathlaneffi/codeial_new/blob/master/views/user_confirm_reset_password.ejs"
    click MailerTemplates "https://github.com/bathlaneffi/codeial_new/blob/master/views/mailers/comments/new_comment.ejs"
    click MailerTemplates "https://github.com/bathlaneffi/codeial_new/blob/master/views/mailers/resetUser/new_resetUser.ejs"
    click AssetPipeline "https://github.com/bathlaneffi/codeial_new/blob/master/gulpfile.js"
    click EmailWorker "https://github.com/bathlaneffi/codeial_new/blob/master/worker/comment_email_worker.js"

    %% Styles
    classDef client fill:#D6EAF8,stroke:#1B4F72,color:#154360
    classDef server fill:#D5F5E3,stroke:#196F3D,color:#145A32
    classDef datastore fill:#F9E79F,stroke:#B9770E,color:#7E5109
    classDef external fill:#E8DAEF,stroke:#6C3483,color:#512E5F
```
