Skip to content

debil746429/notepadAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NotepadAPI

A simple notepad api project focuse on minimal CRUD principles. The moment i was crafting this project, my focus was to learn SOLID principles in a simple implemenation of minimal project I accept feedback and suggestions you guys can provide me

Feel free to use it, play around with it, and update whatever doesn't suit your needs.

SOLID principles

Principle Implementation in Code
Single Responsibility Each module has one job: notes.py handles HTTP only, note_service.py handles business logic, MySQLRepository.py handles persistence.
Open/Closed Query strategies (query_strategies.py) allow adding new fetch types (e.g., SortedNoteStrategy) without modifying get_notes—new strategies are added by extending, not changing existing code.
Liskov Substitution MySQLRepository implements NoteRepository and can be swapped with another implementation (e.g., PostgreSQLRepository) without breaking consumers.
Interface Segregation NoteReader and NoteWriter are split; DeleteId is separate from Id—clients depend only on the methods they use.
Dependency Inversion Services depend on the abstract NoteRepository, not concrete MySQL—dependency injection via FastAPI Depends().

Features

  • Create note
  • Read note by ID
  • Get notes (all, sorted by desc)
  • Update note
  • Delete note (single or batch)

Requirements

  • Python 3.10+
  • MySQL database
  • FastAPI (with standard dependencies)
  • curl
  • postman

Installation

1. Clone the repository

git clone https://github.com/debil746429/notepadAPI.git
cd notepadAPI

2. Create a virtual environment

On Linux/macOS:

python3 -m venv .venv
source .venv/bin/activate

On Windows:

python -m venv .venv
.venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

Configuration

Database Setup

  1. Create a MySQL database (make sure you don't have a database named notepad if you're using the default configuration)

  2. Update the .env file with your configuration:

# Database Configuration
db_host = localhost
db_name = notepad
db_user = your_database_user
db_password = your_database_password
  1. Import the database schema:
mysql -u your_db_user -p your_database_name < schema.sql

Or manually execute the SQL commands from schema.sql in your MySQL client.

Running the Application

Start the development server:

fastapi dev app/main.py

The API will be available at http://127.0.0.1:8000

API Documentation

Once the server is running, you can view the interactive API documentation at:

Testing

You can test the endpoints using:

  • cURL - Command-line tool for making HTTP requests
  • Postman - API testing and development platform
  • Swagger UI - Interactive documentation at /docs endpoint

Project Structure

notepadAPI/
├── app/
│   ├── api/
│   │   ├── main.py              # API router setup
│   │   └── v1/
│   │       ├── main.py          # v1 router
│   │       └── routes/
│   │           └── notes.py     # Note endpoints
│   ├── core/
│   │   └── config.py            # Settings (env)
│   ├── models/
│   │   └── note.py              # Pydantic models
│   ├── repositories/
│   │   ├── note_repository.py   # Abstract repository interface
│   │   ├── MySQLRepository.py   # MySQL implementation
│   │   └── query_strategies.py  # Query strategy pattern
│   ├── services/
│   │   └── note_service.py      # Business logic
│   └── main.py                  # FastAPI entry point
├── .env
├── requirements.txt
├── schema.sql
├── LICENSE.md
└── README.md

License

See LICENSE.md for details.

Contributing

Feel free to fork this project, make changes, and submit pull requests. This is a learning project, so contributions and improvements are welcome!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages