Pokodex is a full-stack application that allows users to search for and view details about Pokémon. It consists of three main components: a Laravel backend, a Svelte frontend, and a Python AI service for data scraping.
- Docker and Docker Compose
- Git
-
Clone the repository:
git clone https://github.com/yourusername/pokodex.git cd pokodex -
Build and start the Docker containers:
docker-compose up --build -d -
Connect to database
docker-compose exec db psql -U pokodex_user -d pokedex_ai -
Run migrations and seed the database:
docker-compose exec laravel-backend php artisan migrate docker-compose exec laravel-backend php artisan db:seed -
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000/api
- Python service: http://localhost:8001
-
Larvel clear cache
docker-compose exec laravel-backend php artisan config:clear docker-compose exec laravel-backend php artisan cache:clear
-
Navigate to the Laravel backend directory:
cd laravel-backend-service -
Install PHP dependencies:
docker-compose exec laravel-backend composer install -
Generate application key:
docker-compose exec laravel-backend php artisan key:generate -
Run migrations:
docker-compose exec laravel-backend php artisan migrate -
Seed the database:
docker-compose exec laravel-backend php artisan db:seed
-
Navigate to the Svelte frontend directory:
cd svelte-frontend-service -
Install Node.js dependencies:
docker-compose exec svelte-frontend npm install -
Build the frontend:
docker-compose exec svelte-frontend npm run build
-
Navigate to the Python AI service directory:
cd python-ai-service -
Install Python dependencies:
docker-compose exec python-ai-service pip install -r requirements.txt
After setting up all services, you can use the Pokodex application:
- Open your web browser and go to
http://localhost:3000to access the Svelte frontend. - Use the search functionality to find Pokémon.
- Click on a Pokémon to view its details.
To work on the project in development mode:
-
For the Laravel backend:
docker-compose exec laravel-backend php artisan serve -
For the Svelte frontend:
docker-compose exec svelte-frontend npm run dev -
For the Python AI service:
docker-compose exec python-ai-service python main.py
- If you encounter any issues with database connections, ensure your
.envfile in the Laravel backend is correctly configured. - For permission issues, you may need to run Docker commands with
sudo(on Linux/macOS). - If the Python service fails to scrape data, check your internet connection and ensure the Wikipedia page structure hasn't changed.
pokodex/
├── laravel-backend-service/
│ ├── app/
│ │ ├── Http/
│ │ │ └── Controllers/
│ │ │ └── PokemonController.php
│ │ └── Models/
│ │ ├── Pokemon.php
│ │ └── User.php
│ ├── config/
│ ├── database/
│ │ ├── migrations/
│ │ └── seeders/
│ │ ├── DatabaseSeeder.php
│ │ └── PokemonSeeder.php
│ ├── routes/
│ │ ├── api.php
│ │ └── web.php
│ ├── storage/
│ ├── tests/
│ └── .env
├── svelte-frontend-service/
│ ├── src/
│ │ ├── lib/
│ │ ├── routes/
│ │ └── app.html
│ ├── static/
│ └── svelte.config.js
├── python-ai-service/
│ ├── Scraper/
│ │ ├── __init__.py
│ │ └── wikiScraper.py
│ ├── main.py
│ └── requirements.txt
└── docker-compose.yml
The Laravel backend handles data storage, retrieval, and API endpoints for the Pokémon data.
app/Http/Controllers/PokemonController.php: Handles CRUD operations for Pokémon data.app/Models/Pokemon.php: Defines the Pokemon model.database/migrations/2024_08_13_105302_create_pokemons_table.php: Defines the schema for the Pokémon table.database/seeders/PokemonSeeder.php: Seeds the database with initial Pokémon data.
Defined in routes/api.php:
GET /api/pokemon: Retrieve all PokémonGET /api/pokemon/{id}: Retrieve a specific PokémonPOST /api/pokemon: Create a new PokémonPUT /api/pokemon/{id}: Update a PokémonDELETE /api/pokemon/{id}: Delete a Pokémon
The Svelte frontend provides the user interface for interacting with the Pokodex.
src/routes/+page.svelte: The main page component.src/app.html: The main HTML template.
/: Home page (defined insrc/routes/+page.svelte)
The Python service is responsible for scraping Pokémon data from Wikipedia.
main.py: Defines the FastAPI application and routes.Scraper/wikiScraper.py: Contains the PokemonScraper class for web scraping.
GET /pokemond-data: Retrieves scraped Pokémon data
-
Clone the repository:
git clone <repository-url> cd pokodex -
Set up environment variables:
- Copy
.env.exampleto.envin the Laravel backend and configure database settings.
- Copy
-
Install dependencies:
- For Laravel:
composer install - For Svelte:
npm install - For Python:
pip install -r requirements.txt
- For Laravel:
-
Run migrations and seed the database:
php artisan migrate php artisan db:seed -
Start the services using Docker:
docker-compose up
- Access the Svelte frontend at
http://localhost:3000 - The Laravel API is available at
http://localhost:8000/api - The Python scraping service can be accessed at
http://localhost:8001
The Pokodex application uses a relational database to store Pokémon information. The primary data model is the Pokemon entity, which is defined in the Laravel backend.
The Pokemon model is defined in laravel-backend-service/app/Models/Pokemon.php:
class Pokemon extends Model
{
use HasFactory;
protected $fillable = [
'name',
'type',
'evolves_from',
'evolves_to',
'notes',
];
}The corresponding database schema is defined in the migration file laravel-backend-service/database/migrations/2024_08_13_111842_update_pokemon_table.php:
public function up()
{
Schema::create('pokemon', function (Blueprint $table) {
$table->id();
$table->string('name', 1000);
$table->string('type', 1000)->nullable();
$table->string('evolves_from', 1000)->nullable();
$table->string('evolves_to', 1000)->nullable();
$table->text('notes')->nullable();
$table->timestamps();
});
}id: Unique identifier for each Pokémon (auto-incrementing integer)name: The name of the Pokémon (string, up to 1000 characters)type: The type(s) of the Pokémon (string, up to 1000 characters, nullable)evolves_from: The Pokémon this one evolves from (string, up to 1000 characters, nullable)evolves_to: The Pokémon this one evolves into (string, up to 1000 characters, nullable)notes: Additional notes about the Pokémon (text, nullable)created_atandupdated_at: Timestamps for record creation and last update
The Laravel backend provides the following API endpoints for interacting with the Pokémon data, as defined in laravel-backend-service/app/Http/Controllers/PokemonController.php:
GET /api/pokemon: Retrieve all PokémonGET /api/pokemon/{pokemon}: Retrieve a specific PokémonPOST /api/pokemon: Create a new PokémonPUT /api/pokemon/{pokemon}: Update a PokémonDELETE /api/pokemon/{pokemon}: Delete a Pokémon
index(): Retrieves all Pokémonshow(Pokemon $pokemon): Retrieves a specific Pokémonstore(Request $request): Creates a new Pokémonupdate(Request $request, Pokemon $pokemon): Updates an existing Pokémondestroy(Pokemon $pokemon): Deletes a Pokémon
Each method includes error handling and logging.
-
Data Scraping: The Python AI service (
python-ai-service/Scraper/wikiScraper.py) scrapes Pokémon data from Wikipedia. -
Data Seeding: The scraped data is used to seed the database using the
PokemonSeederclass inlaravel-backend-service/database/seeders/PokemonSeeder.php. -
Data Storage and Retrieval: The Laravel backend handles CRUD operations for Pokémon data through the
PokemonController. -
Frontend Interaction: The Svelte frontend interacts with the Laravel backend API to display and manage Pokémon data.
docker-compose exec laravel-backend php artisan migrate
docker-compose exec laravel-backend php artisan db:seed