A modern full-stack social media application built with FastAPI (backend) and React (frontend), fully containerized with Docker and deployed on Render. Features user authentication, social interactions, and a responsive modern UI.
Frontend: https://auth-app-frontend-rh30.onrender.com
Backend API: https://auth-app-backend-udya.onrender.com
API Documentation: https://auth-app-backend-udya.onrender.com/docs
Experience the full application with user registration, authentication, and social features.
- User Authentication: Registration and login with JWT tokens
- Social Features: Posts, comments, and likes system
- User Profiles: Protected profile endpoints
- Modern UI: Responsive React frontend with Vite
- Containerized: Full Docker support for development and production
- Database Migrations: Alembic-based migration system
- CORS Enabled: Cross-origin communication between services
- Production Ready: Deployed on Render with PostgreSQL
- Health Checks: Built-in monitoring endpoints
- Security: Password hashing with bcrypt, JWT authentication
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │ │ Backend │ │ Database │
│ (React) │◄──►│ (FastAPI) │◄──►│ (PostgreSQL) │
│ Container │ │ Container │ │ (Render) │
│ Nginx │ │ Uvicorn │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
auth-app-fastapi/
├── app/ # FastAPI backend application
│ ├── __init__.py
│ ├── main.py # FastAPI app entry point
│ ├── database/
│ │ ├── __init__.py
│ │ └── main.py # Database configuration
│ ├── users/ # User management module
│ │ ├── __init__.py
│ │ ├── models.py # User SQLAlchemy model
│ │ ├── routes.py # User API endpoints
│ │ ├── schema.py # User Pydantic schemas
│ │ └── service.py # User business logic
│ ├── posts/ # Posts module
│ │ ├── __init__.py
│ │ ├── models.py # Post SQLAlchemy model
│ │ ├── routes.py # Post API endpoints
│ │ ├── schema.py # Post Pydantic schemas
│ │ └── service.py # Post business logic
│ ├── comments/ # Comments module
│ │ ├── __init__.py
│ │ ├── models.py # Comment SQLAlchemy model
│ │ ├── routes.py # Comment API endpoints
│ │ ├── schema.py # Comment Pydantic schemas
│ │ └── service.py # Comment business logic
│ ├── likes/ # Likes module
│ │ ├── __init__.py
│ │ ├── models.py # Like SQLAlchemy model
│ │ ├── routes.py # Like API endpoints
│ │ ├── schema.py # Like Pydantic schemas
│ │ └── service.py # Like business logic
│ └── auth/ # Authentication module
│ ├── __init__.py
│ ├── routes.py # Auth API endpoints
│ ├── schema.py # Auth Pydantic schemas
│ └── service.py # Auth business logic
├── auth-app-frontend/ # React frontend application
│ ├── public/
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── hooks/ # Custom React hooks
│ │ ├── lib/ # Utility libraries
│ │ ├── utils/ # Helper functions
│ │ ├── api.js # API client configuration
│ │ ├── App.jsx # Main React component
│ │ └── main.jsx # React entry point
│ ├── Dockerfile # Frontend Docker configuration
│ ├── nginx.conf # Nginx configuration
│ ├── package.json # Node.js dependencies
│ └── vite.config.js # Vite configuration
├── migrations/ # Database migrations
│ ├── env.py
│ ├── script.py.mako
│ └── versions/ # Migration files
├── Dockerfile # Backend Docker configuration
├── docker-compose.yaml # Local development orchestration
├── render.yaml # Production deployment blueprint
├── requirements.txt # Python dependencies
├── alembic.ini # Alembic configuration
├── manage_migrations.py # Migration management script
├── reset_database.py # Database reset utility
├── .dockerignore # Docker build exclusions
├── .gitignore # Git exclusions
├── PROJECT_DOCUMENTATION.md # Comprehensive documentation
└── README.md # This file
- Python 3.10+
- Node.js 18+
- Docker & Docker Compose
- Git
-
Clone the repository:
git clone <repository-url> cd auth-app-fastapi
-
Create environment file:
# Create .env file in root directory echo "DATABASE_URL=sqlite:///users.db SECRET_KEY=your-secret-key-here CORS_ALLOWED_ORIGINS=http://localhost:5173 ACCESS_TOKEN_EXPIRES_MINUTES=30 ACCESS_TOKEN_EXPIRES_DAYS=7" > .env
-
Run with Docker Compose:
docker-compose up --build
-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
# Create virtual environment
python -m venv fenv
source fenv/bin/activate # On Windows: fenv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export DATABASE_URL="sqlite:///users.db"
export SECRET_KEY="your-secret-key-here"
export CORS_ALLOWED_ORIGINS="http://localhost:5173"
# Run migrations
python manage_migrations.py init
python manage_migrations.py migrate "Initial migration"
python manage_migrations.py upgrade
# Start backend
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000cd auth-app-frontend
npm install
npm run dev- Base Image: Python 3.10.11-slim
- Server: Uvicorn
- Port: 8000
- Database: PostgreSQL (production) / SQLite (development)
- Build Stage: Node.js 18-alpine
- Production Stage: Nginx alpine
- Port: 80 (mapped to 3000)
- Features: Multi-stage build, static file serving, API proxying
- Backend Service: FastAPI application
- Frontend Service: React app with Nginx
- Environment: Shared environment variables
- Networking: Internal service communication
- Backend: Docker container deployment
- Frontend: Static site deployment
- Database: PostgreSQL hosted on Render
- CI/CD: Automatic deployment from GitHub
DATABASE_URL=postgresql://user:pass@host/db
SECRET_KEY=your-production-secret-key
CORS_ALLOWED_ORIGINS=http://localhost:5173,https://auth-app-frontend-rh30.onrender.com
ACCESS_TOKEN_EXPIRES_MINUTES=30
ACCESS_TOKEN_EXPIRES_DAYS=7- Connect GitHub repository to Render
- Configure environment variables
- Deploy using
render.yamlblueprint - Verify health checks and functionality
POST /api/register— Register a new userPOST /api/login— Log in and receive JWT token
GET /api/profile— Get current user profile (requiresAuthorization: Bearer <token>)
-
GET /api/posts— Get all posts -
POST /api/posts— Create a new post (requires authentication) -
GET /api/posts/{post_id}— Get specific post -
PUT /api/posts/{post_id}— Update post (requires ownership) -
DELETE /api/posts/{post_id}— Delete post (requires ownership) -
POST /api/posts/{post_id}/comments— Add comment to post -
GET /api/posts/{post_id}/comments— Get comments for post -
PUT /api/comments/{comment_id}— Update comment (requires ownership) -
DELETE /api/comments/{comment_id}— Delete comment (requires ownership) -
POST /api/posts/{post_id}/like— Like/unlike a post -
GET /api/posts/{post_id}/likes— Get likes for a post
GET /health— Application health status
# Initialize migrations (first time only)
python manage_migrations.py init
# Create new migration
python manage_migrations.py migrate "Description of changes"
# Apply migrations
python manage_migrations.py upgrade
# Rollback migration
python manage_migrations.py downgrade
# Check current migration
python manage_migrations.py current
# View migration history
python manage_migrations.py historyRun the test suite:
python app/test.pyThe test suite covers:
- User registration and authentication
- JWT token validation
- Protected endpoint access
- Social features (posts, comments, likes)
- Error handling and edge cases
- Use Docker Compose for consistent environment
- Hot reload enabled for both frontend and backend
- SQLite database for development
- CORS configured for localhost
- PostgreSQL database
- Environment-specific configurations
- Health checks and monitoring
- Optimized Docker images
- Environment variables for sensitive data
- Password hashing with bcrypt
- JWT token expiration
- CORS configuration
- Input validation with Pydantic
- Database indexing
- Pagination for large datasets
- Docker multi-stage builds
- Nginx caching
- Connection pooling
For comprehensive documentation including:
- Detailed setup instructions
- Troubleshooting guide
- Architecture explanations
- Best practices
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the PROJECT_DOCUMENTATION.md
- Review the troubleshooting section
- Check Render deployment logs
- Test locally with Docker Compose
Last updated: August 2024