# diya050/resale_x architecture

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

- Interactive diagram: https://gitdiagram.com/diya050/resale_x
- Repository: https://github.com/diya050/resale_x

## Overview

##### Project type and purpose
- This is a full-stack web application (“ResaleX”) built with Django (Python) on the back end, Bootstrap/HTML/CSS/JS on the front end, and an integrated machine-learning model (XGBoost) for resale-price prediction. It functions as a marketplace for pre-owned cars, with user authentication, listing management, search filters, and email notifications.

##### File structure
- Top level:
- Procfile, runtime.txt – Heroku deployment
- requirements.txt – Python dependencies
- previews/ – screenshot assets
- src/ – application source
- Inside src/:
- resale_x/ – Django project settings, ASGI/WSGI, URL routing
- main/ – “main” app (listings, filters, forms, ML)
- users/ – “users” app (registration, login, profile)
- media/ – uploaded listing images
- db.sqlite3 – development database
- manage.py – Django CLI entry point
- “main/ml/” holds serialized artifacts: best_xgb.model, scaler.pkl, mappings, etc.

##### README
- Confirms tech stack: Django, Bootstrap, XGBoost
- Describes key features: authentication, listings CRUD, price prediction, dynamic filters, email notifications
- Notes deployment targets (PostgreSQL in prod, SQLite for dev) and standard Django setup steps.

##### Main components
a. Client (Browser/Mobile)
- Renders HTML templates, CSS, JS; interacts via HTTP/AJAX
b. Web Server / Load Balancer (e.g., Heroku Dyno + Gunicorn)
- Receives HTTP requests, forwards to Django
c. Django Application
- Project layer (resale_x)
- Apps:
- Users App: authentication, profiles
- Main App: listings, search filters, CRUD, price-prediction API
- ML Module: loads XGBoost artifacts, runs inference
d. Database
- PostgreSQL (prod) / SQLite (dev) storing users, listings, likes, migrations
e. Media Storage
- Local filesystem or cloud storage (S3, etc.) for uploaded images
f. External Services
- Email SMTP service for notifications
g. Static File Server / CDN
- Serves CSS/JS/assets (Bootstrap, custom styles)

##### Relationships and interactions
- Client → Web Server: HTTP GET/POST for pages, AJAX calls for “Predict My Car Price”
- Web Server → Django Views:
- Users URLs → Users Views (login, register, profile)
- Main URLs → Main Views (list, detail, create, edit, AJAX-predict endpoint)
- Django Views → ML Module: load model artifacts, run prediction
- Django Views → Database: read/write models (User, Profile, Listing, Likes)
- Django Views → Email Service: send contact emails
- Django Static/Media Handling → Static File Server / Media Storage
- Web Server ↔ CDN: serve static assets efficiently

##### Architectural patterns and design principles
- MVC (MVT) pattern inherent to Django: Models (models.py), Views (views.py), Templates (templates/), Forms, Filters
- Separation of concerns:
- Authentication logic in users app
- Business logic + ML in main app
- Externalized ML artifacts: single responsibility for prediction
- Standard 3-tier segmentation: Presentation (browser), Application (Django), Data (DB & media)

