Backend web application for managing students with Django.
- CRUD API for students
- PostgreSQL database
- Docker Compose setup
- Correlation-ID middleware for logging
- Request counter middleware (total, 2xx, 4xx, 5xx)
- Latency measurement decorator with histogram storage
- Health check endpoint
- Integration tests
- Ruff linting configuration
- Docker and Docker Compose
- Python 3.11+ (for local development)
-
Copy
.env.exampleto.envand adjust settings if needed:cp .env.example .env
-
Build and start containers:
docker-compose up --build
-
The API will be available at
http://localhost
GET /health- Health check endpoint (returns 200)
POST /students- Create a new studentGET /students- Get all studentsGET /students/{id}- Get student by idPUT /students/{id}- Update student
curl -X POST http://localhost/students \
-H "Content-Type: application/json" \
-d '{
"name": "Иван Иванов",
"age": 20,
"email": "ivan@example.com"
}'curl http://localhost/studentscurl http://localhost/students/1curl -X PUT http://localhost/students/1 \
-H "Content-Type: application/json" \
-d '{
"name": "Иван Иванович",
"age": 21,
"email": "ivan_updated@example.com"
}'docker-compose exec web python manage.py testdocker-compose exec web ruff check ..
├── exam/ # Django project settings
│ ├── config.py # Configuration module for environment variables
│ ├── settings.py # Django settings
│ └── urls.py # URL configuration
├── myapp/ # Main application
│ ├── models.py # Student model and monitoring models
│ ├── views.py # API views
│ ├── serializers.py # Data validation
│ ├── middleware/ # Custom middleware
│ │ ├── correlation_id.py
│ │ ├── request_counter.py
│ │ └── latency.py
│ └── tests.py # Integration tests
├── nginx/ # Nginx configuration
├── Dockerfile # Web container definition
├── docker-compose.yml # Docker Compose configuration
└── requirements.txt # Python dependencies
- db: PostgreSQL database
- web: Django application (Gunicorn)
- nginx: Reverse proxy (port 80)
All containers run health checks and do not run as root user.
sudo systemctl stop nginxsudo service nginx stopsudo lsof -i :80wsl -e bash -c "cd /mnt/m/prep_kval/EXAM && docker-compose exec web python manage.py createsuperuser"