# salint/social-media architecture

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

- Interactive diagram: https://gitdiagram.com/salint/social-media
- Repository: https://github.com/salint/social-media

## Overview

##### Project type and purpose
- This is a full-stack social media web application built with Node.js/Express and server-side rendering (EJS).
- The purpose is to allow users to sign up, log in, view profiles, create/edit posts, and manage sessions.

##### File structure
- Top-level files: package.json (Node dependencies), database.sql (schema), .env (config).
- src/ folder follows an MVC-style breakdown:
- controllers/ – request handlers (auth, user, post, root)
- services/ – business logic & external interactions (database, session, server, post, user)
- middleware/ – request pre-processing (auth)
- util/ – shared utilities (custom error class)
- main.js & index.js – app bootstrap and HTTP server startup
- static/ – public CSS assets
- views/ – EJS templates for each page (login, signup, profile, posts, 404, etc.)

##### README for additional insights
- Express.js server
- EJS for server-side HTML rendering
- SQL (via database.sql) as the data store
- Session management (likely via cookies)

a. Main components
1) Client (Browser + static assets + rendered EJS pages)
2) Web Server (Express app)
3) Controllers (auth, user, post, root)
4) Services (database, session, user, post, server)
5) Database (SQL)
6) Middleware (auth)
7) Util layer (ErrorEx)
b. Relationships & interactions
- Browser sends HTTP requests → Express Server
- Server applies auth.middleware → routes to appropriate controller
- Controller invokes service(s) for business logic
- Service uses database.service or session.service to read/write data
- Controller renders a view via EJS or redirects/responses
- Response returns HTML/CSS for the Browser
c. Architectural patterns & principles
- MVC-style separation:
- Model = database + database.service
- View = EJS templates + static assets
- Controller = controllers folder
- Service layer abstracts data and session logic
- Middleware handles cross-cutting concerns (authentication)
- Single monolithic codebase
d. Key technologies/frameworks
- Node.js & Express.js (server)
- EJS (templating engine)
- SQL database (schema in database.sql)
- Session handling (session.service + cookies)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client/UI Layer
    subgraph "Client / UI"
        direction TB
        Browser["Web Browser"]:::blue
        StaticAssets["Static Assets"]:::blue
        Views["EJS Views"]:::blue
    end

    Browser -->|requests assets| StaticAssets
    Browser -->|requests pages| Views
    Browser -->|HTTP Request| ExpressConfig

    %% Server Side
    subgraph "Server (Node.js / Express.js)"
        direction TB

        MainJS["main.js (App Bootstrap)"]:::green
        ExpressConfig["index.js (Express Config)"]:::green

        MainJS --> ExpressConfig
        ExpressConfig --> AuthMiddleware

        AuthMiddleware["Auth Middleware"]:::green

        subgraph "Controllers"
            direction TB
            AuthController["auth.controller"]:::green
            UserController["user.controller"]:::green
            PostController["post.controller"]:::green
            RootController["root.controller"]:::green
        end

        AuthMiddleware --> AuthController
        ExpressConfig --> UserController
        ExpressConfig --> PostController
        ExpressConfig --> RootController

        subgraph "Services"
            direction TB
            UserService["user.service"]:::orange
            PostService["post.service"]:::orange
            SessionService["session.service"]:::orange
            ServerService["server.service"]:::orange
            DatabaseService["database.service"]:::orange
        end

        AuthController --> SessionService
        UserController --> UserService
        PostController --> PostService
        RootController --> ServerService

        UserService --> DatabaseService
        PostService --> DatabaseService
        SessionService --> DatabaseService

        subgraph "Utilities"
            direction TB
            ErrorEx["ErrorEx (Custom Error)"]:::orange
        end

        AuthController --> ErrorEx
        UserController --> ErrorEx
        PostController --> ErrorEx
        SessionService --> ErrorEx
        ServerService --> ErrorEx
    end

    %% Database Layer
    Database["SQL Database"]:::grey

    DatabaseService --> Database

    %% Click Events
    click StaticAssets "https://github.com/salint/social-media/tree/main/static/"
    click Views "https://github.com/salint/social-media/tree/main/views/"
    click MainJS "https://github.com/salint/social-media/blob/main/src/main.js"
    click ExpressConfig "https://github.com/salint/social-media/blob/main/src/index.js"
    click AuthMiddleware "https://github.com/salint/social-media/blob/main/src/middleware/auth.middleware.js"
    click AuthController "https://github.com/salint/social-media/blob/main/src/controllers/auth.controller.js"
    click UserController "https://github.com/salint/social-media/blob/main/src/controllers/user.controller.js"
    click PostController "https://github.com/salint/social-media/blob/main/src/controllers/post.controller.js"
    click RootController "https://github.com/salint/social-media/blob/main/src/controllers/root.controller.js"
    click DatabaseService "https://github.com/salint/social-media/blob/main/src/services/database.service.js"
    click UserService "https://github.com/salint/social-media/blob/main/src/services/user.service.js"
    click PostService "https://github.com/salint/social-media/blob/main/src/services/post.service.js"
    click SessionService "https://github.com/salint/social-media/blob/main/src/services/session.service.js"
    click ServerService "https://github.com/salint/social-media/blob/main/src/services/server.service.js"
    click ErrorEx "https://github.com/salint/social-media/blob/main/src/util/ErrorEx.js"
    click Database "https://github.com/salint/social-media/blob/main/database.sql"

    %% Styles
    classDef blue fill:#add8e6,stroke:#333,stroke-width:1px
    classDef green fill:#98fb98,stroke:#333,stroke-width:1px
    classDef orange fill:#ffdead,stroke:#333,stroke-width:1px
    classDef grey fill:#d3d3d3,stroke:#333,stroke-width:1px
```
