# stepsisstuck/sp-y2-s2-sc-ca-project architecture

> Architecture diagram of the GitHub repository stepsisstuck/sp-y2-s2-sc-ca-project, 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/stepsisstuck/sp-y2-s2-sc-ca-project
- Repository: https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project

## Overview

##### Project Type and Purpose
- This is a full-stack web marketplace application (“SnapSell”) comprising:
- A static front-end (HTML/CSS) served by a Node.js server.
- A back-end REST API (Express) with JWT authentication, models for listings/offers/users/images/likes, and a relational database.
- CI workflow for CSV export and deployment via GitHub Actions.

##### File Structure Analysis
- Top-Level Directories:
- BackEnd/ – Express app:
– server.js (entry-point)
– controller/app.js (API routes)
– auth/verifyToken.js (JWT middleware)
– model/… (databaseConfig.js + ORM or query definitions for user, listing, offer, image, likes)
– public/… (static assets, seed SQL file)
– config.js (environment settings)
- FrontEnd/ – Static client:
– server.js (serves HTML/CSS)
– public/… (HTML pages, CSS styles)
- .github/workflows/CSV_Export.yml – CI job exporting data
- snapsell.sql & Set Up Instructions.txt – database schema + setup docs

##### Guidance
a. Main Components
1) Client Browser
2) Front-End Server (Node.js) – delivers static HTML/CSS/JS
3) Back-End Server (Express) – handles REST API endpoints, business logic, authentication
4) Authentication Layer – JWT verification middleware
5) Database (MySQL or PostgreSQL) – persistent storage for users, listings, offers, likes, images
6) Static Asset Store – local public folder for images and SQL seeds (could be S3 in production)
7) CI/CD Pipeline – GitHub Actions for CSV export and deployment
b. Relationships & Data Flow
- Browser → Front-End Server: HTTP GET to load pages (login, listings, view/edit pages)
- Browser → Back-End Server: AJAX/Fetch calls (login, CRUD listings/offers, profile updates)
- Back-End Server → Auth Layer: verifyToken.js validates incoming JWTs
- Back-End Server → Database: model/databaseConfig.js opens DB connection; models perform queries
- Back-End Server → Static Asset Store: serve or upload images via public/ folder
- CI Pipeline → Back-End Server & Database: runs CSV_Export workflow to dump data
c. Architectural Patterns & Principles
- MVC-style separation in BackEnd (controllers ↔ models ↔ config)
- RESTful API design for CRUD operations
- Stateless authentication with JWT tokens
- Clear separation of concerns: static client vs. dynamic API
d. Key Technologies
- Node.js & Express.js
- JWT (JSON Web Tokens) for auth
- Relational DB (MySQL/Postgres) via databaseConfig.js & snapsell.sql
- HTML/CSS (no SPA framework) for UI
- GitHub Actions for CI/CD

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Tier
    subgraph "Presentation Tier"
        Browser["Client Browser"]:::external
        FEserver["Front-End Server\n(Node.js)"]:::server
        StaticAssets["Static Assets\n(HTML/CSS)"]:::doc
    end

    %% Application Tier
    subgraph "Application Tier"
        subgraph BackEnd["Back-End Server"]
            ExpressServer["Express API Server"]:::server
            Auth["JWT Auth Middleware"]:::auth
            Controllers["API Routes\n(app.js)"]:::server
            subgraph "Models & Config"
                ConfigEnv["config.js"]:::server
                DBConn["databaseConfig.js"]:::server
                UserModel["user.js"]:::server
                ListingModel["listing.js"]:::server
                OfferModel["offer.js"]:::server
                ImagesModel["images.js"]:::server
                LikesModel["likes.js"]:::server
            end
        end
    end

    %% Data Tier
    subgraph "Data Tier"
        Database["Relational Database"]:::db
        AssetStore["Static Asset Store"]:::doc
        RootSchema["snapsell.sql"]:::doc
        SeedSQL["snapsell-1610007683525.sql"]:::doc
    end

    %% CI/CD Pipeline
    CI["CI/CD Pipeline\n(CSV Export)"]:::ci

    %% Relationships
    Browser -->|HTTP GET| FEserver
    FEserver -->|serves| StaticAssets
    Browser -->|AJAX/Fetch| ExpressServer
    FEserver -->|REST API calls| ExpressServer
    ExpressServer -->|uses| Controllers
    Controllers -->|calls| Auth
    Auth -->|validates JWT| ExpressServer
    ExpressServer -->|reads/writes| DBConn
    ExpressServer -->|reads/writes| AssetStore
    DBConn -->|connects to| Database
    ExpressServer -->|CRUD operations| UserModel
    ExpressServer -->|CRUD operations| ListingModel
    ExpressServer -->|CRUD operations| OfferModel
    ExpressServer -->|CRUD operations| ImagesModel
    ExpressServer -->|CRUD operations| LikesModel
    CI -.->|dumps data| Database
    CI -.->|runs workflow| ExpressServer

    %% Click Events
    click FEserver "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/FrontEnd/server.js"
    click StaticAssets "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/tree/main/FrontEnd/public/"
    click ExpressServer "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/server.js"
    click Controllers "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/controller/app.js"
    click Auth "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/auth/verifyToken.js"
    click ConfigEnv "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/config.js"
    click DBConn "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/model/databaseConfig.js"
    click UserModel "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/model/user.js"
    click ListingModel "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/model/listing.js"
    click OfferModel "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/model/offer.js"
    click ImagesModel "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/model/images.js"
    click LikesModel "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/model/likes.js"
    click AssetStore "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/tree/main/BackEnd/public/"
    click RootSchema "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/snapsell.sql"
    click SeedSQL "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/BackEnd/public/snapsell-1610007683525.sql"
    click CI "https://github.com/stepsisstuck/sp-y2-s2-sc-ca-project/blob/main/.github/workflows/CSV_Export.yml"

    %% Styles
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef external fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef doc fill:#FFFFE0,stroke:#333,stroke-width:1px;
    classDef auth fill:#FFD700,stroke:#333,stroke-width:1px;
    classDef db fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef ci fill:#D3D3D3,stroke:#333,stroke-width:1px;
```
