Skip to content

8adiq/chatr

Repository files navigation

Chatr - Full Stack Social Media Application

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.

🌐 Live Demo

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.


✨ Features

Core 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

Technical Features

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   Database      β”‚
β”‚   (React)       │◄──►│   (FastAPI)     │◄──►│   (PostgreSQL)  β”‚
β”‚   Container     β”‚    β”‚   Container     β”‚    β”‚   (Render)      β”‚
β”‚   Nginx         β”‚    β”‚   Uvicorn       β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

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

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Docker & Docker Compose
  • Git

Option 1: Docker Setup (Recommended)

  1. Clone the repository:

    git clone <repository-url>
    cd auth-app-fastapi
  2. 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
  3. Run with Docker Compose:

    docker-compose up --build
  4. Access the application:

Option 2: Direct Setup

Backend Setup

# 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 8000

Frontend Setup

cd auth-app-frontend
npm install
npm run dev

🐳 Docker Configuration

Backend Container

  • Base Image: Python 3.10.11-slim
  • Server: Uvicorn
  • Port: 8000
  • Database: PostgreSQL (production) / SQLite (development)

Frontend Container

  • Build Stage: Node.js 18-alpine
  • Production Stage: Nginx alpine
  • Port: 80 (mapped to 3000)
  • Features: Multi-stage build, static file serving, API proxying

Docker Compose

  • Backend Service: FastAPI application
  • Frontend Service: React app with Nginx
  • Environment: Shared environment variables
  • Networking: Internal service communication

☁️ Production Deployment

Render Platform

  • Backend: Docker container deployment
  • Frontend: Static site deployment
  • Database: PostgreSQL hosted on Render
  • CI/CD: Automatic deployment from GitHub

Environment Variables (Production)

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

Deployment Process

  1. Connect GitHub repository to Render
  2. Configure environment variables
  3. Deploy using render.yaml blueprint
  4. Verify health checks and functionality

πŸ“š API Documentation

Authentication

  • POST /api/register β€” Register a new user
  • POST /api/login β€” Log in and receive JWT token

User Management

  • GET /api/profile β€” Get current user profile (requires Authorization: Bearer <token>)

Social Features

  • 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

Health Check

  • GET /health β€” Application health status

πŸ—„οΈ Database Management

Migration Commands

# 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 history

πŸ§ͺ Testing

Run the test suite:

python app/test.py

The test suite covers:

  • User registration and authentication
  • JWT token validation
  • Protected endpoint access
  • Social features (posts, comments, likes)
  • Error handling and edge cases

πŸ”§ Development

Local Development

  • Use Docker Compose for consistent environment
  • Hot reload enabled for both frontend and backend
  • SQLite database for development
  • CORS configured for localhost

Production Development

  • PostgreSQL database
  • Environment-specific configurations
  • Health checks and monitoring
  • Optimized Docker images

πŸ“‹ Best Practices

Security

  • Environment variables for sensitive data
  • Password hashing with bcrypt
  • JWT token expiration
  • CORS configuration
  • Input validation with Pydantic

Performance

  • Database indexing
  • Pagination for large datasets
  • Docker multi-stage builds
  • Nginx caching
  • Connection pooling

πŸ“– Documentation

For comprehensive documentation including:

  • Detailed setup instructions
  • Troubleshooting guide
  • Architecture explanations
  • Best practices

See: PROJECT_DOCUMENTATION.md


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.


πŸ†˜ Support

For issues and questions:

  1. Check the PROJECT_DOCUMENTATION.md
  2. Review the troubleshooting section
  3. Check Render deployment logs
  4. Test locally with Docker Compose

Last updated: August 2024

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors