Documentation
How this application works and how to run it.
Local Setup
Prerequisites:
- Python 3.8+
- MySQL 8.0+ (or use Docker for MySQL)
- pip (Python package manager)
Steps:
- Clone the repository
- Create a virtual environment:
python -m venv venv - Activate the virtual environment:
- Windows:
venv\Scripts\activate - Linux/Mac:
source venv/bin/activate
- Windows:
- Install dependencies:
pip install -r requirements.txt - Create a
.envfile with database credentials - Set up the MySQL database and create the notes table
- Run the Flask app:
python app.py - Access the application at
http://localhost:5000
Docker Setup
Prerequisites:
- Docker Desktop installed
- Docker Compose (included with Docker Desktop)
Quick Start:
- Create a
.envfile in the project root with:DB_HOST=mysql DB_USER=root DB_PASSWORD=rootpassword DB_NAME=devops_notes MYSQL_ROOT_PASSWORD=rootpassword - Build and start containers:
docker compose up --build - Initialize the database (one-time setup):
docker exec -it devops-mysql mysql -uroot -prootpassword devops_notes# Then run SQL:
CREATE TABLE notes ( id INT AUTO_INCREMENT PRIMARY KEY, command VARCHAR(255) NOT NULL, description TEXT NOT NULL, category VARCHAR(50), tags VARCHAR(255), example TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ); - Access the application at
http://localhost:5000
Useful Commands:
- Stop containers:
docker compose down - Stop and remove volumes:
docker compose down -v - View logs:
docker compose logs -f - Rebuild after changes:
docker compose up --build
DevOps Concepts Practiced
This project demonstrates:
- Containerization: Application and database run in isolated Docker containers
- Service Orchestration: Docker Compose manages multi-container setup
- Environment Variables: Secure configuration using
.envfiles - Persistent Storage: Docker volumes for database data persistence
- Service Discovery: Containers communicate via Docker network
Database Schema
The application uses a MySQL database with the following table structure:
CREATE TABLE notes (
id INT AUTO_INCREMENT PRIMARY KEY,
command VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
category VARCHAR(50),
tags VARCHAR(255),
example TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
Fields:
id: Primary key, auto-incrementingcommand: The DevOps command or operation namedescription: Detailed explanation (HTML formatted)category: Predefined category for organization
REST API Usage
The application now supplies a REST API for programmatic access to your notes.
Authentication:
All API requests require an X-API-Token header. You can generate your token in the Settings page.
curl -H "X-API-Token: YOUR_TOKEN" http://localhost/api/notes
Endpoints:
GET /api/notes- List all notes (supports -category=X&search=Y)GET /api/notes/<id>- Get a single notePOST /api/notes- Create a new note (JSON body required)GET /api/categories- List all available categories
Example Creation:
curl -X POST http://localhost/api/notes \
-H "X-API-Token: YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"command": "ls -la", "description": "List all files", "category": "Linux"}'