##### Detail without overthinking
- Every app (users, main, resale_x), the ML artifacts directory, media folder, static assets, and deployment config (Procfile).
- How the price-prediction endpoint fits into the CRUD flow.
- Real file-tree modules: migrations, utils, forms, filters, templates, static/js/css.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser/Mobile)" 
        direction TB
        ClientTemplates["Templates"]:::frontend
        ClientStatic["Static Assets"]:::frontend
    end

    %% Web Server Layer
    subgraph "Web Server / Load Balancer" 
        direction TB
        ProcfileNode["Procfile"]:::backend
        RuntimeNode["runtime.txt"]:::backend
        Gunicorn["Gunicorn"]:::backend
    end

    %% Django Application Layer
    subgraph "Django Application" 
        direction TB
        subgraph "Project Layer (resale_x)"
            direction TB
            Settings["settings.py"]:::backend
            URLs["urls.py"]:::backend
            ASGI["asgi.py"]:::backend
            WSGI["wsgi.py"]:::backend
            Manage["manage.py"]:::backend
        end

        subgraph "Users App"
            direction TB
            UsersDir["users/"]:::backend
            UsersURLs["urls.py"]:::backend
            UsersViews["views.py"]:::backend
            UsersForms["forms.py"]:::backend
            UsersModels["models.py"]:::backend
            UsersSignals["signals.py"]:::backend
            UsersTemplates["templates/ (login, register, profile)"]:::frontend
        end

        subgraph "Main App"
            direction TB
            MainDir["main/"]:::backend
            MainURLs["urls.py"]:::backend
            MainViews["views.py"]:::backend
            MainModels["models.py"]:::backend
            MainForms["forms.py"]:::backend
            MainFilters["filters.py"]:::backend
            MainUtils["utils.py"]:::backend
            MainAdmin["admin.py"]:::backend
            MainTests["tests.py"]:::backend
            MainTemplates["templates/ (base, components, views)"]:::frontend
        end

        subgraph "ML Inference Module"
            direction TB
            MLDir["ml/"]:::backend
        end
    end

    %% Data and External
    Database["PostgreSQL / SQLite"]:::data
    MigrationsMain["main migrations/"]:::data
    MigrationsUsers["users migrations/"]:::data
    DevDB["db.sqlite3"]:::data

    MediaStorage["Media Storage\n(src/media/)"]:::data
    CDN["Static File Server / CDN"]:::external
    SMTP["SMTP Email Service"]:::external

    %% Connections
    ClientTemplates -->|renders views| ClientStatic
    ClientTemplates -->|HTTP/HTTPS| ProcfileNode
    ClientStatic -->|fetch static| CDN

    ProcfileNode -->|starts| Gunicorn
    RuntimeNode -->|runtime config| Gunicorn
    Gunicorn -->|forwards requests| Settings

    Settings --> UsersURLs
    Settings --> MainURLs

    UsersURLs --> UsersViews
    MainURLs --> MainViews

    UsersViews --> UsersModels
    UsersViews --> UsersForms
    UsersViews --> UsersTemplates
    UsersViews --> SMTP

    MainViews --> MainModels
    MainViews --> MainForms
    MainViews --> MainFilters
    MainViews --> MainUtils
    MainViews --> MainTemplates
    MainViews --> MLDir
    MainViews --> Database
    MainViews --> SMTP

    MLDir -->|loads artifacts| MainUtils

    Database --> MigrationsMain
    Database --> MigrationsUsers
    Database --> DevDB

    Gunicorn -->|serves media| MediaStorage
    Gunicorn -->|serves static| CDN

    %% Click Events
    click ClientTemplates "https://github.com/diya050/resale_x/tree/main/src/main/templates/"
    click ClientStatic "https://github.com/diya050/resale_x/tree/main/src/main/static/"
    click ProcfileNode "https://github.com/diya050/resale_x/tree/main/Procfile"
    click RuntimeNode "https://github.com/diya050/resale_x/blob/main/runtime.txt"
    click Settings "https://github.com/diya050/resale_x/blob/main/src/resale_x/settings.py"
    click URLs "https://github.com/diya050/resale_x/blob/main/src/resale_x/urls.py"
    click ASGI "https://github.com/diya050/resale_x/blob/main/src/resale_x/asgi.py"
    click WSGI "https://github.com/diya050/resale_x/blob/main/src/resale_x/wsgi.py"
    click Manage "https://github.com/diya050/resale_x/blob/main/src/manage.py"
    click UsersDir "https://github.com/diya050/resale_x/tree/main/src/users/"
    click UsersURLs "https://github.com/diya050/resale_x/blob/main/src/users/urls.py"
    click UsersViews "https://github.com/diya050/resale_x/blob/main/src/users/views.py"
    click UsersForms "https://github.com/diya050/resale_x/blob/main/src/users/forms.py"
    click UsersModels "https://github.com/diya050/resale_x/blob/main/src/users/models.py"
    click UsersSignals "https://github.com/diya050/resale_x/blob/main/src/users/signals.py"
    click UsersTemplates "https://github.com/diya050/resale_x/tree/main/src/users/templates/views/"
    click MainDir "https://github.com/diya050/resale_x/tree/main/src/main/"
    click MainURLs "https://github.com/diya050/resale_x/blob/main/src/main/urls.py"
    click MainViews "https://github.com/diya050/resale_x/blob/main/src/main/views.py"
    click MainModels "https://github.com/diya050/resale_x/blob/main/src/main/models.py"
    click MainForms "https://github.com/diya050/resale_x/blob/main/src/main/forms.py"
    click MainFilters "https://github.com/diya050/resale_x/blob/main/src/main/filters.py"
    click MainUtils "https://github.com/diya050/resale_x/blob/main/src/main/utils.py"
    click MainAdmin "https://github.com/diya050/resale_x/blob/main/src/main/admin.py"
    click MainTests "https://github.com/diya050/resale_x/blob/main/src/main/tests.py"
    click MainTemplates "https://github.com/diya050/resale_x/tree/main/src/main/templates/"
    click MLDir "https://github.com/diya050/resale_x/tree/main/src/main/ml/"
    click MigrationsMain "https://github.com/diya050/resale_x/tree/main/src/main/migrations/"
    click MigrationsUsers "https://github.com/diya050/resale_x/tree/main/src/users/migrations/"
    click DevDB "https://github.com/diya050/resale_x/blob/main/src/db.sqlite3"
    click MediaStorage "https://github.com/diya050/resale_x/tree/main/src/media/"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef backend fill:#C8E6C9,stroke:#388E3C,color:#000
    classDef data fill:#FFE0B2,stroke:#EF6C00,color:#000
    classDef external fill:#E1BEE7,stroke:#8E24AA,color:#000
```
