Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“˜ Flask MongoDB CRUD API

A RESTful API built with Flask, MongoDB, and Docker, supporting full CRUD operations for user management.

πŸ”— Live Demo

You can deploy it using Render, Railway, or Docker on VPS. Link goes here if hosted.


πŸ“‚ Project Structure

flask_mongo_crud/
β”‚
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ __init__.py         # App factory
β”‚   β”œβ”€β”€ config.py           # App config (Mongo URI, etc.)
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── user.py         # User model
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── user_routes.py  # API route definitions
β”‚   β”œβ”€β”€ schemas/
β”‚   β”‚   └── user_schema.py  # Marshmallow schema for validation
β”‚   └── services/
β”‚       └── user_service.py # Business logic for users
β”‚
β”œβ”€β”€ .env                    # MongoDB URI (excluded via .gitignore)
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
└── run.py                  # Entry point to start Flask app

πŸ“¦ Features

  • RESTful API using Flask + Flask-RESTful
  • MongoDB database (via Flask-PyMongo)
  • Input validation with marshmallow
  • Secure password hashing using Werkzeug
  • Dockerized for easy setup and deployment
  • Modular architecture with services/models/routes
  • Environment variable support with python-dotenv

πŸ§ͺ API Endpoints

Method Endpoint Description
GET /users/ Get all users
GET /users/<id> Get user by ID
POST /users/ Create a new user
PUT /users/<id> Update existing user
DELETE /users/<id> Delete a user

🧰 Technologies Used

  • Backend: Flask, Flask-PyMongo, Flask-RESTful, Marshmallow
  • Database: MongoDB
  • Security: Werkzeug (password hashing)
  • Containerization: Docker, Docker Compose
  • Testing: Pytest (optional)
  • Environment Handling: python-dotenv

▢️ How to Run

🐳 With Docker

docker-compose up --build

Visit the API at: http://localhost:5050/users

πŸ–₯️ Without Docker

# Create a virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Set environment variables
export MONGO_URI="your-mongodb-uri"

# Run the server
python run.py

✏️ Example curl Commands

# Create a user
curl -X POST http://localhost:5050/users/ \
  -H "Content-Type: application/json" \
  -d '{"name":"John Doe","email":"john@example.com","password":"secure123"}'

# Get all users
curl http://localhost:5050/users/

# Get single user
curl http://localhost:5050/users/<id>

# Update user
curl -X PUT http://localhost:5050/users/<id> \
  -H "Content-Type: application/json" \
  -d '{"name":"Jane Doe"}'

# Delete user
curl -X DELETE http://localhost:5050/users/<id>

πŸ“„ License

This project is licensed under the MIT License.

About

UserHub is a secure, Dockerized RESTful API for user management (Name, E-mail, πŸ”’ password). Built with Flask + MongoDB, using clean architecture, Marshmallow schemas, and service layers. 🐳 Easily deployable via Docker Compose.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages