Skip to content

RakanMirai/Todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ Todo App - Full-Stack Application

A modern full-stack Todo application with FastAPI backend and React frontend, deployable as a single Docker container to AWS Elastic Beanstalk.

✨ Features

  • πŸ” User Authentication - JWT-based auth with access/refresh tokens
  • πŸ‘₯ Role-Based Access - User and Admin roles
  • βœ… Full CRUD Operations - Create, read, update, delete todos
  • πŸ“Š Priority Levels - Low, medium, high priority tasks
  • 🎯 Filtering - View all, active, or completed todos
  • πŸ“± Responsive Design - Works on desktop and mobile
  • πŸ”’ Security - Rate limiting, password hashing, JWT tokens
  • πŸ“š API Documentation - Auto-generated interactive docs

πŸ—οΈ Tech Stack

Backend

  • FastAPI - Modern Python web framework
  • SQLAlchemy - Async ORM
  • PostgreSQL - Production database (SQLite for dev)
  • JWT - Authentication tokens
  • Pydantic - Data validation

Frontend

  • React 18 - UI library
  • React Router - Client-side routing
  • Axios - HTTP client
  • Modern CSS - Styled components

Deployment

  • Docker - Containerization
  • Nginx - Reverse proxy & static file serving
  • AWS Elastic Beanstalk - Hosting platform

πŸ“¦ Project Structure

ToDo/
β”œβ”€β”€ Backend (FastAPI)
β”‚   β”œβ”€β”€ main.py              # Application entry point
β”‚   β”œβ”€β”€ auth.py              # Authentication logic
β”‚   β”œβ”€β”€ config.py            # Configuration
β”‚   β”œβ”€β”€ database.py          # Database connection
β”‚   β”œβ”€β”€ models.py            # SQLAlchemy models
β”‚   β”œβ”€β”€ schemas.py           # Pydantic schemas
β”‚   β”œβ”€β”€ dependencies.py      # FastAPI dependencies
β”‚   β”œβ”€β”€ middleware.py        # Custom middleware
β”‚   └── routers/             # API route handlers
β”‚       β”œβ”€β”€ auth.py          # Auth endpoints
β”‚       β”œβ”€β”€ todos.py         # Todo endpoints
β”‚       └── admin.py         # Admin endpoints
β”‚
β”œβ”€β”€ Frontend (React)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”œβ”€β”€ context/         # React context (auth)
β”‚   β”‚   β”œβ”€β”€ services/        # API client
β”‚   β”‚   └── styles/          # CSS styles
β”‚   β”œβ”€β”€ public/              # Static files
β”‚   └── package.json         # Dependencies
β”‚
β”œβ”€β”€ Deployment
β”‚   β”œβ”€β”€ Dockerfile           # Multi-stage Docker build
β”‚   β”œβ”€β”€ nginx-fullstack.conf # Nginx configuration
β”‚   β”œβ”€β”€ start-fullstack.sh   # Container startup script
β”‚   └── prepare-fullstack-deployment.ps1
β”‚
β”œβ”€β”€ Development
β”‚   β”œβ”€β”€ run.py               # Run backend locally
β”‚   β”œβ”€β”€ start-local.ps1      # Start both services
β”‚   β”œβ”€β”€ docker-compose.yml   # Local Docker setup
β”‚   └── requirements.txt     # Python dependencies
β”‚
└── Documentation
    β”œβ”€β”€ README.md            # This file
    β”œβ”€β”€ QUICK_DEPLOY.md      # Quick AWS deployment guide
    β”œβ”€β”€ FULLSTACK_DEPLOYMENT.md  # Detailed deployment guide
    └── LOCAL_TESTING.md     # Local development guide

πŸš€ Quick Start

Local Development

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • npm or yarn

Option 1: Automatic Start (Recommended)

# Clone the repository
git clone <your-repo-url>
cd ToDo

# Create virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1

# Install Python dependencies
pip install -r requirements.txt

# Start both backend and frontend
.\start-local.ps1

This opens two terminals:

Option 2: Manual Start

Terminal 1 - Backend:

.\venv\Scripts\Activate.ps1
python run.py

Terminal 2 - Frontend:

cd frontend
npm install
npm start

Default Login

Username: admin
Password: admin123

⚠️ Change this in production!

Docker (Local)

# Build and run with Docker Compose
docker-compose up

# Access at http://localhost:8000

☁️ AWS Deployment

Quick Deploy

  1. Prepare package:
