How sunvtoan/book-review-website-flask works
Main Components
• Frontend:
– The “templates” directory (HTML files for index, details, login, register, etc.) and “static” folder (CSS, SCSS files) represent the presentation layer built with HTML, CSS, and Jinja templating.
• Backend:
– The main Flask application (application.py) handles routing, authentication (registration, login, logout), API integration, and interactions with external services.
– Scripts like crawl.py (for using Beautiful Soup 4 to crawl Amazon reviews) and import.py (to import CSV data into the database) reside here.
• Database:
– The “tables.sql” file indicates a PostgreSQL database setup.
– CSV files (books.csv, reviews1.csv, bookscopy.csv) are sources for data imported via import.py.
• External Services / APIs:
– Integration with the Open Library API is used to fetch book data (cover images, ratings, etc.).
– The project also interacts with an external website (Amazon) through web scraping to gather additional review data.
• Session Management:
– The “flask_session” folder stores session data, showing that the project uses server-side session management.
• Environment and Deployment:
– Files such as .env, Procfile, and requirements.txt imply considerations for environment configuration and deployment (possibly on platforms like Heroku).
Relationships and Interactions
• Users interact with the frontend (web pages rendered using Jinja) by registering, logging in, searching for books, and submitting reviews.
• These actions trigger HTTP requests to the Flask backend (application.py) where:
– Business logic processes the request.
– For user authentication, the backend handles form submissions and session management.
– For book searches or details, the backend queries the Postgres database (set up using tables.sql) and enriches this data by calling the Open Library API.
– The backend may also run the crawl.py process (or similar functionality) to scrape additional data from external sources when needed.
• Data Import:
– The import.py script is used initially (or periodically) to load book data from CSV files into the PostgreSQL database.
• Data Flow:
– Data flows from external APIs and CSV sources into the database, then from the database to the backend, and finally to the user interface on the frontend.
• Sessions:
– Session management is handled by Flask and stored in the flask_session directory, maintaining user state between requests.
Important Architectural Patterns and Technologies
• MVC (or similar clear separation) – with the “Model” represented by the database and data import scripts, the “View” in the templates/static, and the “Controller” in the Flask routes (application.py) managing the logic.
• Integration of third-party APIs (Open Library API) and web scraping for additional content.
• Use of file-based session management (flask_session), which suggests a design decision to persist session data beyond a single request.
• Technologies: Python (Flask), PostgreSQL, Beautiful Soup for web scraping, and standard web technologies (HTML, CSS, Jinja).