Python3 web application Demo for comment tree (including comment tree, user authentication, and Swagger API documentation), using Python3+FastAPI+SQLModel+Pydantic+Alembic as backend, and Next.js+TypeScript as frontend.
A full-stack application featuring:
- Backend API with Python (FastAPI)
- Frontend UI with Next.js
- Comment tree functionality with nested replies
- User authentication system
- Swagger API documentation
- Docker support
- Backend: Python, FastAPI, SQLModel, Pydantic, Alembic
- Frontend: Next.js, TypeScript
- Package Management: uv
- Database: SQLite (development)
- API Docs: Swagger UI is available on
http://<ip>:8000/docs
- Python 3.11+
- Node.js 18+ (optional)
- Docker (optional)
Two ways to run the application:
- Run application locally, or
- Run application in Docker
-
(Once) Install uv
-
**Setup Environment Variables **:
cp .env.example .env
make db- Run Application Locally:
make run- build the docker image
make docker- run the docker container
sudo docker run -p 8000:8000 comment-app:v0.0.1- install uv which will be used to manage this Python backend.
- run the following commands to initialize the backend (with alembic + fastapi + pydantic + sqlmodel)
cd backend
uv venv
source .venv/bin/activate
uv init
uv add alembic fastapi[standard] pydantic-settings sqlmodel python-jose[cryptography] passlib python-multipart
uv add --dev pytest ruff mypy
alembic init alembic
# Add model in backend/app/database/models, then modify alembic/env.py to add model's metadata,
# finally run the following command to create migration
alembic revision --autogenerate -m "init"
alembic upgrade head
# Testing backend
fastapi run app/main.py- run the following commands to initialize the frontend UI(with next.js)
cd ui
npx create-next-app@latest .- change the output config by modifying
next.config.js - install the dependencies
npm install- run the following commands to build the static UI
npm run build- download swagger UI from swagger-ui dist folder
- update backend code to mount the swagger-ui and static UI
- create
.envfile by copy and modify file.env.example - change setting in .env such as
ENVIRONMENTandDATABASE_URL - change
SECRET_KEYin.envfile to a random long string in production environment for security reason make runto start the application based on the environment from.envfile
make testto run the tests
make lintto run the linting and code style checkmake formatto format the code