Money_Project

Flask Modular Application

A modular Flask application with Flask-SQLAlchemy, Flask-Migrate, Flask-Babel, and Flask-Login.

Features

Project Structure

mon3y_clone/
├── app/
│   ├── __init__.py           # Application factory
│   ├── extensions.py         # Flask extensions
│   ├── main/                 # Main blueprint
│   │   ├── __init__.py
│   │   └── routes.py         # Main routes
│   └── translations/         # Babel translations directory
├── config.py                 # Configuration classes
├── run.py                    # Application entry point
├── .env                      # Environment variables
├── requirements.txt          # Python dependencies
└── README.md                 # This file

Installation

  1. Clone the repository:
    git clone <repository-url>
    cd mon3y_clone
    
  2. Create a virtual environment:
    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. Configure environment variables: Edit the .env file with your configuration:
    SECRET_KEY=your-secret-key-here
    FLASK_ENV=development
    SQLALCHEMY_DATABASE_URI=sqlite:///dev-database.db
    BABEL_DEFAULT_LOCALE=en
    BABEL_SUPPORTED_LOCALES=en,es,fr,pt,de
    
  5. Initialize the database:
    flask db init
    flask db migrate -m "Initial migration"
    flask db upgrade
    
  6. Initialize Babel translations (optional):
    # Extract translatable strings
    pybabel extract -F babel.cfg -o messages.pot .
       
    # Initialize translations for each language
    pybabel init -i messages.pot -d app/translations -l es
    pybabel init -i messages.pot -d app/translations -l fr
    pybabel init -i messages.pot -d app/translations -l pt
    pybabel init -i messages.pot -d app/translations -l de
       
    # Compile translations
    pybabel compile -d app/translations
    

Usage

Running the Application

Development mode:

python run.py

Or using Flask CLI:

export FLASK_APP=run.py
flask run

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

Configuration

The application supports two configurations:

Set the configuration in .env:

FLASK_ENV=development  # or production

Extensions

Flask-SQLAlchemy

Database ORM for managing database models and queries.

Flask-Migrate

Database migrations using Alembic.

Flask-Babel

Internationalization and localization support.

Supported languages:

Flask-Login

User session management and authentication.

Development

Adding a New Blueprint

  1. Create a new directory in app/:
    mkdir app/new_blueprint
    
  2. Create __init__.py:
    from flask import Blueprint
       
    bp = Blueprint('new_blueprint', __name__)
       
    from app.new_blueprint import routes
    
  3. Create routes.py with your routes

  4. Register the blueprint in app/__init__.py:
    from app.new_blueprint import bp as new_bp
    app.register_blueprint(new_bp, url_prefix='/new')
    

Database Models

Create models in a new file app/models.py:

from app.extensions import db

class User(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)

Database Migrations

# Create a new migration
flask db migrate -m "Description of changes"

# Apply migrations
flask db upgrade

# Rollback migrations
flask db downgrade

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.