FastAPI-based REST API for the X Clone (Twitter clone) application.
- 🔐 Authentication: JWT-based authentication with access and refresh tokens
- 📧 Email Verification: Required email verification before login
- 🔑 Password Reset: Secure password reset via email
- 👤 User Management: User profiles and account management
- 🐘 PostgreSQL: Async database with SQLAlchemy 2.0
- 📝 Migrations: Database migrations with Alembic
- Framework: FastAPI
- Database: PostgreSQL with asyncpg
- ORM: SQLAlchemy 2.0 (async)
- Migrations: Alembic
- Auth: JWT (python-jose) + bcrypt
- Email: FastAPI-Mail
- Validation: Pydantic v2
- Python 3.11+
- PostgreSQL
- UV package manager
-
Install dependencies using UV:
cd server uv sync -
Configure environment variables:
cp .env.example .env # Edit .env with your configuration -
Create the database:
CREATE DATABASE x_clone;
-
Run database migrations:
uv run alembic upgrade head
-
Start the development server:
uv run uvicorn app.main:app --reload --port 8000
When running in debug mode, API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/register |
Register new user |
| POST | /api/v1/auth/login |
Login and get tokens |
| POST | /api/v1/auth/refresh |
Refresh access token |
| POST | /api/v1/auth/logout |
Logout (revoke refresh token) |
| POST | /api/v1/auth/verify-email |
Verify email address |
| POST | /api/v1/auth/resend-verification |
Resend verification email |
| POST | /api/v1/auth/forgot-password |
Request password reset |
| POST | /api/v1/auth/reset-password |
Reset password |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/users/me |
Get current user profile |
server/
├── alembic/ # Database migrations
├── app/
│ ├── api/ # API routes
│ │ └── v1/
│ │ └── endpoints/ # Route handlers
│ ├── core/ # Core utilities
│ ├── db/ # Database configuration
│ ├── models/ # SQLAlchemy models
│ ├── repositories/ # Data access layer
│ ├── schemas/ # Pydantic schemas
│ ├── services/ # Business logic
│ └── main.py # Application entry point
├── .env # Environment variables
├── alembic.ini # Alembic configuration
└── pyproject.toml # Project dependencies
uv run alembic revision --autogenerate -m "Description of changes"uv run alembic upgrade headuv run alembic downgrade -1