- Introduction
- System Architecture
- Technical Components
- Database Design
- API Documentation
- Setup and Deployment
- Security Features
- Testing Strategy
- Troubleshooting Guide
- Development Guidelines
- Project Setup and Deployment Guide
ShopEasy is a modern e-commerce application built using a three-tier architecture. It provides essential e-commerce functionalities including user authentication, product browsing, cart management, and order processing.
- User Authentication (Login/Signup)
- Product Catalog
- Shopping Cart Management
- Order Processing
- Session Management
- Responsive Design
- Frontend: HTML5, CSS3, JavaScript
- Backend: Python, Flask Framework
- Database: MySQL 8.0
- Containerization: Docker, Docker Compose
graph TB
subgraph "Frontend Layer"
UI[HTML/CSS/JavaScript]
end
subgraph "Application Layer"
BE[Flask Backend]
Auth[Authentication]
Cart[Cart Management]
Orders[Order Processing]
end
subgraph "Data Layer"
DB[(MySQL Database)]
end
UI --> BE
BE --> Auth
BE --> Cart
BE --> Orders
Auth --> DB
Cart --> DB
Orders --> DB
graph LR
A[Frontend Pages] --> B[index.html]
A --> C[catalog.html]
A --> D[cart.html]
A --> E[login.html]
A --> F[signup.html]
A --> G[order-success.html]
graph TB
A[app.py] --> B[auth_routes.py]
A --> C[product_routes.py]
A --> D[cart_routes.py]
A --> E[order_routes.py]
B --> F[Authentication Logic]
C --> G[Product Management]
D --> H[Cart Operations]
E --> I[Order Processing]
frontend/
├── index.html # Home page
├── catalog.html # Product listing
├── cart.html # Shopping cart
├── login.html # User login
├── signup.html # User registration
├── order-success.html # Order confirmation
└── styles.css # Global styles
backend/
├── app.py # Application entry point
├── routes/ # API route handlers
│ ├── auth_routes.py
│ ├── cart_routes.py
│ ├── order_routes.py
│ └── product_routes.py
├── models/ # Data models
│ ├── user.py
│ ├── product.py
│ └── order.py
├── database/ # Database scripts
│ ├── 01_schema.sql
│ └── 02_data.sql
└── Dockerfile.backend
erDiagram
users ||--o{ cart_items : has
users ||--o{ orders : places
products ||--o{ cart_items : contains
products ||--o{ order_items : includes
orders ||--|{ order_items : contains
-- Users Table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Products Table
CREATE TABLE products (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
price DECIMAL(10,2) NOT NULL,
description TEXT
);
-- Cart Items Table
CREATE TABLE cart_items (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL DEFAULT 1,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);
-- Orders Table
CREATE TABLE orders (
id INT PRIMARY KEY AUTO_INCREMENT,
user_id INT NOT NULL,
total_amount DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- Order Items Table
CREATE TABLE order_items (
id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT NOT NULL,
product_id INT NOT NULL,
quantity INT NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(id),
FOREIGN KEY (product_id) REFERENCES products(id)
);- URL:
/api/auth/login - Method:
POST - Body:
{
"username": "string",
"password": "string"
}- Response:
{
"message": "Login successful",
"user": {
"user_id": "integer",
"username": "string"
}
}- URL:
/api/auth/signup - Method:
POST - Body:
{
"username": "string",
"password": "string"
}- URL:
/api/products - Method:
GET - Response: List of products
- URL:
/api/cart - Method:
GET - Response: Cart items with totals
- URL:
/api/cart - Method:
POST - Body:
{
"product_id": "integer",
"quantity": "integer"
}- URL:
/api/orders - Method:
POST - Body:
{
"user_id": "integer",
"total_amount": "float",
"items": [
{
"product_id": "integer",
"quantity": "integer"
}
]
}- Git
- Docker
- Docker Compose
- Clone Repository
git clone https://github.com/SubbuTechOps/ecommerce-app-three-tier.git
cd ecommerce-app-three-tier- Environment Setup
cp .env.example .env
# Update .env with your configurations:
DB_HOST=db
DB_USER=subbu
DB_PASSWORD=admin@1234
DB_NAME=ecommerce
SECRET_KEY=your_secure_secret_key
FLASK_DEBUG=True
PORT=5000
SESSION_FILE_DIR=/tmp/flask_sessions- Docker Deployment
# Build and start containers
docker compose -f docker/docker-compose.yaml up --build
# Run in background
docker compose -f docker/docker-compose.yaml up --build -d
# View logs
docker compose -f docker/docker-compose.yaml logs -fgraph TB
subgraph "Docker Environment"
A[Backend Container]
B[MySQL Container]
C[Volume: flask_sessions]
D[Volume: mysql_data]
end
A --> B
A --> C
B --> D
- Session-based authentication
- Password hashing using secure algorithms
- Session timeout management
- CSRF protection
- SQL injection prevention
- XSS protection
- Input validation
- Secure password storage
- CORS configuration
- Unit Testing
- Integration Testing
- System Testing
- User Acceptance Testing
- API endpoints
- Database operations
- Authentication flow
- Business logic
- User interface
# Check database container
docker compose -f docker/docker-compose.yaml ps db
# View database logs
docker compose -f docker/docker-compose.yaml logs db# Check session directory
docker compose -f docker/docker-compose.yaml exec backend ls -la /tmp/flask_sessions
# Clear sessions
docker compose -f docker/docker-compose.yaml exec backend rm -rf /tmp/flask_sessions/*# Backend shell access
docker compose -f docker/docker-compose.yaml exec backend bash
# Database access
docker compose -f docker/docker-compose.yaml exec db mysql -u subbu -p- Follow PEP 8 for Python code
- Use proper HTML5 semantic elements
- Maintain consistent CSS naming conventions
- Follow REST API best practices
- Create feature branch
- Make changes
- Test locally
- Submit pull request
- Code review
- Merge to main
- Test in development
- Build Docker images
- Deploy to staging
- Run integration tests
- Deploy to production
- Git
- Docker
- Docker Compose
- Make (optional, for Makefile commands)
- Clone the Repository
# Clone the repository
git clone https://github.com/yourusername/shopeasy.git
cd shopeasy- Environment Configuration
# Copy example environment file
cp .env.example .env
# Update .env file with your configurations
DB_HOST=db
DB_USER=subbu
DB_PASSWORD=admin@1234
DB_NAME=ecommerce
SECRET_KEY=your_secure_secret_key
FLASK_DEBUG=True
PORT=5000
SESSION_FILE_DIR=/tmp/flask_sessions- Project Structure
shopeasy/
├── backend/
│ ├── app.py
│ ├── routes/
│ ├── models/
│ ├── database/
│ └── Dockerfile.backend
├── frontend/
│ ├── index.html
│ ├── catalog.html
│ ├── cart.html
│ └── styles.css
├── docker/
│ └── docker-compose.yaml
├── .env
└── README.md
- Docker Compose Deployment
# Build and start containers
docker compose -f docker/docker-compose.yaml up --build
# To run in detached mode
docker compose -f docker/docker-compose.yaml up --build -d
# To stop the containers
docker compose -f docker/docker-compose.yaml down
# To view logs
docker compose -f docker/docker-compose.yaml logs -f- Database Initialization
# Database migrations and initial data will be loaded automatically
# from the SQL files in backend/database/ directory:
- 01_schema.sql
- 02_data.sql- Verify Deployment
- Access the application: http://localhost:5000
- Check container status:
docker compose -f docker/docker-compose.yaml ps- Troubleshooting Commands
# Check backend logs
docker compose -f docker/docker-compose.yaml logs -f backend
# Check database logs
docker compose -f docker/docker-compose.yaml logs -f db
# Restart specific service
docker compose -f docker/docker-compose.yaml restart backend
# Remove volumes and clean start
docker compose -f docker/docker-compose.yaml down -v
docker compose -f docker/docker-compose.yaml up --build-
Default test account:
- Username: subbu
- Password: admin@1234
-
Test the deployment:
- Visit http://localhost:5000
- Login with test credentials
- Browse catalog
- Add items to cart
- Place test order
- Database Connection Issues
# Check if database is running
docker compose -f docker/docker-compose.yaml ps db
# Check database logs
docker compose -f docker/docker-compose.yaml logs db
# Manual database connection test
docker compose -f docker/docker-compose.yaml exec db mysql -u subbu -p- Session Issues
# Check session directory permissions
docker compose -f docker/docker-compose.yaml exec backend ls -la /tmp/flask_sessions
# Clear sessions
docker compose -f docker/docker-compose.yaml exec backend rm -rf /tmp/flask_sessions/*- Port Conflicts
# Check if ports are in use
netstat -tulpn | grep 5000
netstat -tulpn | grep 3306
# Change ports in docker-compose.yaml if needed- Access Container Shell
# Backend container
docker compose -f docker/docker-compose.yaml exec backend bash
# Database container
docker compose -f docker/docker-compose.yaml exec db bash- Database Management
# Create database backup
docker compose -f docker/docker-compose.yaml exec db mysqldump -u subbu -p ecommerce > backup.sql
# Restore database
docker compose -f docker/docker-compose.yaml exec -T db mysql -u subbu -p ecommerce < backup.sql- Code Updates
# Apply code changes
docker compose -f docker/docker-compose.yaml restart backend
# View updated logs
docker compose -f docker/docker-compose.yaml logs -f backend- Security Considerations
- Update SECRET_KEY in .env
- Set FLASK_DEBUG=False
- Use proper SSL/TLS certificates
- Update database passwords
- Remove test accounts
- Performance Optimization
- Configure proper database indexes
- Set up proper logging
- Configure backup strategy
- Set up monitoring
- Scaling Notes
- Configure load balancer if needed
- Set up database replication
- Configure proper cache strategy
- Set up proper monitoring and alerts