A backend service for the Rust Learning App built with Rust, Axum, Askama, and PostgreSQL using Domain-Driven Design (DDD) principles.
- Framework: Axum (async web framework)
- Database: PostgreSQL with SQLx
- Templates: Askama (for admin dashboard)
- Authentication: JWT tokens with Argon2 password hashing
- Architecture: Domain-Driven Design (DDD)
- User authentication and authorization
- Topics, lessons, questions, and code practices management
- User progress tracking
- Leaderboard system
- Admin dashboard (Askama templates)
- RESTful API
src/
├── domain/ # Domain layer (DDD)
│ ├── entities/ # Domain entities
│ ├── value_objects/ # Value objects
│ ├── repositories/ # Repository interfaces
│ └── services/ # Domain services
├── application/ # Application layer
│ ├── use_cases/ # Use cases
│ ├── dtos/ # Data transfer objects
│ └── interfaces/ # Application interfaces
├── infrastructure/ # Infrastructure layer
│ ├── database/ # Database models and connection
│ ├── repositories/ # Repository implementations
│ └── external_services/ # External service integrations
├── presentation/ # Presentation layer
│ ├── api/ # REST API handlers
│ ├── web/ # Web dashboard handlers
│ └── handlers/ # Shared handlers
└── shared/ # Shared utilities
├── config/ # Configuration
├── errors/ # Error handling
└── utils/ # Utility functions
- Rust 1.75+
- PostgreSQL 15+
- Docker (optional)
-
Clone and navigate to backend directory:
cd backend -
Install dependencies:
cargo build
-
Set up environment variables:
cp env.example .env # Edit .env with your configuration -
Start PostgreSQL (using Docker):
docker-compose up postgres -d
-
Run migrations:
cargo run --bin migrate
-
Start the server:
cargo run
# Start all services
docker-compose up
# Start in background
docker-compose up -d
# View logs
docker-compose logs -f backendPOST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/refresh- Refresh token
GET /api/topics- List all topicsGET /api/topics/{id}- Get topic by IDGET /api/lessons- List lessonsGET /api/lessons/{id}- Get lesson by IDGET /api/questions- List questionsGET /api/questions/{id}- Get question by IDGET /api/code-practices- List code practicesGET /api/code-practices/{id}- Get code practice by ID
GET /api/progress- Get user progressPOST /api/progress/questions- Submit question resultPOST /api/progress/code-practices- Submit code practice resultGET /api/leaderboard- Get leaderboard
GET /admin- Admin dashboardGET /admin/topics- Manage topicsGET /admin/lessons- Manage lessonsGET /admin/questions- Manage questionsGET /admin/users- Manage users
The database includes the following main tables:
users- User accounts and authenticationtopics- Learning topics with localized contentlessons- Individual lessons within topicsquestions- Quiz questions with various typescode_practices- Hands-on coding exercisesuser_progress- User progress trackingquestion_results- Individual question resultslesson_results- Lesson completion resultscompleted_code_practices- Code practice completionsleaderboard- Weekly and all-time rankings
# Run the development setup script
./scripts/setup-dev.sh
# Or use make commands
make install# Run all tests
make test
# Run tests in watch mode
make test-watch
# Run specific test
cargo test test_name# Run all quality checks
make check
# Format code
make format
# Run linter
make lint
# Run pre-commit hooks
make pre-commit# Create new migration
make migrate-create NAME=migration_name
# Run migrations
make migrate
# Reset database (WARNING: deletes all data)
make db-reset# Start development environment with Docker
make dev
# Or manually
make docker-up
cargo run| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | postgres://postgres:password@localhost:5432/rust_learning |
JWT_SECRET |
Secret key for JWT tokens | your-secret-key-change-in-production |
SERVER_HOST |
Server host | 0.0.0.0 |
SERVER_PORT |
Server port | 3000 |
CORS_ORIGINS |
Allowed CORS origins | http://localhost:3000,http://localhost:3001 |
RUST_LOG |
Log level | debug |
- Follow DDD principles
- Write tests for new features
- Update documentation
- Follow Rust conventions
- Use meaningful commit messages
This project is part of the Rust Learning App.