TASK-001: Setup FastAPI project structure
This commit is contained in:
199
README.md
199
README.md
@@ -1,151 +1,62 @@
|
||||
# SocialPhoto - Instagram Clone
|
||||
# Instagram Clone API
|
||||
|
||||
A simple Instagram clone API built with FastAPI and SQLite.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### 1. Install dependencies
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 2. Run the server
|
||||
|
||||
```bash
|
||||
cd app
|
||||
uvicorn main:app --reload --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
Or from the root directory:
|
||||
|
||||
```bash
|
||||
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
|
||||
```
|
||||
|
||||
### 3. Access API docs
|
||||
|
||||
Open your browser to: http://localhost:8000/docs
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Authentication
|
||||
|
||||
```bash
|
||||
# Register
|
||||
curl -X POST http://localhost:8000/auth/register \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"test","email":"test@test.com","password":"password123"}'
|
||||
|
||||
# Login
|
||||
curl -X POST http://localhost:8000/auth/login \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"username":"test","password":"password123"}'
|
||||
```
|
||||
|
||||
### Posts
|
||||
|
||||
```bash
|
||||
# Create post (requires auth token)
|
||||
curl -X POST http://localhost:8000/posts \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-F "caption=My first post" \
|
||||
-F "image=@photo.jpg"
|
||||
|
||||
# Get all posts
|
||||
curl http://localhost:8000/posts
|
||||
|
||||
# Get single post
|
||||
curl http://localhost:8000/posts/1
|
||||
|
||||
# Like a post
|
||||
curl -X POST http://localhost:8000/posts/1/like \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
|
||||
# Delete post (owner only)
|
||||
curl -X DELETE http://localhost:8000/posts/1 \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
```
|
||||
|
||||
### Users
|
||||
|
||||
```bash
|
||||
# Get user profile
|
||||
curl http://localhost:8000/users/1
|
||||
|
||||
# Get user posts
|
||||
curl http://localhost:8000/users/1/posts
|
||||
|
||||
# Get user stats
|
||||
curl http://localhost:8000/users/1/stats
|
||||
|
||||
# Follow user
|
||||
curl -X POST http://localhost:8000/users/1/follow \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
|
||||
# Unfollow user
|
||||
curl -X DELETE http://localhost:8000/users/1/follow \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
```
|
||||
|
||||
### Comments
|
||||
|
||||
```bash
|
||||
# Add comment
|
||||
curl -X POST http://localhost:8000/posts/1/comments \
|
||||
-H "Authorization: Bearer YOUR_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"content":"Great post!"}'
|
||||
|
||||
# Get comments
|
||||
curl http://localhost:8000/posts/1/comments
|
||||
|
||||
# Delete comment (owner only)
|
||||
curl -X DELETE http://localhost:8000/comments/1 \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
```
|
||||
|
||||
### Feed
|
||||
|
||||
```bash
|
||||
# Get followed users feed (requires auth)
|
||||
curl http://localhost:8000/feed \
|
||||
-H "Authorization: Bearer YOUR_TOKEN"
|
||||
|
||||
# Get global feed
|
||||
curl http://localhost:8000/feed/global
|
||||
```
|
||||
|
||||
## Running Tests
|
||||
|
||||
```bash
|
||||
pytest tests/ -v
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
app/
|
||||
├── main.py # FastAPI application
|
||||
├── database.py # SQLite database setup
|
||||
├── models.py # Pydantic models
|
||||
├── auth.py # JWT authentication
|
||||
└── routes/
|
||||
├── auth.py # Auth endpoints
|
||||
├── users.py # User endpoints
|
||||
├── posts.py # Post endpoints
|
||||
├── comments.py # Comment endpoints
|
||||
└── feed.py # Feed endpoints
|
||||
```
|
||||
A FastAPI-based Instagram clone API with SQLAlchemy 2.0 and Alembic migrations.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- **Framework**: FastAPI 0.109+
|
||||
- **Database**: SQLite
|
||||
- **Auth**: JWT (python-jose)
|
||||
- **Password Hashing**: bcrypt
|
||||
- **Testing**: pytest
|
||||
- **ORM**: SQLAlchemy 2.0
|
||||
- **Database**: SQLite (dev), PostgreSQL (prod)
|
||||
- **Migrations**: Alembic
|
||||
- **Testing**: pytest + httpx
|
||||
|
||||
## License
|
||||
## Project Structure
|
||||
|
||||
MIT
|
||||
```
|
||||
instagram-clone/
|
||||
├── app/
|
||||
│ ├── api/
|
||||
│ │ ├── endpoints/ # API route handlers
|
||||
│ │ └── dependencies/ # FastAPI dependencies
|
||||
│ ├── core/ # Configuration and settings
|
||||
│ ├── db/ # Database connection and models
|
||||
│ ├── models/ # SQLAlchemy models
|
||||
│ ├── schemas/ # Pydantic schemas
|
||||
│ ├── services/ # Business logic
|
||||
│ └── utils/ # Utility functions
|
||||
├── alembic/ # Database migrations
|
||||
├── tests/
|
||||
│ ├── unit/ # Unit tests
|
||||
│ └── integration/ # Integration tests
|
||||
├── pyproject.toml
|
||||
└── alembic.ini
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
pip install -e ".[dev]"
|
||||
|
||||
# Run database migrations
|
||||
alembic upgrade head
|
||||
|
||||
# Run the application
|
||||
uvicorn app.main:app --reload
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Run all tests
|
||||
pytest
|
||||
|
||||
# Run with coverage
|
||||
pytest --cov=app tests/
|
||||
```
|
||||
|
||||
## API Documentation
|
||||
|
||||
Once running, visit:
|
||||
- Swagger UI: http://localhost:8000/docs
|
||||
- ReDoc: http://localhost:8000/redoc
|
||||
|
||||
Reference in New Issue
Block a user