A robust RESTful API for event scheduling with collaborative editing features, built with FastAPI.
- Secure authentication with JWT tokens
- Role-based access control (Owner, Editor, Viewer)
- CRUD operations for events
- Recurring events with customizable patterns
- Conflict detection for overlapping events
- Batch operations for creating multiple events
- Sharing system with granular permissions
- Real-time notifications
- Edit history tracking
- Version control with rollback capability
- Changelog with diff visualization
- Event conflict resolution
- Transaction system for atomic operations
- Rate limiting for API endpoints
- OpenTelemetry integration for distributed tracing
- Health check endpoint
- CORS support
- Comprehensive error handling
- FastAPI 0.104.1
- SQLAlchemy 2.0.23
- PostgreSQL
- Redis for caching and rate limiting
- OpenTelemetry for distributed tracing
- Alembic for database migrations
- Pydantic for data validation
- JWT for authentication
Below is a step-by-step plan to set up the PostgreSQL database, Redis, and the Python environment for the Event Scheduling API.
-
PostgreSQL Setup
-- Connect to PostgreSQL as superuser brew services start postgresql or install postgres psql -U postgres
-- Create database user CREATE USER event_scheduler_user WITH PASSWORD 'event_password';
-- Create database CREATE DATABASE event_scheduler;
-- Grant privileges GRANT ALL PRIVILEGES ON DATABASE event_scheduler TO event_scheduler_user;
-
Redis Setup
brew install redis
brew services start redis
-
Python Environment Setup
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
-
Environment Configuration
cp .env.example .env
DATABASE_URL=postgresql://event_scheduler_user:event_password@localhost:5432/event_scheduler SECRET_KEY=49938093a51aff6862f945644edf5987662c79b44dadaea1a3ec9e4b6244f603 ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=30 REFRESH_TOKEN_EXPIRE_DAYS=7 REDIS_URL=redis://localhost:6379 RATE_LIMIT_PER_MINUTE=60 ALLOWED_ORIGINS=http://localhost:3000
-
Database Migration
alembic upgrade head
-
Start the Application
uvicorn app.main:app --reload
Once the server starts, you can access:
- API: http://localhost:8000
- Swagger Documentation: http://localhost:8000/docs
- ReDoc Documentation: http://localhost:8000/redoc
app/
├── alembic/ # Database migrations
│ └── v1/ # API version 1
├── api/ # API endpoints
├── core/ # Core functionality and configuration
├── db/ # Database models and session
├── middleware/ # Custom middleware (auth, rate limiting, tracing)
├── schemas/ # Pydantic models
├── services/ # Business logic
└── utils/ # Utility functions
-
GET /: Welcome message and documentation links -
GET /health: Health check endpoint- /api/v1/auth/register
- /api/v1/auth/login
- /api/v1/auth/refresh
- /api/v1/auth/logout
POST /api/v1/events: Create eventGET /api/v1/events: List eventsGET /api/v1/events/{event_id}: Get event detailsPUT /api/v1/events/{event_id}: Update eventDELETE /api/v1/events/{event_id}: Delete eventPOST /api/v1/events/{event_id}/share: Share eventPOST /api/v1/events/batch: Create multiple events at once
PUT /api/v1/events/{event_id}/permissions/{user_id}: Update a user's permission for an eventDELETE /api/v1/events/{event_id}/permissions/{user_id}: Remove a user's access to an eventGET /api/v1/events/{event_id}/permissions: Get all permissions for an event
GET /api/v1/events/{event_id}/history: Get full version history of an eventGET /api/v1/events/{event_id}/history/{version_id}: Get a specific version of an eventGET /api/v1/events/{event_id}/versions: List all versions (paginated)GET /api/v1/events/{event_id}/versions/{version_number}: Get a specific versionPOST /api/v1/events/{event_id}/rollback/{version_id}: Roll back to a previous versionGET /api/v1/events/{event_id}/versions: List all versions (paginated)GET /api/v1/events/{event_id}/versions/{version_number}: Get a specific versionPOST /api/v1/events/{event_id}/rollback/{version_id}: Roll back to a previous versionGET /api/v1/events/{event_id}/changelog: Get change log of event
- JWT-based authentication
- Role-based access control
- Rate limiting
- CORS protection
- Input validation
- Secure password hashing
- OpenTelemetry integration for distributed tracing
- Health check endpoint
- Comprehensive error handling
- Request/Response logging
MIT