# creatoon/jar-web-app architecture

> Architecture diagram of the GitHub repository creatoon/jar-web-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/creatoon/jar-web-app
- Repository: https://github.com/creatoon/jar-web-app

## Overview

##### Main Components

a) Client-Side (Frontend):
- Views (Pug templates)
- Static assets (CSS, JavaScript)
- Client-side MVC architecture (models and views folders in public/js)

b) Server-Side (Backend):
- Express.js server
- Socket.io server
- MVC architecture components (controllers, models, routes)
- Authentication system

c) Database:
- MongoDB database (implied by the model structure)
- Collections for Users, Rooms, Messages, and Proposals

##### Component Relationships

- Client ↔ Server: HTTP/HTTPS connections (REST API)
- Client ↔ Server: WebSocket connection (Socket.io)
- Server ↔ Database: Mongoose ODM connection
- Authentication flow between components

##### Specific Implementation Details

a) API Layer:
- User routes
- Chat routes
- Room routes
- Proposal routes
- View routes

b) Real-time Communication:
- Socket.io server implementation
- Message handling
- Room management

##### Architectural Patterns to Highlight

- MVC Pattern (Both client and server-side)
- Factory Pattern (handlerFactory.js)
- Error Handling Middleware
- Authentication Middleware

##### Additional Elements

- Error handling flow
- File upload handling (for user images)
- Static file serving
- Security middleware
- Environment configuration

**[Client Layer]**
- ↕
**[API/Socket Layer]**
- ↕
**[Business Logic Layer]**
- ↕
**[Data Access Layer]**
- ↕
**[Database Layer]**

Key Guidelines:
##### Scaling points

Remember to:
- Keep the main flow clear and centered
- Related components visually
- Use appropriate spacing between components
- Version information and dependencies
- Document all external service integrations
- Deployment configuration (Dockerfile presence)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Views["Views (Pug)"]:::frontend
        StaticAssets["Static Assets"]:::frontend
        ClientModels["Client Models"]:::frontend
        ClientViews["Client Views"]:::frontend
        DevEntry["Development Entry"]:::frontend
        ProdBundle["Production Bundle"]:::frontend
    end

    subgraph API_Layer
        Express["Express Server"]:::backend
        SocketIO["Socket.IO Server"]:::backend
        
        subgraph Routes
            ChatRoutes["Chat Routes"]:::api
            RoomRoutes["Room Routes"]:::api
            UserRoutes["User Routes"]:::api
            ViewRoutes["View Routes"]:::api
            ProposalRoutes["Proposal Routes"]:::api
        end
    end

    subgraph Business_Logic
        subgraph Controllers
            AuthController["Auth Controller"]:::controller
            ErrorController["Error Controller"]:::controller
            MessageController["Message Controller"]:::controller
            RoomController["Room Controller"]:::controller
            UserController["User Controller"]:::controller
            ViewController["View Controller"]:::controller
            HandlerFactory["Handler Factory"]:::controller
        end

        subgraph Utils
            AppError["App Error"]:::util
            CatchAsync["Catch Async"]:::util
        end
    end

    subgraph Data_Layer
        UserModel["User Model"]:::model
        RoomModel["Room Model"]:::model
        MessageModel["Message Model"]:::model
        ProposalModel["Proposal Model"]:::model
    end

    subgraph Database
        MongoDB[(MongoDB)]:::database
    end

    %% Connections
    Client --> Express
    Client --> SocketIO
    Express --> Routes
    Routes --> Controllers
    Controllers --> Data_Layer
    Data_Layer --> MongoDB
    Utils --> Controllers

    %% Click Events
    click Views "https://github.com/creatoon/jar-web-app/tree/development/views/"
    click StaticAssets "https://github.com/creatoon/jar-web-app/tree/development/public/"
    click ClientModels "https://github.com/creatoon/jar-web-app/tree/development/public/js/models/"
    click ClientViews "https://github.com/creatoon/jar-web-app/tree/development/public/js/views/"
    click DevEntry "https://github.com/creatoon/jar-web-app/blob/development/public/js/development/index.js"
    click ProdBundle "https://github.com/creatoon/jar-web-app/blob/development/public/js/production/bundle.js"
    
    click Express "https://github.com/creatoon/jar-web-app/blob/development/app.js"
    click SocketIO "https://github.com/creatoon/jar-web-app/blob/development/socketServer.js"
    
    click ChatRoutes "https://github.com/creatoon/jar-web-app/blob/development/routes/chatRoute.js"
    click RoomRoutes "https://github.com/creatoon/jar-web-app/blob/development/routes/roomRoute.js"
    click UserRoutes "https://github.com/creatoon/jar-web-app/blob/development/routes/userRoute.js"
    click ViewRoutes "https://github.com/creatoon/jar-web-app/blob/development/routes/viewRoute.js"
    click ProposalRoutes "https://github.com/creatoon/jar-web-app/blob/development/routes/proposalRoute.js"
    
    click AuthController "https://github.com/creatoon/jar-web-app/blob/development/controllers/authController.js"
    click ErrorController "https://github.com/creatoon/jar-web-app/blob/development/controllers/errorController.js"
    click MessageController "https://github.com/creatoon/jar-web-app/blob/development/controllers/messageController.js"
    click RoomController "https://github.com/creatoon/jar-web-app/blob/development/controllers/roomController.js"
    click UserController "https://github.com/creatoon/jar-web-app/blob/development/controllers/userController.js"
    click ViewController "https://github.com/creatoon/jar-web-app/blob/development/controllers/viewController.js"
    click HandlerFactory "https://github.com/creatoon/jar-web-app/blob/development/controllers/handlerFactory.js"
    
    click UserModel "https://github.com/creatoon/jar-web-app/blob/development/models/userModel.js"
    click RoomModel "https://github.com/creatoon/jar-web-app/blob/development/models/roomModel.js"
    click MessageModel "https://github.com/creatoon/jar-web-app/blob/development/models/messageModel.js"
    click ProposalModel "https://github.com/creatoon/jar-web-app/blob/development/models/proposalModel.js"
    
    click AppError "https://github.com/creatoon/jar-web-app/blob/development/utils/appError.js"
    click CatchAsync "https://github.com/creatoon/jar-web-app/blob/development/utils/catchAsync.js"

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef api fill:#FF9800,color:white
    classDef controller fill:#9C27B0,color:white
    classDef model fill:#F44336,color:white
    classDef database fill:#FFC107,color:black
    classDef util fill:#607D8B,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        API["API Route"]:::api
        Controller["Controller"]:::controller
        Model["Model"]:::model
        DB["Database"]:::database
        Utility["Utility"]:::util
    end
```
