Skip to content

Latest commit

Β 

History

94 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rust Admin

A full-stack admin panel built with a Rust backend and Vue 3 frontend. The backend provides a RESTful API powered by Axum and SeaORM with SQLite, while the frontend is a modern admin dashboard based on vue-pure-admin.

✨ Features

  • Authentication: OAuth2 token-based auth with JWT, login/logout/refresh token support
  • User Management: CRUD operations, pagination, password reset, enable/disable toggle, role assignment
  • Role Management: CRUD operations, role-based access control, role-menu authorization
  • Menu Management: Tree-structured menus, per-user menu permissions, parent-child hierarchy
  • Organization Management: Tree-structured org units, batch delete, parent-child queries
  • Dictionary Management: System dictionaries and dictionary items with type-based lookups
  • System Log: Operation logging with pagination and sensitive data masking
  • Request Logging Middleware: Automatic HTTP request tracking with response time measurement

πŸ—οΈ Architecture

rust-admin/
β”œβ”€β”€ backend/           # Rust REST API (Axum + SeaORM + SQLite)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ api/       # HTTP layer (routes, middleware, app state)
β”‚   β”‚   β”œβ”€β”€ auth/      # Authentication (JWT + Redis token store)
β”‚   β”‚   β”œβ”€β”€ common/    # Shared utilities (error handling, pagination, traits)
β”‚   β”‚   β”œβ”€β”€ config/    # Application configuration
β”‚   β”‚   β”œβ”€β”€ migration/ # Database migrations
β”‚   β”‚   └── system/    # Business modules (user, role, menu, org, dict, log, auth)
β”‚   β”œβ”€β”€ tests/         # Integration tests (organized by module)
β”‚   └── config.toml    # Server, Redis, and database configuration
└── frontend/          # Vue 3 admin panel (vue-pure-admin)
    β”œβ”€β”€ src/
    β”‚   β”œβ”€β”€ api/       # API service functions
    β”‚   β”œβ”€β”€ router/    # Vue Router configuration
    β”‚   β”œβ”€β”€ store/     # Pinia state management
    β”‚   β”œβ”€β”€ views/     # Page components
    β”‚   └── ...       # Components, plugins, styles, utils
    └── vite.config.ts # Dev server with API proxy

Backend Architecture

The backend follows a layered architecture with trait-based dependency injection, inspired by Spring patterns:

Layer Responsibility Example
Handlers HTTP request/response handlers.rs
Service Business logic service.rs
Repository Data access (trait + impl) repository.rs
Domain Types, DTOs, entity aliases domain.rs
Entity SeaORM database models entity.rs

Each module under system/ follows this consistent structure, making it easy to add new business domains.

Frontend Architecture

The frontend is based on the vue-pure-admin template with Element Plus UI and TailwindCSS:

  • Vue 3 Composition API with <script setup> syntax
  • Pinia for state management
  • Element Plus component library
  • TailwindCSS 4 utility-first styling
  • Vue Router with lazy-loaded route modules
  • Axios for HTTP requests with auto-refresh token support
  • i18n multi-language support (en, zh-CN, zh-TW, ja, ko)

πŸ› οΈ Tech Stack

Backend

Technology Version Purpose
Rust Edition 2024 Language
Axum 0.8 Web framework
SeaORM 1.1 ORM (SQLite)
Tokio 1 Async runtime
Redis β€” Token/session storage
SQLite β€” Primary database
JWT β€” Authentication tokens

Frontend

Technology Version Purpose
Vue 3.5+ UI framework
TypeScript 5.8+ Type safety
Vite 6 Build tool
Element Plus 2.9+ UI component library
TailwindCSS 4 Utility CSS
Pinia 3 State management
Vue Router 4 Routing
VxeTable 4.6 Advanced table component
ECharts 5 Charts
Axios 1.9 HTTP client

πŸš€ Getting Started

Prerequisites

  • Rust (latest stable, edition 2024 support)
  • Node.js ^18.18.0 || ^20.9.0 || >=22.0.0
  • pnpm >=9
  • Redis server running on localhost:6379

1. Clone the Repository

git clone <your-repo-url>
cd rust-admin

2. Start the Backend

cd backend

