A powerful template for building AI-powered applications with Next.js, FastAPI, PostgreSQL, and OpenAI.
- Next.js 14.x with TypeScript
- Tailwind CSS + ShadcN UI for beautiful, responsive UI
- React Query for efficient data fetching
- Zustand for state management
- NextAuth.js for authentication
- FastAPI (Python 3.11+) for high-performance API
- PostgreSQL + pgvector for vector storage
- SQLAlchemy ORM for database operations
- LangChain for AI orchestration
- OpenAI API integration
- Vector embeddings with pgvector
- RAG (Retrieval Augmented Generation)
- Docker for containerization
- GitHub Actions for CI/CD
- AWS Lambda deployment ready
- Vercel deployment ready
- Node.js 18+
- Python 3.11+
- Docker and Docker Compose
- PostgreSQL 14+
This project includes root-level scripts to simplify installation and running both frontend and backend components:
# Install all dependencies (both frontend and backend)
npm run install:all
# Start both frontend and backend in development mode
npm run dev
# Start both services in production mode
npm run start
# Use Docker for development (recommended)
npm run docker:devThe easiest way to get started is using Docker:
# Start the complete development environment
npm run docker:dev
# Access the application at http://localhost:3000
# The API is available at http://localhost:8000This will start:
- PostgreSQL database with pgvector extension
- FastAPI backend with hot reloading
- Next.js frontend with hot reloading
All services are configured to work together, and your local code changes will be reflected immediately.
- Clone the repository:
git clone https://github.com/rikudi/next-fastAPI-postgres.git
cd next-fastAPI-postgres- Set up the backend:
cd backend
cp .env.example .env # Configure your environment variables
docker-compose up -d postgres # Start PostgreSQL with pgvector
pip install -r requirements.txt- Set up the frontend:
cd frontend
cp .env.example .env # Configure your environment variables
npm install# From the root directory
npm run dev # Run both frontend and backend in development mode
npm run dev:frontend # Run only frontend
npm run dev:backend # Run only backend- Start the backend:
cd backend
uvicorn app.main:app --reload- Start the frontend:
cd frontend
npm run dev- Open your browser and navigate to
http://localhost:3000
| Command | Description |
|---|---|
npm run install:all |
Install all dependencies for both frontend and backend |
npm run install:frontend |
Install only frontend dependencies |
npm run install:backend |
Install only backend dependencies |
npm run dev |
Run both frontend and backend in development mode |
npm run dev:frontend |
Run only frontend in development mode |
npm run dev:backend |
Run only backend in development mode |
npm run build:frontend |
Build the frontend for production |
npm run start |
Run both frontend and backend in production mode |
npm run start:frontend |
Run only frontend in production mode |
npm run start:backend |
Run only backend in production mode |
npm run docker:up |
Start all services with Docker Compose |
npm run docker:down |
Stop all Docker Compose services |
npm run docker:dev |
Start development environment with Docker Compose |
npm run docker:dev:down |
Stop development Docker Compose services |
├── backend/ # FastAPI backend
│ ├── app/ # Application code
│ │ ├── api/ # API endpoints
│ │ ├── core/ # Core functionality
│ │ ├── db/ # Database models
│ │ └── services/ # Business logic
│ ├── alembic/ # Database migrations
│ └── tests/ # Backend tests
│
├── frontend/ # Next.js frontend
│ ├── app/ # App router pages
│ ├── components/ # React components
│ ├── lib/ # Utilities and hooks
│ └── public/ # Static assets
│
└── docker-compose.yml # Docker configuration
- Document Q&A: Upload documents and ask questions about them
- Semantic Search: Search through documents using natural language
- AI Chat: Chat with an AI assistant that has context from your documents
cd backend
python -m pytest # Run testscd frontend
npm run lint # Run ESLint
npm run build # Build for productionThis project is licensed under the MIT License - see the LICENSE file for details.
Created by Rikudi