Perga API
Personal organizer backend that provides the core functionality for the Perga system.
Overview
Perga API is the core of the product, providing a RESTful API for the Perga personal organizer system. It works in conjunction with Perga Web, which is a standalone browser client that connects to the backend to provide a user-friendly web interface.
Features
- Daily planner
- Monthly agenda and backlog
- RESTful API with FastAPI
- User authentication with JWT tokens
- Comprehensive documentation with Swagger UI
Tech Stack
- FastAPI: Modern, fast web framework for building APIs
- SQLAlchemy: SQL toolkit and ORM
- Alembic: Database migration tool
- PostgreSQL: Relational database
- JWT: JSON Web Tokens for authentication
- Pydantic: Data validation and settings management
- Pytest: Testing framework
Installation
Prerequisites
- Python 3.10+
- PostgreSQL 15+
Setup
-
Clone the repository:
git clone https://github.com/dbtiunov/perga-api.git
cd perga-api -
Create a virtual environment and activate it:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file based on.env.example
:cp .env.example .env
-
Update the
.env
file with your specific configuration:- Set a secure
SECRET_KEY
- Configure PostgreSQL connection details
- Set
CORS_ORIGINS
- Set a secure
-
Run database migrations:
alembic upgrade head
-
Start the application:
uvicorn app.main:app --reload
The API will be available at http://localhost:8000 with the Swagger documentation at http://localhost:8000/docs.
Docker Setup
You can also run the application using Docker:
-
Build and start the containers:
docker-compose up -d
-
The API will be available at http://localhost:8080
API Documentation
Once the application is running, you can access the interactive API documentation:
- Swagger UI: http://localhost:8080/docs
- ReDoc: http://localhost:8080/redoc
API Endpoints
Authentication
POST /api/v1/auth/signup/
: Register a new userPOST /api/v1/auth/access_token/
: Get access token (form data)POST /api/v1/auth/access_token_json/
: Get access token (JSON)POST /api/v1/auth/refresh_token/
: Refresh access tokenGET /api/v1/auth/user/
: Get current user informationPUT /api/v1/auth/user/
: Update user information
Planner Days
GET /api/v1/planner/days/
: Get planner items for a specific dayPOST /api/v1/planner/days/
: Add a new item for a specific dayPUT /api/v1/planner/days/{item_id}
: Update a planner day itemDELETE /api/v1/planner/days/{item_id}
: Delete a planner day item
Monthly Agenda and Backlog
GET /api/v1/planner/agendas/
: Get agendas by specific dayGET /api/v1/planner/agendas/{agenda_id}/items
: Get items for a specific agendaPOST /api/v1/planner/agendas/{agenda_id}/items
: Create a new agenda itemPUT /api/v1/planner/agendas/items/{item_id}
: Update an agenda itemDELETE /api/v1/planner/agendas/items/{item_id}
: Delete an agenda item
Development
Project Structure
app/
: Main application packageapi/
: API endpoints and routerscore/
: Core functionality (config, database)models/
: SQLAlchemy modelsschemas/
: Pydantic schemas for request/response validationservices/
: Business logictests/
: Test files
Testing
Run tests with pytest:
python -m pytest
Run specific tests:
python -m pytest app/tests/test_services/test_user_service.py
Database Migrations
Create a new migration:
./scripts/create_migration.sh <migration_name>
Apply migrations:
alembic upgrade head
License
This project is licensed under the MIT License - see the LICENSE file for details.