updated readme after major changes in code

This commit is contained in:
Andreas Jönsson 2025-11-16 18:11:15 +01:00
parent 65ed8d0659
commit e4a8f7f6c7

154
README.md
View File

@ -1,90 +1,106 @@
# Flask Base Application # Flask Base Project
A simple Flask web application with user authentication features. A starter template for Flask web applications with Docker support, user authentication, and deployment configurations.
## Features
- User registration, login, and dashboard functionality
- Docker and Docker Compose for containerized environments
- SQLite database (with optional PostgreSQL support)
- Environment configuration via .env file
- Jinja2 templating with base HTML structure
- Git version control integration
## Prerequisites
- Python 3.9+
- Docker 20.10+
- Docker Compose 2.4+
## Installation ## Installation
1. Clone the repository:
```bash ```bash
# Clone the repository git clone ssh://git@git.leoan.se:30009/andreas/flask-base.git
git clone https://git.leoan.se/andreas/flask-base.git
cd flask-base cd flask-base
# Create and activate virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Linux/MacOS
# venv\Scripts\activate # On Windows
# Install dependencies
pip install flask flask-sqlalchemy flask-login werkzeug
# Initialize database
flask init-db
``` ```
## Usage 2. Install Python dependencies:
### Local Development
```bash ```bash
# Start development server pip install -r requirements.txt
flask run --host=0.0.0.0 --port=5001
# Optional: Kill any existing flask server first
pkill -f "flask run" && flask run --host=0.0.0.0 --port=5001
``` ```
### Docker Deployment 3. Configure environment variables:
```bash ```bash
# First generate and set your secret key cp .env.example .env
python -c 'import secrets; print(f"FLASK_SECRET_KEY={secrets.token_hex(32)}")' >> .env # Edit .env with your configuration
```
# Then start the container ## Running the Application
### Development Mode
```bash
flask run --port=5000 --debug
```
### Production Mode with Docker
```bash
docker-compose up --build docker-compose up --build
# Production deployment (detached mode)
docker-compose up --build -d
```
Note: Docker will automatically load the `.env` file from your project root
The application will be available at `http://localhost:5001`
### Persisting Data
The database file (database.db) will be preserved between container restarts through the `./instance` volume mount.
**Important:** After renaming the database:
1. Delete the old database file if it exists:
```bash
rm instance/users.db
```
2. Reinitialize the database:
```bash
flask init-db
``` ```
## Configuration ## Configuration
### Secret Key Management Essential environment variables in `.env`:
The application uses a hierarchical configuration for the secret key: ```ini
1. Environment variable `FLASK_SECRET_KEY` (highest priority) FLASK_APP=app.py
2. Hardcoded value in `app.py` (development fallback only) FLASK_ENV=production
DATABASE_URL=sqlite:///instance/app.db
**Production Setup:** SECRET_KEY=your-secret-key-here
```bash
# Generate a secure secret key
python -c 'import secrets; print(secrets.token_hex(32))'
# Update .env file
echo "FLASK_SECRET_KEY=your_generated_secret_here" >> .env
``` ```
**Important Security Notes:** ## Deployment
- Never commit the `.env` file to version control
- The default secret key should only be used for development
- In production, use proper secret management (Vault, KMS, etc.)
## Features 1. Build production Docker image:
- User registration with password confirmation ```bash
- Secure password hashing docker build -t flask-base:latest .
- Login/logout functionality ```
- SQLite database
- Environment-based configuration 2. Start container with database:
```bash
docker-compose -f docker-compose.prod.yml up -d
```
## Project Structure
```
flask-base/
├── app.py
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── templates/
├── base.html
├── login.html
├── register.html
└── dashboard.html
```
## Contributing
1. Create your feature branch:
```bash
git checkout -b feature/your-feature
```
2. Commit changes:
```bash
git commit -m 'Add some feature'
```
3. Push to branch:
```bash
git push origin feature/your-feature
```
## License
MIT License - see [LICENSE](LICENSE) for details