Skip to main content

Flask + MongoDB + Docker + Session Auth tek komutla hazır başlangıç şablonu

Project description

kw-flask

Flask + MongoDB + Docker + Session Auth — tek komutla hazır, modüler REST API şablonu.

pip install kw-flask
kw-flask benim-projem

Özellikler

  • 🏗️ Blueprint tabanlı modüler yapı — her modül kendi route/service/model/validator'ına sahip
  • 🔐 Flask-Login session auth — server-side session, remember me, rol bazlı erişim
  • 🍃 MongoEngine ODM — class tabanlı MongoDB modelleri
  • 🐳 Docker Compose — app + MongoDB + Mongo Express UI hazır
  • ⚙️ Ortam bazlı config — development / production / testing
  • 🛡️ Global hata yönetimi — tüm hatalar tutarlı JSON döner
  • 🔑 Otomatik SECRET_KEY — her projede benzersiz anahtar üretilir

Hızlı Başlangıç

# Kur
pip install kw-flask

# Proje oluştur
kw-flask siparis-api
cd siparis-api

# Docker ile başlat
docker compose up -d

API http://localhost:5000 adresinde hazır.
Mongo Express UI: http://localhost:8081


Endpoint'ler

Metod Endpoint Açıklama
POST /api/v1/auth/register Kayıt ol (oturum otomatik açılır)
POST /api/v1/auth/login Giriş yap (remember: true → 30 gün)
POST /api/v1/auth/logout Çıkış yap
GET /api/v1/auth/me Oturum açık kullanıcı
GET /api/v1/auth/check Session kontrolü
GET /api/v1/users Kullanıcı listesi (admin)
GET /api/v1/users/<id> Kullanıcı detayı
PATCH /api/v1/users/<id> Profil güncelle
POST /api/v1/users/<id>/change-password Şifre değiştir
DELETE /api/v1/users/<id> Hesabı devre dışı bırak
GET /health Servis + DB sağlık durumu

Proje Yapısı

app/
├── core/
│   ├── config.py              # Ortam bazlı konfigürasyon
│   ├── database/connection.py # DatabaseManager (MongoEngine)
│   ├── exceptions/            # AppException hiyerarşisi + global handler'lar
│   └── middlewares/
│       ├── session.py         # Flask-Login + @require_roles dekoratörü
│       └── health.py          # /health endpoint'i
├── modules/
│   └── user/
│       ├── models/            # MongoEngine User (UserMixin dahil)
│       ├── services/          # AuthService, UserService (class tabanlı)
│       ├── routes/            # Blueprint'ler
│       └── validators/        # Marshmallow şemaları
└── utils/
    ├── response.py            # success_response / error_response
    ├── validators.py          # validate_request yardımcısı
    └── logger.py              # Yapılandırılmış loglama

Yeni Modül Eklemek

app/modules/
└── urun/
    ├── __init__.py
    ├── models/urun_model.py
    ├── services/urun_service.py
    ├── routes/urun_routes.py
    └── validators/schemas.py

app/__init__.py içindeki _register_blueprints fonksiyonuna blueprint'i kaydet:

from .modules.urun.routes.urun_routes import urun_bp
app.register_blueprint(urun_bp, url_prefix="/api/v1/urunler")

Rol Bazlı Erişim

from app.core.middlewares.session import require_roles

@urun_bp.delete("/<id>")
@login_required
@require_roles("admin")
def delete_urun(id):
    ...

Ortam Değişkenleri

Değişken Açıklama
FLASK_ENV development / production
MONGO_URI MongoDB bağlantı adresi
MONGO_DB_NAME Veritabanı adı
SECRET_KEY Session imzalama anahtarı (otomatik üretilir)
BCRYPT_LOG_ROUNDS Bcrypt iş faktörü (varsayılan: 12)

Lisans

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kw_flask-1.0.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kw_flask-1.0.0-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file kw_flask-1.0.0.tar.gz.

File metadata

  • Download URL: kw_flask-1.0.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for kw_flask-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8362284633a45594ba89e7ba14a7c1b311dd13f5217507576ff2a91d3e21ac51
MD5 77f9c76431690b42bd4116b8dcb2b66f
BLAKE2b-256 3c0b35320e4db7a69809c4410535f7cce0eadbe3024da3cff69a584b3b7efacb

See more details on using hashes here.

File details

Details for the file kw_flask-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kw_flask-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for kw_flask-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 178675aa3172c556fc342255cc1fc862adc780eebeaa8ce763624a4790f00cc2
MD5 2cc43e7c52a05f1cea2aca95f17c3fb5
BLAKE2b-256 9122802155f5e658f0249c821c1fd475850c5a0727ecf8d0cd34b77cf382e8ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page