A modern web application built with FastAPI following the MVC (Model-View-Controller) pattern, featuring user authentication and post management.
-
Authentication & Authorization
- JWT token-based authentication
- Secure password hashing with bcrypt
- Email validation
- Protected routes
-
Database & ORM
- MySQL 8.0 database
- SQLAlchemy ORM
- Automatic table creation
- Connection pooling
-
API Features
- FastAPI with automatic OpenAPI documentation
- Request/Response validation with Pydantic
- Response caching with cachetools
- File upload support
- Comprehensive error handling
-
Development & Deployment
- Docker containerization
- Docker Compose for multi-container setup
- Environment variable configuration
- Health checks and container orchestration
- Docker and Docker Compose
- Python 3.9+ (for local development)
- MySQL client (optional, for direct database access)
- Clone the repository:
git clone https://github.com/Markolissimo/mvc.git
cd mvc- Build and start the containers:
docker-compose up --buildThe application will be available at http://localhost:8000
Once the application is running, you can access:
- Interactive API docs (Swagger UI): http://localhost:8000/docs
- Alternative API docs (ReDoc): http://localhost:8000/redoc
mvc/
├── src/ # Source code
│ ├── controllers/ # Route handlers and request processing
│ ├── models/ # SQLAlchemy and Pydantic models
│ ├── services/ # Business logic and data processing
│ ├── auth.py # Authentication utilities
│ ├── database.py # Database configuration
│ └── main.py # FastAPI application entry point
├── mysql/ # MySQL configuration
│ ├── conf.d/ # MySQL configuration files
│ └── init.sql # Database initialization script
├── tests/ # Test files
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Web application container definition
├── requirements.txt # Python dependencies
├── wait_for_db.py # Database connection check script
└── README.md # Project documentation
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration- Run the development server:
uvicorn src.main:app --reloadPOST /auth/signup- Register a new userPOST /auth/login- Login and receive JWT token
POST /posts/- Create a new postGET /posts/- List all postsGET /posts/{post_id}- Get a specific postPUT /posts/{post_id}- Update a postDELETE /posts/{post_id}- Delete a post
The application uses two containers:
-
Web application (FastAPI)
- Port: 8000
- Environment variables from .env
- Volume mount for code changes
-
MySQL database
- Port: 3306
- Persistent volume for data
- Custom configuration
- Initialization script
Run the test suite:
pytest- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - see LICENSE file for details