A full-stack system template built with FastAPI backend, UniApp frontend, and MySQL database. This project serves as a comprehensive starter template for building modern web applications with cross-platform support.
βββ backend/ # FastAPI backend service
β βββ app/
β β βββ api/ # API routes and endpoints
β β βββ core/ # Core configurations and security
β β βββ crud/ # Database CRUD operations
β β βββ db/ # Database connection and setup
β β βββ models/ # SQLAlchemy data models
β β βββ schemas/ # Pydantic schemas for validation
β β βββ main.py # FastAPI application entry point
β βββ requirements.txt # Python dependencies
β βββ .env # Environment variables
βββ frontend/ # UniApp Vue3 frontend application
β βββ src/
β β βββ pages/ # Application pages
β β βββ utils/ # Utility functions
β β βββ main.ts # Application entry point
β βββ package.json # Node.js dependencies
β βββ vite.config.ts # Vite configuration
βββ database/ # Database initialization scripts
β βββ init.sql # Database schema and sample data
βββ logs/ # Application logs
βββ scripts/ # Startup and utility scripts
- β User Management: Registration, authentication, and user profiles
- β Post Management: Full CRUD operations for blog posts
- β JWT Authentication: Secure token-based authentication
- β Permission Control: Role-based access control
- β Statistics API: Dashboard metrics and analytics
- β Admin Interface: Built-in SQLAdmin management panel
- β API Documentation: Auto-generated OpenAPI/Swagger docs
- β Database ORM: SQLAlchemy with async support
- β Responsive Design: Modern UI with mobile-first approach
- β Post Browsing: Article listing and detailed views
- β Real-time Stats: Dynamic dashboard with live data
- β Cross-platform: Supports H5, WeChat Mini Program, and more
- β TypeScript: Full type safety throughout the application
- β Vue 3 Composition API: Modern Vue.js development patterns
- β MySQL Integration: Robust relational database support
- β Schema Management: Well-structured user and post tables
- β Data Relationships: Foreign key constraints and indexes
- β Sample Data: Pre-populated demo content for quick start
- Python 3.12+
- Node.js 20+
- MySQL 8.0+
# Create database and tables
mysql -h 127.0.0.1 -u root -p < database/init.sql
cd backend
# Install dependencies
pip install -r requirements.txt
# Start the FastAPI server
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
cd frontend
# Install dependencies
npm install
# Start development server for H5
npm run dev:h5
# Or for WeChat Mini Program
npm run dev:mp-weixin
- Frontend Application: http://localhost:5174/
- API Documentation: http://localhost:8000/docs
- Admin Panel: http://localhost:8000/admin/
- Alternative API Docs: http://localhost:8000/redoc
Admin Account:
- Username:
admin
- Password:
secret
Test Users:
- alice / secret
- bob / secret
- charlie / secret
POST /api/v1/auth/login # User login
POST /api/v1/users/ # User registration
GET /api/v1/users/me # Get current user info
GET /api/v1/posts/published # Get published posts
GET /api/v1/posts/{id} # Get post details
POST /api/v1/posts/ # Create post (authenticated)
PUT /api/v1/posts/{id} # Update post (authenticated)
DELETE /api/v1/posts/{id} # Delete post (authenticated)
GET /api/v1/stats/dashboard # Get dashboard statistics
GET /api/v1/stats/overview # Get application overview
Field | Type | Description |
---|---|---|
id | INT | Primary key |
username | VARCHAR(50) | Unique username |
VARCHAR(100) | User email address | |
password_hash | VARCHAR(255) | Hashed password |
full_name | VARCHAR(100) | Display name |
is_active | BOOLEAN | Account status |
created_at | DATETIME | Creation timestamp |
updated_at | DATETIME | Last update timestamp |
Field | Type | Description |
---|---|---|
id | INT | Primary key |
title | VARCHAR(200) | Post title |
content | TEXT | Post content |
author_id | INT | Foreign key to users |
is_published | BOOLEAN | Publication status |
created_at | DATETIME | Creation timestamp |
updated_at | DATETIME | Last update timestamp |
- Framework: FastAPI 0.116.0
- Database: MySQL 8.0 with SQLAlchemy ORM
- Authentication: JWT with python-jose
- Password: bcrypt hashing
- Admin: SQLAdmin interface
- Validation: Pydantic v2
- Environment: python-dotenv
- Framework: Vue 3.4.21 with Composition API
- Build Tool: Vite 5.2.8
- Language: TypeScript 4.9.4
- UI Framework: UniApp 3.0
- Cross-platform: H5, WeChat Mini Program, Alipay Mini Program
- HTTP Client: Axios with request interceptors
- Code Quality: ESLint, Ruff formatter
- Type Checking: TypeScript, Vue TSC
- Environment: Docker-ready configuration
- Logging: Structured logging with file rotation
cd backend
# Install dependencies
pip install -r requirements.txt
# Run with hot reload
uvicorn app.main:app --reload
# Format code with Ruff
ruff format .
# Lint code
ruff check .
cd frontend
# Install dependencies
npm install
# Development (H5)
npm run dev:h5
# Development (WeChat Mini Program)
npm run dev:mp-weixin
# Build for production
npm run build
# Type checking
npm run type-check
# Lint code
npm run lint
# Lint and fix
npm run lint:fix
The UniApp framework enables deployment to multiple platforms:
- H5: Web browsers and mobile web
- WeChat Mini Program: Native WeChat integration
- Alipay Mini Program: Alipay ecosystem support
- Mobile Apps: Android and iOS with uni-app build
- RESTful API architecture
- OpenAPI 3.0 specification
- Automatic documentation generation
- Request/response validation
- Error handling with proper HTTP status codes
- JWT token-based authentication
- Password hashing with bcrypt
- CORS configuration for cross-origin requests
- SQL injection prevention with SQLAlchemy ORM
- Input validation with Pydantic schemas
// Frontend API call
const createPost = async (postData) => {
const response = await uni.request({
url: 'http://localhost:8000/api/v1/posts/',
method: 'POST',
header: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
data: postData
});
return response.data;
};
# Backend authentication
from app.core.security import verify_password, create_access_token
def authenticate_user(username: str, password: str):
user = get_user_by_username(username)
if not user or not verify_password(password, user.password_hash):
return False
return user
# Generate JWT token
access_token = create_access_token(data={"sub": user.username})
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the API documentation when running the backend
- Review the console logs in the
logs/
directory - Ensure all dependencies are properly installed
- Verify database connection settings in
backend/.env
- β Fixed all Ruff formatting issues
- β Updated repository to git@github.com:clacky-ai/uniapp-fastapi-mysql-starter.git
- β Enhanced project documentation
- β Improved code structure and organization
Made with β€οΈ using FastAPI, Vue 3, and UniApp