This repository serves as the core backend operational engine for the Toti Cakery system. It is built using FastAPI with a fully asynchronous architecture and PostgreSQL 17 as the primary database management system.
The application implements a structured access control mechanism using a dynamic Hierarchical Role-Based Access Control (RBAC) framework.
Before running this project, ensure the following software is installed on your machine:
- Python 3.12+
- PostgreSQL 17+
- Homebrew (macOS / Apple Silicon users only)
- Postman or Insomnia (for API testing)
Follow these steps to run the project locally.
git clone https://github.com/nicholl2/backend-cakery.git
cd backend-cakery/BackendCreate a Python virtual environment:
python3 -m venv venvActivate the virtual environment:
macOS / Linux
source venv/bin/activateWindows (PowerShell)
.\venv\Scripts\Activate.ps1pip install --upgrade pip
pip install -r requirements.txtbrew install postgresql@17Start the PostgreSQL service:
brew services start postgresql@17Open the PostgreSQL CLI:
psql postgresInside the PostgreSQL shell, execute:
CREATE USER postgres WITH PASSWORD 'yourpassword' SUPERUSER;
CREATE DATABASE toti_cakery OWNER postgres;Exit PostgreSQL:
\qCreate a .env file in the project root directory and add the following configuration:
DATABASE_URL=your-database-url
SECRET_KEY=your-super-secret-key-change-this-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=480
SERVICE_API_KEY=your-chatbot-service-key
CHATBOT_URL=http://localhost:8000
CHATBOT_INTERNAL_KEY=your-internal-key
CHATBOT_WA_NUMBER=6281234567890
MIDTRANS_SERVER_KEY=SB-Mid-server-...
MIDTRANS_IS_PRODUCTION=...
CORS_ORIGINS=http://your-cors-origin
ENVIRONMENT=development
WA_VERIFICATION_MODE=mockCatatan Pengujian WA & Keamanan Produksi:
ENVIRONMENT:"development"|"production"WA_VERIFICATION_MODE:"mock"|"real"(JikaENVIRONMENT="production", sistem secara otomatis memaksakan mode"real"untuk menjaga keamanan verifikasi).- Default
CORS_ORIGINStelah mendukung frontend produksi di Vercel (https://toti-cakery.vercel.app) dan development local (localhost:5173).
uvicorn app.main:app --reloadThe API server will be available at:
http://127.0.0.1:8000
FastAPI automatically generates interactive API documentation.
-
Swagger UI
http://127.0.0.1:8000/docs -
ReDoc
http://127.0.0.1:8000/redoc
- FastAPI
- PostgreSQL 17
- SQLAlchemy (Async)
- Alembic
- Pydantic
- JWT Authentication
- Hierarchical RBAC