.\prepare-fullstack-deployment.ps1
  1. Generate SECRET_KEY:
python -c "import secrets; print(secrets.token_urlsafe(64))"
  1. Upload to AWS:
  1. Set Environment Variables:
SECRET_KEY=<your-generated-key>
DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/dbname
DEBUG=False
  1. Done! Wait 10-15 minutes.

See QUICK_DEPLOY.md for step-by-step instructions.

πŸ“š API Documentation

Interactive API Docs

Key Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Login (get tokens)
  • GET /auth/me - Get current user
  • POST /auth/refresh - Refresh access token

Todos

  • GET /todos/ - List todos
  • POST /todos/ - Create todo
  • GET /todos/{id} - Get todo
  • PUT /todos/{id} - Update todo
  • PATCH /todos/{id}/complete - Toggle complete
  • DELETE /todos/{id} - Delete todo
  • GET /todos/stats/summary - Get statistics

Admin

  • GET /admin/users - List users
  • PUT /admin/users/{id}/role - Update user role
  • DELETE /admin/users/{id} - Delete user

πŸ§ͺ Testing

Run Tests

# Backend tests
pytest

# Frontend tests
cd frontend
npm test

Manual Testing

# Health check
curl http://localhost:8000/health

# Login
curl -X POST http://localhost:8000/auth/login \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=admin&password=admin123"

πŸ”§ Configuration

Environment Variables

Variable Required Default Description
SECRET_KEY Yes - JWT signing key (64+ chars)
DATABASE_URL Yes sqlite+aiosqlite:///./todo.db Database connection string
DEBUG No True Debug mode (set False in prod)
ALGORITHM No HS256 JWT algorithm
ACCESS_TOKEN_EXPIRE_MINUTES No 30 Token expiry
REFRESH_TOKEN_EXPIRE_DAYS No 7 Refresh token expiry

Database

Development (SQLite):

DATABASE_URL=sqlite+aiosqlite:///./todo.db

Production (PostgreSQL):

DATABASE_URL=postgresql+asyncpg://user:password@host:5432/dbname

πŸ”’ Security

  • βœ… Password hashing with bcrypt
  • βœ… JWT token authentication
  • βœ… Role-based access control
  • βœ… Rate limiting (60 req/min)
  • βœ… CORS configuration
  • βœ… SQL injection protection (SQLAlchemy)
  • βœ… XSS protection (React)
  • βœ… Security headers (Nginx)

πŸ“Š Architecture

Development (Separate)

Frontend (React) :3000 β†’ Backend (FastAPI) :8000 β†’ Database

Production (Integrated)

User β†’ Port 8080 (Nginx)
         β”œβ”€ / β†’ React Frontend (SPA)
         └─ /api/* β†’ Backend (Proxy)
                      ↓
                 Uvicorn :8000
                      ↓
                 PostgreSQL

πŸ› οΈ Development

Backend Hot Reload

Backend automatically reloads on file changes when running python run.py.

Frontend Hot Reload

Frontend automatically refreshes on file changes when running npm start.

Adding Dependencies

Backend:

pip install <package>
pip freeze > requirements.txt

Frontend:

cd frontend
npm install <package>

πŸ“ Scripts

Script Purpose
start-local.ps1 Start both backend & frontend
run.py Start backend only
prepare-fullstack-deployment.ps1 Create AWS deployment package
docker-compose up Run with Docker locally

πŸ› Troubleshooting

Port Already in Use

# Find process
netstat -ano | findstr :8000

# Kill process
taskkill /PID <pid> /F

Database Issues

# Delete database and restart
rm todo.db
python run.py

Frontend Can't Connect

  1. Check backend is running on port 8000
  2. Check CORS settings in main.py
  3. Verify API URL in frontend/src/services/api.js

Docker Build Fails

# Clean Docker cache
docker system prune -a

# Rebuild
docker-compose build --no-cache

πŸ“ˆ Scaling

Database

  • Use PostgreSQL in production
  • Enable connection pooling
  • Add database indexes

Caching

  • Add Redis for session storage
  • Cache frequently accessed data
  • Use CDN for static assets

Load Balancing

  • Deploy multiple EB instances
  • Use AWS Application Load Balancer
  • Enable auto-scaling

πŸ“„ License

MIT License - see LICENSE file for details

🀝 Contributing

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

πŸ“ž Support

πŸŽ‰ Acknowledgments

  • FastAPI for the amazing framework
  • React team for the UI library
  • AWS for hosting platform

Built with ❀️ using FastAPI and React

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors