This repository follows a documentation-first development process.

If implementation conflicts with the approved documentation, DO NOT modify the documented architecture, database design, business rules, or project structure. Instead, ask for clarification before making changes.

# Student Bazaar

## Project Overview

Student Bazaar is a student marketplace platform built using Flask.

The platform allows students to buy and sell second-hand items within their campus community.

Student Bazaar does **not** process payments. Buyers and sellers communicate through the platform, negotiate prices, arrange meet-ups, and complete transactions independently.

This project follows a documentation-first development approach. All implementation must conform to the approved documentation located in the `/docs` directory.

---

# Technology Stack

Backend

* Python 3.x
* Flask
* Flask-SQLAlchemy
* Flask-Migrate
* Flask-WTF
* Flask-Login
* Flask-Mail

Database

* MySQL

Frontend

* HTML5
* CSS3
* Bootstrap 5
* JavaScript (ES6)

Development Tools

* VS Code
* Claude Code
* Git
* MySQL Workbench

---

# Project Architecture

The project follows:

* Flask Application Factory Pattern
* Modular Architecture
* Service Layer Pattern
* SQLAlchemy ORM
* Blueprint-based Routing
* MVC-inspired structure

---

# Folder Structure

The project structure is:

```text
Student Bazaar/

app/
    auth/
    marketplace/
    negotiation/
    chat/
    meetup/
    notifications/
    admin/

    models/
    services/
    forms/
    utils/
    templates/
    static/

    config.py
    extensions.py

docs/

migrations/

tests/

uploads/

app.py

requirements.txt

CLAUDE.md
```

---

# Documentation

Before implementing any feature, always review the relevant documentation.

Documentation is located inside:

```
docs/
```

The following documents define the project architecture:

Project

* Vision
* Scope
* Software Requirements Specification
* User Stories

Architecture

* System Architecture
* Database Design
* Entity Model
* Database Relationships
* ER Diagram
* Security Design
* API Design
* Folder Structure
* Coding Standards

Development

* Development Roadmap
* Deployment Guide
* Testing Strategy

These documents are the single source of truth.

Do not contradict them.

---

# Database

The database architecture has already been approved.

Implementation must follow:

* SQLAlchemy ORM
* Flask-Migrate
* MySQL

Current database:

18 tables

Do not modify the schema without approval.

---

# Business Rules

Always preserve these rules.

Student Accounts

* One account can both buy and sell.

Marketplace

* Listings require between 1 and 7 images.
* Listings support draft mode.
* Listings expire automatically.
* Listings use soft deletion where applicable.

Negotiation

* Price negotiation is performed using offers and counter-offers.
* Offer history must never be deleted.

Chat

* Communication occurs only through the built-in chat.
* Each participant has an independent free 10-message limit per conversation, counted from their first message.
* Watching one rewarded advertisement unlocks 5 additional messages.
* Premium users have unlimited messaging.
* Personal contact information must not be shared before an offer is accepted.

Meet-up

* Meet-ups can only be scheduled after an offer has been accepted.
* Listings become Sold only after both participants confirm completion.

Payments

* Student Bazaar does not process payments.
* The platform is not responsible for transactions between students.

---

# Coding Rules

All generated code must follow:

* PEP 8
* Flask best practices
* SQLAlchemy best practices
* Bootstrap 5 conventions
* Modular architecture

Never generate unnecessary complexity.

Keep code readable.

Keep functions focused.

Avoid duplicated logic.

---

# Security Rules

Always implement:

* Password hashing
* CSRF protection
* Input validation
* Authorization checks
* Authentication checks
* SQL injection prevention
* XSS prevention
* Secure file uploads
* Secure session management

Never trust client input.

Always validate on the server.

---

# Development Workflow

Always work module by module.

Recommended order:

1. Project Setup
2. Database Models
3. Authentication
4. Marketplace
5. Negotiation
6. Chat
7. Meet-up
8. Notifications
9. Administration
10. Testing
11. Deployment

Do not skip phases.

---

# Code Generation Rules

When generating code:

* Follow the existing project structure.
* Reuse existing code whenever possible.
* Avoid duplicate implementations.
* Do not change database tables without approval.
* Do not rename approved entities.
* Do not change business rules.
* Generate production-quality code.
* Include comments only where they improve understanding.
* Prefer maintainability over cleverness.

---

# Error Handling

Use Flask error handlers.

Return user-friendly error messages.

Log unexpected exceptions.

Do not expose sensitive system information.

---

# Testing

Every implemented feature should be testable.

Generate tests where appropriate.

Verify:

* Business rules
* Database operations
* Authentication
* Permissions
* Input validation

---

# Before Writing Code

Before implementing a feature:

1. Read the relevant documentation.
2. Review the related database schema.
3. Check existing code for reuse.
4. Preserve project architecture.
5. Implement incrementally.
6. Explain major design decisions when introducing new components.

---

# Important Instructions

Do not introduce unnecessary libraries.

Do not replace Flask with another framework.

Do not modify approved documentation unless explicitly requested.

Do not change the database architecture without approval.

Do not introduce breaking changes.

Always preserve compatibility with the existing project structure.

Prioritize:

* Maintainability
* Readability
* Security
* Scalability
* Consistency

over writing the shortest possible code.

---

# Documentation Priority

When implementing features, use the following priority order:

1. CLAUDE.md
2. docs/01_Project/
3. docs/02_Architecture/
4. docs/03_Modules/
5. docs/04_Development/

If there is any conflict between implementation and documentation, the documentation takes precedence until explicitly updated.