This project is a scalable backend system built using Python (FastAPI) with JWT authentication and role-based access control, along with a basic frontend UI to interact with the APIs.
The system allows users to register, log in, and perform CRUD operations on a secondary entity (Tasks) while enforcing proper authorization rules. It is designed with security, modularity, and scalability in mind.
backend/
βββ app/
β βββ main.py
β βββ core/
β β βββ config.py
β β βββ security.py
β β βββ dependencies.py
β βββ models/
β β βββ user.py
β β βββ task.py
β βββ schemas/
β β βββ user.py
β β βββ task.py
β βββ routes/
β β βββ auth.py
β β βββ users.py
β β βββ tasks.py
β βββ db/
β β βββ mongodb.py
β βββ utils/
β β βββ logger.py
β βββ Scalability_Guide.md
βββ Dockerfile
βββ requirements.txt
βββ README.md
docs/
βββ Back-End.md
βββ Front-End.md
βββ DB_Schema.md
frontend/
βββ src/
β βββ api/
β βββ components/
β βββ context/
β βββ pages/
β βββ App.tsx
β βββ main.tsx
βββ package.json
βββ vite.config.ts
βββ Dockerfile
βββ README.md
.github/
βββ workflows/
βββ ci.yml
docker-compose.yml
- User registration & login
- Passwords are hashed using bcrypt
- JWT tokens issued on successful login
- Tokens must be sent in headers:
Authorization: Bearer <token>- USER: Can create and manage own tasks
- ADMIN: Can view and delete any task
{
"id": "Integer (PK)",
"name": "String",
"email": "String (Unique)",
"permission": "String",
"role": "USER / ADMIN",
"hashed_password": "String",
"created_at": "Timestamp"
}
{
"id": "Integer (PK)",
"title": "String",
"description": "String",
"owner_id": "Foreign Key (User)",
"created_at": "Timestamp"
}
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/health | Health check |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/register | Register user |
| POST | /api/v1/auth/login | Login & get JWT |
| Method | Endpoint | Access |
|---|---|---|
| GET | /api/v1/tasks | User |
| POST | /api/v1/tasks | User |
| PUT | /api/v1/tasks/{id} | Owner |
| DELETE | /api/v1/tasks/{id} | Admin |
| GET | /api/v1/tasks | User |
| Method | Endpoint | Access |
|---|---|---|
| GET | /api/v1/users | User |
| POST | /api/v1/users | User |
| PUT | /api/v1/users/{id} | Owner |
| DELETE | /api/v1/users/{id} | Admin |
| GET | /api/v1/users | Admin |
The project includes Dockerfiles for both backend and frontend. Run both services using:
docker-compose up --build
Swagger UI is available at:
https://authdb-832j.onrender.com/docsA Postman collection is also provided for API testing.
- All request bodies validated using Pydantic
- Proper HTTP status codes
- Centralized error handling
- Sanitized inputs to prevent injection attacks
- User registration & login
- JWT-based protected dashboard
- CRUD operations on tasks
- Display API success/error responses
- Simple and functional UI
git clone https://github.com/HackyCoder0951/authdb.git
python -m venv .venv
cd backend
source .venv/bin/activate
pip install -r requirements.txt
# Ensure MongoDB is running locally or set MONGO_URI in .env
uvicorn app.main:app --host 0.0.0.0 --port 8001
cd frontend
npm install
npm run dev- Password hashing (bcrypt)
- JWT expiry & verification
- Role-based access control
- Input validation
- ORM-based database access
- Scalability Guide: A detailed guide (
app/Scalability_Guide.md) is included to assist with understanding microservices, caching (Redis), and load balancing. - Microservices-based architecture (Proposed)
- Redis caching for frequently accessed data (Proposed)
- Load balancing using NGINX (Proposed)
- Advanced Logging: Custom logging utility for better observability.
- Docker containerization
- API rate limiting
For deep dives into specific areas, please refer to the docs/ directory:
- Backend Architecture: Logic flow, Auth, and Task management.
- Frontend Architecture: Component structure and State management.
- Database Schema: ERD diagrams and Collection details.
- Scalability Guide: Scalability and Future Improvements.
Automated testing and build pipelines are implemented using GitHub Actions.
- Config:
.github/workflows/ci.yml - Backend: Runs unit tests and verifies API health.
- Frontend: Installs dependencies and checks build status.
- RESTful API design
- Secure authentication & authorization
- Clean database schema
- Functional frontend integration
- Scalable project structure
- API documentation