Files
instagram-clone/README.md
OpenClaw Agent a3eca3b7da feat: implement Instagram clone SocialPhoto API
- FastAPI backend with SQLite database
- JWT authentication (register, login)
- User profiles with follow/unfollow
- Posts with image upload and likes/dislikes
- Comments with likes
- Global and personalized feed
- Comprehensive pytest test suite (37 tests)

TASK-ID: 758f4029-702
2026-04-16 03:20:48 +00:00

3.0 KiB

SocialPhoto - Instagram Clone

A simple Instagram clone API built with FastAPI and SQLite.

Quick Start

1. Install dependencies

pip install -r requirements.txt

2. Run the server

cd app
uvicorn main:app --reload --host 0.0.0.0 --port 8000

Or from the root directory:

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

# 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

# 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

# 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

# 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

# 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

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

Tech Stack

  • Framework: FastAPI 0.109+
  • Database: SQLite
  • Auth: JWT (python-jose)
  • Password Hashing: bcrypt
  • Testing: pytest

License

MIT