A full-stack application with a FastAPI backend and Next.js frontend.
- Docker and Docker Compose (for PostgreSQL)
- Python 3.10+ (for backend)
- Node.js 18+ and npm (for frontend)
The project uses PostgreSQL as its database. Start PostgreSQL using Docker Compose:
cd backend
docker-compose up -dThis will start PostgreSQL with the following defaults:
- Host:
localhost - Port:
5432 - User:
postgres - Password:
postgres - Database:
postgres(default database)
docker psYou should see a container named backend-db-1 running.
If you need to create a new database:
docker exec -it backend-db-1 psql -U postgres -c "CREATE DATABASE mime;"Or connect to PostgreSQL and create it manually:
docker exec -it backend-db-1 psql -U postgresThen in the PostgreSQL prompt:
CREATE DATABASE mime;
\q- Navigate to backend directory and create a virtual environment:
cd backend
python3 -m venv venv- Activate the virtual environment:
On macOS/Linux:
source venv/bin/activateOn Windows:
venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
Create a .env file in the backend directory:
touch .envAdd the following to .env:
_DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgresIf you created a different database, update the database name in the URL:
_DATABASE_URL=postgresql://postgres:postgres@localhost:5432/mimeNote: The connection string format is: postgresql://[user]:[password]@[host]:[port]/[database]
You may also need to add other environment variables for API keys (OpenAI, Pinecone, etc.) depending on your use case.
- Run database migrations:
alembic upgrade headThis will create all necessary database tables.
- Start the backend server:
Development mode (with auto-reload):
make start-devOr manually:
uvicorn main:app --reloadThe backend will start on http://localhost:8000.
To verify it's running, visit http://localhost:8000 in your browser. You should see:
{"message": "API is running"}- Navigate to frontend directory:
cd ../frontend- Install dependencies:
npm install- Start the development server:
npm run devThe frontend will start on http://localhost:3000.
- Start PostgreSQL (in one terminal):
cd backend
docker-compose up -d- Start the backend (in another terminal):
cd backend
source venv/bin/activate
make start-dev- Start the frontend (in a third terminal):
cd frontend
npm run devmake start-dev- Start development server with auto-reloadmake start-prod- Start production server with gunicornmake migrate- Run database migrationsmake autogen-migrations "message"- Create a new migration
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run linter
docker-compose ps- Check PostgreSQL container statusdocker-compose logs db- View PostgreSQL logsdocker-compose down- Stop and remove PostgreSQL containerdocker-compose down -v- Stop and remove container with volumes (⚠️ deletes data)
If you see database connection errors:
-
Verify PostgreSQL is running:
docker ps
-
Check if you can connect:
docker exec -it backend-db-1 psql -U postgres -c "\l"
-
Verify your
_DATABASE_URLin.envmatches the PostgreSQL credentials -
Ensure the database exists (PostgreSQL defaults to
postgresdatabase if none specified)
If migrations fail:
- Make sure your database is accessible
- Check that all models are imported in
models/postgresql.py - You may need to create an initial migration:
alembic revision --autogenerate -m "Initial migration" alembic upgrade head
If port 5432 is already in use, you can change it in backend/docker-compose.yaml:
ports:
- 5433:5432 # Use 5433 on host insteadThen update your _DATABASE_URL accordingly.
mime-v2/
├── backend/ # FastAPI backend
│ ├── api/ # API routes
│ ├── models/ # Database models
│ ├── logic/ # Business logic
│ ├── migrations/ # Alembic migrations
│ └── main.py # FastAPI app entry point
├── frontend/ # Next.js frontend
│ └── src/ # Source code
└── docker-compose.yaml # PostgreSQL configuration
- The backend API runs on port 8000
- The frontend runs on port 3000
- PostgreSQL runs on port 5432
- The backend uses Alembic for database migrations
- Environment variables are loaded from
.envfiles usingpython-dotenv