A modern full-stack application with a Python FastAPI backend and Supabase integration, following modular monolith architecture principles.
This project follows a Modular Monolith pattern, where:
- Backend: Python FastAPI with Supabase integration
- Frontend: (To be implemented)
- Database: Supabase (PostgreSQL with real-time features)
- Authentication: Supabase Auth
python-modular-monolith/
├── backend/ # Python FastAPI backend
│ ├── api.py # Main FastAPI application
│ ├── config.py # Configuration management
│ ├── database.py # Supabase client setup
│ ├── models.py # Pydantic models
│ ├── services.py # Business logic layer
│ ├── requirements.txt # Python dependencies
│ ├── run.py # Server startup script
│ ├── test_setup.py # Setup verification
│ ├── env.example # Environment template
│ └── README.md # Backend documentation
├── frontend/ # Frontend application (future)
├── .gitignore # Git ignore rules
└── README.md # This file
- Python 3.11+ (recommended for best compatibility)
- Supabase account and project
- Git
-
Clone the repository
git clone <your-repo-url> cd python-modular-monolith
-
Set up the backend
cd backend python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Configure environment variables
cp env.example .env # Edit .env with your Supabase credentials
-
Start the server
python run.py
-
Verify setup
python test_setup.py
Once the server is running, visit:
- Interactive API Docs: http://localhost:8000/docs
- ReDoc Documentation: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
Create a .env
file in the backend/
directory:
# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_key
# Server Configuration
HOST=0.0.0.0
PORT=8000
DEBUG=True
- Go to Supabase Dashboard
- Select your project
- Go to Settings → API
- Copy the Project URL and anon public key
POST /auth/register
- Register a new userPOST /auth/login
- Login userPOST /auth/logout
- Logout userPOST /auth/refresh
- Refresh access token
GET /users/me
- Get current user infoPUT /users/me
- Update current userDELETE /users/me
- Delete current user
GET /admin/users/{user_id}
- Get user by IDPUT /admin/users/{user_id}
- Update user by IDDELETE /admin/users/{user_id}
- Delete user by ID
GET /health
- Health checkGET /
- Root endpoint
The backend follows a clean architecture pattern:
config.py
: Centralized configuration managementdatabase.py
: Supabase client initialization and connection managementmodels.py
: Pydantic models for request/response validationservices.py
: Business logic layer with UserService and AuthServiceapi.py
: FastAPI application with route definitions
- Models: Add new Pydantic models in
models.py
- Services: Add business logic in
services.py
- Routes: Add new endpoints in
api.py
- Configuration: Add new settings in
config.py
if needed
# Run setup tests
python test_setup.py
# Install test dependencies
pip install pytest pytest-asyncio httpx
# Run tests (when implemented)
pytest
- Set
DEBUG=False
in environment variables - Configure proper CORS origins
- Use a production WSGI server:
pip install gunicorn gunicorn api:app -w 4 -k uvicorn.workers.UvicornWorker
- Set up proper logging and monitoring
- Configure environment variables securely
Docker configuration will be added for containerized deployment.
- JWT-based authentication via Supabase
- Environment variable configuration
- Input validation with Pydantic
- CORS middleware configured
- Secure password handling
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
- Python version compatibility: Use Python 3.11+ for best results
- Supabase connection errors: Verify your credentials in
.env
- Import errors: Ensure virtual environment is activated
- Port conflicts: Change
PORT
in.env
if 8000 is in use
- Check the API documentation at
/docs
- Review the health endpoint at
/health
- Check server logs for detailed error messages
- Frontend implementation
- Docker containerization
- CI/CD pipeline
- Comprehensive test suite
- Database migrations
- Real-time features
- API rate limiting
- Monitoring and logging