Database & Storage Architecture

The data layer of Socon-MKT is designed with a strict separation between local development and production environments. This approach ensures that local development remains lightweight, fast, and easy to set up, while the production environment is robust, highly scalable, and secure.


Database Architecture

Socon-MKT relies on a relational database to manage critical platform data, including users, marketplace products, chat histories, and escrow transactions.

Development: SQLite3

For local development, the platform uses SQLite3.

  • Why: It requires zero external configuration, is supported natively by Python, and allows developers to get the project running instantly.
  • Location: The entire database is stored as a single local file (db.sqlite3) at the root of the project. This file is excluded from version control via .gitignore.

Production: PostgreSQL

In the live production environment, the platform switches to PostgreSQL.

  • Why: PostgreSQL handles concurrent connections effortlessly, ensures strict data integrity, and supports the complex, high-volume querying required by a social marketplace and active negotiation trackers.
  • Security: To prevent credential leaks, all database settings are injected dynamically using environment variables.

.env PostgreSQL Configuration

DB_ENGINE=django.db.backends.postgresql
DB_NAME=socon_mkt_prod
DB_USER=socon_admin
DB_PASSWORD=your_secure_password
DB_HOST=your_database_host_ip
DB_PORT=5432

File Storage Architecture

Socon-MKT handles two types of files:

  1. Static Files: CSS, JavaScript, fonts, and platform images needed for the site to function.
  2. Media Files: User-generated content, such as profile pictures (post_profile_pics/), post images, and product uploads.

Development Storage (Local File System)

When running locally (DEBUG = True), Django serves both static and media files directly from your computer's hard drive.

File Type Source Directory Root/Destination URL Path
Static Files statics/ staticfiles/ /static/
Media Files Stored directly in media/ media/ /media/

Production Storage (Cloudflare R2)

Serving static and media files directly from a Django application server in production is highly inefficient. For the live deployment, Socon-MKT offloads all file storage to Cloudflare R2.

  • Why Cloudflare R2? R2 is an S3-compatible object storage solution. It provides lightning-fast content delivery via Cloudflare's global CDN while avoiding the egregious egress fees typically associated with AWS S3.
  • How it works: When a user uploads a product image, Django processes the file and immediately pushes it to the R2 bucket. When users view the feed, their browsers fetch the images directly from Cloudflare, bypassing the Django server entirely.

Environment Data Flow

Below is a visual representation of how Django routes database queries and file requests based on the active environment.

graph TD A{"Active Environment"} A -->|"DEBUG = True (Local)"| B["Local Django Server"] B -->|"DB Queries"| C[("SQLite3 <br/> (db.sqlite3)")] B -->|"Static Files"| D["Local /staticfiles/"] B -->|"Media Uploads"| E["Local /media/"] A -->|"DEBUG = False (Production)"| F["Production Django Server"] F -->|"DB Queries"| G[("PostgreSQL <br/> (Managed DB)")] F -->|"Uploads & Collectstatic"| H[("Cloudflare R2 <br/> (Object Storage)")] H -->|"CDN Delivery"| I["End User Browser"]