A FastAPI-based REST API for managing anime data, evolved from a simple CRUD application into a structured backend with SQLAlchemy, JWT authentication, API-key authorization, middleware, modular routing, and environment-based configuration.
AnimeDex V4 focuses on practical backend engineering concepts such as REST API design, database management, authentication, authorization, validation, dependency injection, and separation of concerns.
AnimeDex V4 introduces a major backend upgrade over V3:
- π JWT-based user authentication
- π API-key based authorization
- π Secure password hashing with
pwdlib - π‘οΈ JWT + API-key ownership verification for sensitive operations
- π§© Modular routing with FastAPI
APIRouter - β‘ Custom request-timing middleware
- ποΈ SQLAlchemy 2.0 ORM with SQLite
- βοΈ Full and partial anime updates using
PUTandPATCH - βοΈ Environment-based configuration with Pydantic Settings
- β Structured validation and error handling
- Get all anime
- Get anime by ID
- Get a random anime
- Get top 10 highest-rated anime
- Retrieve unique genres
- Retrieve unique studios
- Retrieve unique statuses
- Filter anime by genre, studio, and status
- Create anime
- Fully update anime
- Partially update anime
- Delete anime
- User registration
- Secure password hashing
- User login
- JWT access-token generation
- JWT validation
- Bearer authentication
- Protected endpoints
- Generate API keys for authenticated users
- Cryptographically secure key generation
- Store API-key secrets as hashes
- Validate API keys
- Check API-key status
- Verify API-key ownership
Custom TimerMiddleware measures request processing time and adds the result to the response:
X-Process-Time: 0.00421AnimeDex V4 uses two layers of security for sensitive operations.
After registering and logging in, the client receives a JWT access token.
Authorization: Bearer <access_token>The JWT identifies the authenticated user.
Authenticated users can generate an API key:
POST /api_key/api_keysThe API key is supplied using:
X-API-Key: <api_key>The server validates the key, checks its status, and verifies that it belongs to the authenticated user.
Client Request
β
βΌ
JWT Authentication
β
βΌ
Identify User
β
βΌ
API Key Validation
β
βΌ
Verify Key Ownership
β
βΌ
Perform Operation
This demonstrates the distinction between:
- Authentication β Who are you?
- Authorization β Are you allowed to perform this operation?
AnimeDex V4 supports both full and partial updates.
Used for a full update of an anime resource.
PUT /anime/{id}Used when only specific fields need to be changed.
PATCH /anime/{id}For example:
{
"rating": 9.3,
"status": "Completed"
}This allows partial resource modification without resending the entire anime object.
AnimeDex uses SQLite for persistent storage and SQLAlchemy 2.0 as the ORM.
Key database concepts used:
- SQLAlchemy ORM
Mappedandmapped_column- Database sessions
- Dependency-injected sessions
- CRUD abstraction
- Model relationships
- Enum-based fields
- Persistent SQLite storage
| Technology | Purpose |
|---|---|
| Python | Programming language |
| FastAPI | REST API framework |
| SQLAlchemy 2.0 | ORM |
| SQLite | Database |
| Pydantic | Validation & schemas |
| Pydantic Settings | Configuration |
| pwdlib | Password hashing |
| joserfc | JWT handling |
| Starlette | Middleware |
| Uvicorn | ASGI server |
Anime-Dex/
β
βββ app/
β βββ routers/
β β βββ anime.py # Anime routes
β β βββ user.py # Authentication routes
β β βββ apikey_route.py # API-key routes
β β
β βββ crud.py # Database operations
β βββ database.py # Database configuration
β βββ dependencies.py # Shared dependencies & authentication
β βββ enums.py # Enum definitions
β βββ main.py # FastAPI application
β βββ middleware.py # Request timing middleware
β βββ models.py # SQLAlchemy models
β βββ schemas.py # Pydantic schemas
β βββ config.py # Application configuration
β βββ utils.py # Authentication utilities
β
βββ seed.py
βββ requirements.txt
βββ README.md
βββ .gitignore
βββ LICENSE
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
API home |
| Method | Endpoint | Auth |
|---|---|---|
| GET | /anime/ |
β |
| GET | /anime/{id} |
β |
| GET | /anime/random |
β |
| GET | /anime/top10 |
β |
| GET | /anime/genres |
β |
| GET | /anime/studios |
β |
| GET | /anime/statuses |
β |
| POST | /anime/ |
JWT |
| PUT | /anime/{id} |
JWT |
| PATCH | /anime/{id} |
JWT + API Key |
| DELETE | /anime/{id} |
JWT + API Key |
| Method | Endpoint | Description |
|---|---|---|
| POST | /user/register |
Register a user |
| POST | /user/login |
Login and receive JWT |
| Method | Endpoint | Auth |
|---|---|---|
| POST | /api_key/api_keys |
JWT |
Anime can be filtered using query parameters:
GET /anime/?genre=ActionGET /anime/?studio=MadhouseGET /anime/?status=CompletedMultiple filters can be combined:
GET /anime/?genre=Action&studio=MAPPA&status=Completed{
"title": "Monster",
"genre": "Thriller",
"episodes": 74,
"rating": 9.2,
"studio": "Madhouse",
"release_year": 2004,
"status": "Completed"
}git clone https://github.com/Pranavkr323/Anime-Dex.git
cd Anime-Dexpython -m venv venvWindows
venv\Scripts\activatemacOS / Linux
source venv/bin/activatepip install -r requirements.txtCreate a .env file with the required application configuration.
Do not commit secrets such as JWT signing keys to the repository.
uvicorn app.main:app --reloadThe API will be available at:
http://127.0.0.1:8000
FastAPI automatically provides interactive documentation.
Interactive API documentation generated automatically by FastAPI.
Protected endpoints require JWT authentication along with a valid API key where applicable.
http://127.0.0.1:8000/docs
http://127.0.0.1:8000/redoc
Swagger UI can be used to explore endpoints, inspect schemas, authenticate with JWT, provide API keys, and test protected operations.
- REST API design
- FastAPI application structure
- APIRouter
- Dependency injection
- Middleware
- Request/response handling
- HTTP status codes
- Exception handling
- SQLAlchemy 2.0
- ORM-based database operations
- SQLite
- Database sessions
- CRUD abstraction
- Model relationships
- Password hashing
- JWT authentication
- Bearer authentication
- Token validation
- API-key generation
- API-key hashing
- API-key verification
- Ownership-based authorization
- Authentication vs authorization
- Query parameter filtering
- PUT vs PATCH
- Pydantic schemas
- Validation
- Separation of concerns
- Modular backend architecture
Potential areas for the next version:
- Automated testing with Pytest
- Database migrations with Alembic
- PostgreSQL support
- Pagination
- Async SQLAlchemy
- Dockerization
- CI/CD
- API rate limiting
- Logging & monitoring
- Production deployment
- Anime watchlists & favorites
This project is licensed under the MIT License.
Pranav Kumar
Backend Developer β’ Python β’ FastAPI β’ SQLAlchemy
- GitHub: https://github.com/Pranavkr323
- LinkedIn: https://www.linkedin.com/in/pranavkr323/
If you found AnimeDex useful or interesting, consider giving the repository a β.