# Configure the database and Redis (edit config/config.toml if needed)
# The default config uses SQLite (auto-created) and localhost Redis

# Run database migrations and start the server
cargo run

The API server starts at http://127.0.0.1:3000.

3. Start the Frontend

cd frontend

# Install dependencies
pnpm install

# Start the dev server
pnpm dev

The frontend dev server starts (port configured in .env), with /api requests proxied to http://127.0.0.1:3000.

Note: Run the backend and frontend in separate terminal sessions.

πŸ“‘ API Endpoints

All API endpoints are prefixed with /api. Protected routes require a Bearer token in the Authorization header.

Module Endpoint Pattern Description
Auth POST /api/token Login
Auth GET /api/token/logout Logout
Auth GET /api/token/refresh/{refresh_token} Refresh token
Auth GET /api/token/check_token Validate token
User GET /api/sysUser/getPage Users (paginated)
User POST/GET/PUT/DELETE /api/sysUser[/{id}] User CRUD
User PUT /api/sysUser/resetPwd Reset password
User PUT /api/sysUser/enable Toggle user enabled
Role GET /api/sysRole/getPage Roles (paginated)
Role POST/GET/PUT/DELETE /api/sysRole[/{id}] Role CRUD
Menu GET /api/sysMenu/tree Menu tree
Menu GET /api/sysMenu/user-menu Current user's menus
Menu POST/GET/PUT/DELETE /api/sysMenu[/{id}] Menu CRUD
Org GET /api/sysOrg/tree Organization tree
Org POST/GET/PUT/DELETE /api/sysOrg[/{id}] Org CRUD
Dict GET /api/sysDict/getPage Dictionaries (paginated)
Dict POST/GET/PUT/DELETE /api/sysDict[/{id}] Dict CRUD
Dict Item GET /api/sysDictItem/getByType Items by type
Dict Item POST/GET/PUT/DELETE /api/sysDictItem[/{id}] Dict Item CRUD
Log GET /api/sysLog/getPage Logs (paginated)
Log POST/GET/PUT/DELETE /api/sysLog[/{id}] Log CRUD
Auth Config GET /api/sysAuth/getMenuData/{role_code} Role menu data
Auth Config POST /api/sysAuth/setMenuAuth Set menu permissions

πŸ§ͺ Testing

Backend

cd backend

# Run all tests
cargo test

# Run a specific test module
cargo test --test user_service_tests
cargo test --test role_api_tests
cargo test --test auth_service_tests

# Run a single test by name
cargo test -- <test_name>

Tests use UUID-based temporary SQLite database files that are automatically created and cleaned up.

Frontend

cd frontend

# Lint (required before commit)
pnpm lint

# Type checking
pnpm typecheck

Note: No frontend test framework is currently configured.

πŸ”§ Configuration

Backend (backend/config/config.toml)

jwt_secret = "your-secret-key"
database_url = "sqlite:data/users.db?mode=rwc"  # Adjust path to your environment

[server]
host = "127.0.0.1"
port = 3000

[redis]
host = "localhost"
port = 6379
password = "123456"

Frontend (frontend/vite.config.ts)

The dev server proxies /api β†’ http://127.0.0.1:3000 for seamless backend integration.

πŸ“ Code Quality

Backend

cd backend
cargo fmt && cargo fmt -- --check   # Format check
cargo clippy -- -D warnings         # Lint (zero warnings)

Frontend

cd frontend
pnpm lint              # Run all linters (ESLint + Prettier + Stylelint)
pnpm lint:eslint       # Lint JS/TS/Vue only
pnpm lint:prettier     # Format code
pnpm lint:stylelint    # Lint CSS/SCSS
pnpm typecheck         # TypeScript type checking

Husky + lint-staged automatically run linters on commit.

🐳 Docker Deployment

The frontend includes Docker support for containerized deployment:

cd frontend

# Build and run with Docker Compose
docker-compose up --build

See frontend/Dockerfile and frontend/docker-compose.yml for configuration details.

πŸ“¦ Production Build

Backend

cd backend
cargo build --release    # Output β†’ target/release/x-rust

Frontend

cd frontend
pnpm build               # Output β†’ dist/

πŸ“„ License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages