Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud-Saeed-Mahmoud committed Dec 5, 2024
0 parents commit cbf3286
Show file tree
Hide file tree
Showing 13 changed files with 1,036 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
venv/
ENV/
env/

# IDE
.idea/
.vscode/
*.swp
*.swo

# Database
*.db
*.sqlite3

# Environment variables
.env

# Logs
*.log

# System Files
.DS_Store
Thumbs.db
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Mahmoud Saeed

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# CRM System

A Customer Relationship Management (CRM) system designed to help sales and customer service teams manage their customer interactions effectively. Created with [Windsurf](https://www.windsurfai.com/), the world's first agentic IDE.

## Features

- User Authentication
- Customer Management
- Interaction Tracking
- Dashboard with Key Metrics
- Responsive Design

## Setup

1. Create a virtual environment:
```bash
python -m venv venv
```

2. Activate the virtual environment:
- Windows:
```bash
venv\Scripts\activate
```
- Unix/MacOS:
```bash
source venv/bin/activate
```

3. Install dependencies:
```bash
pip install -r requirements.txt
```

4. Run the application:
```bash
python app.py
```

The application will be available at `http://localhost:5000`

## Project Structure

- `app.py`: Main application file with routes and models
- `templates/`: HTML templates
- `base.html`: Base template with common layout
- `index.html`: Dashboard template
- `login.html`: Login page
- `customer_form.html`: New customer form
- `customer_detail.html`: Customer details page
- `requirements.txt`: Project dependencies

## Dependencies

- Flask
- Flask-SQLAlchemy
- Flask-Login
- Flask-WTF
- SQLite (database)
- Bootstrap 5 (frontend)

## Security Note

Make sure to change the secret key in `app.py` before deploying to production.

## Credits

This project was created using [Windsurf](https://www.windsurfai.com/), an innovative AI-powered IDE that enables rapid application development through natural language interaction.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
203 changes: 203 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
from datetime import datetime, timedelta
from werkzeug.security import generate_password_hash, check_password_hash
from sqlalchemy import func

app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key' # Change this to a secure secret key
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///crm.db'
db = SQLAlchemy(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'

# Models
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
password = db.Column(db.String(120), nullable=False)

class Customer(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
email = db.Column(db.String(120))
phone = db.Column(db.String(20))
company = db.Column(db.String(100))
status = db.Column(db.String(20))
created_at = db.Column(db.DateTime, default=datetime.utcnow)
interactions = db.relationship('Interaction', backref='customer', lazy=True)

class Interaction(db.Model):
id = db.Column(db.Integer, primary_key=True)
customer_id = db.Column(db.Integer, db.ForeignKey('customer.id'), nullable=False)
type = db.Column(db.String(20))
notes = db.Column(db.Text)
date = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))

@login_manager.unauthorized_handler
def unauthorized():
flash('Please log in to access this page.')
return redirect(url_for('login'))

# Routes
@app.route('/')
@login_required
def index():
customers = Customer.query.all()
return render_template('index.html', customers=customers)

@app.route('/setup', methods=['GET', 'POST'])
def setup():
if User.query.first():
return "Setup already completed."

if request.method == 'POST':
username = request.form.get('username')
email = request.form.get('email')
password = request.form.get('password')

if username and email and password:
user = User(
username=username,
email=email,
password=generate_password_hash(password)
)
db.session.add(user)
db.session.commit()
flash('Admin user created successfully!')
return redirect(url_for('login'))

return render_template('setup.html')

@app.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('index'))

if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
user = User.query.filter_by(username=username).first()

if user and check_password_hash(user.password, password):
login_user(user)
flash('Logged in successfully!')
next_page = request.args.get('next')
return redirect(next_page if next_page else url_for('index'))
flash('Invalid username or password')
return render_template('login.html')

@app.route('/logout')
@login_required
def logout():
logout_user()
flash('Logged out successfully!')
return redirect(url_for('login'))

@app.route('/analytics')
@login_required
def analytics():
# Get customer statistics
total_customers = Customer.query.count()
new_customers_month = Customer.query.filter(
Customer.created_at >= datetime.utcnow() - timedelta(days=30)
).count()

# Get interaction statistics
total_interactions = Interaction.query.count()
interactions_by_type = db.session.query(
Interaction.type,
func.count(Interaction.id)
).group_by(Interaction.type).all()

# Get customer status distribution
status_distribution = db.session.query(
Customer.status,
func.count(Customer.id)
).group_by(Customer.status).all()

return render_template('analytics.html',
total_customers=total_customers,
new_customers_month=new_customers_month,
total_interactions=total_interactions,
interactions_by_type=interactions_by_type,
status_distribution=status_distribution)

@app.route('/settings', methods=['GET', 'POST'])
@login_required
def settings():
if request.method == 'POST':
# Handle profile update
current_user.email = request.form.get('email', current_user.email)
if request.form.get('new_password'):
current_user.password = generate_password_hash(request.form.get('new_password'))
db.session.commit()
flash('Settings updated successfully!')
return redirect(url_for('settings'))

return render_template('settings.html')

@app.route('/customer/new', methods=['GET', 'POST'])
@login_required
def new_customer():
if request.method == 'POST':
customer = Customer(
name=request.form.get('name'),
email=request.form.get('email'),
phone=request.form.get('phone'),
company=request.form.get('company'),
status=request.form.get('status')
)
db.session.add(customer)
db.session.commit()
flash('Customer added successfully!')
return redirect(url_for('customer_detail', id=customer.id))
return render_template('customer_form.html')

@app.route('/customer/<int:id>')
@login_required
def customer_detail(id):
customer = Customer.query.get_or_404(id)
return render_template('customer_detail.html', customer=customer)

@app.route('/customer/<int:id>/edit', methods=['GET', 'POST'])
@login_required
def edit_customer(id):
customer = Customer.query.get_or_404(id)
if request.method == 'POST':
customer.name = request.form.get('name', customer.name)
customer.email = request.form.get('email', customer.email)
customer.phone = request.form.get('phone', customer.phone)
customer.company = request.form.get('company', customer.company)
customer.status = request.form.get('status', customer.status)
db.session.commit()
flash('Customer updated successfully!')
return redirect(url_for('customer_detail', id=customer.id))
return render_template('customer_form.html', customer=customer)

@app.route('/customer/<int:id>/interaction', methods=['POST'])
@login_required
def add_interaction(id):
customer = Customer.query.get_or_404(id)
interaction = Interaction(
customer_id=customer.id,
type=request.form.get('type'),
notes=request.form.get('notes'),
user_id=current_user.id
)
db.session.add(interaction)
db.session.commit()
flash('Interaction added successfully!')
return redirect(url_for('customer_detail', id=customer.id))

if __name__ == '__main__':
with app.app_context():
db.create_all()
app.run(debug=True)
8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Flask==2.0.1
Flask-SQLAlchemy==2.5.1
Flask-Login==0.5.0
Flask-WTF==0.15.1
Werkzeug==2.0.1
SQLAlchemy==1.4.23
python-dotenv==0.19.0
email-validator==1.1.3
Loading

0 comments on commit cbf3286

Please sign in to comment.