How yetone/shorturl works
Main Components
• Backend Service: Built using FastAPI; located in the “backend” directory. It handles API endpoints, business logic (URL creation, redirection, analytics tracking), authentication via JWT, and database interactions using SQLAlchemy. Note the presence of migration scripts (via Alembic) which manage the database schema.
• Frontend Application: A React application developed in TypeScript; located in the “frontend” directory. It provides the user interface for URL management, registration/login, and displays analytics using libraries like Recharts.
• Database: While SQLite is the default configuration (with options for PostgreSQL/MySQL), it’s central to storing URL mappings, user data, and analytics data.
• External Services / Data: The “geodata” directory containing the GeoLite2-City.mmdb suggests that the backend might include geolocation features to enhance analytics by mapping IP addresses to geographical data.
• Docker Setup: The Dockerfile and associated ignore files indicate containerization for deployment.
Relationships and Interactions
• User Interaction Flow: Users interact with the Frontend (React app) to create, manage, and view shortened URLs.
• API Layer: The Frontend communicates with the Backend via REST endpoints (documented in Swagger and ReDoc). This layer handles authentication, URL redirection, and analytics data submission.
• Database Communication: The Backend uses SQLAlchemy to interact with the database (whether SQLite or other SQL databases), and Alembic runs migrations to update the schema.
• Authentication Flow: Secure registration and login are managed by JWT where tokens are issued upon successful authentication.
• Analytics & Geolocation: When a short URL is accessed, the request is processed by the Backend, which tracks click data and employs the GeoLite2 database to resolve geolocation.
• Developer Operations: Docker and configuration files guide deployment and environment setup.
Architectural Patterns and Design Principles
• Separation of Concerns: The project is segmented into a clear Frontend/Backend separation.
• RESTful API Design: The backend design follows REST principles, providing endpoints for URL creation, redirection, and analytics.
• MVC-like Separation within Backend: Even if not explicitly an MVC framework, the file organization into models, schemas, and routers mirrors this pattern.
• Containerization: Use of Docker indicates an isolated, portable, and consistent runtime environment.
Technologies & Frameworks
• Backend: FastAPI, SQLAlchemy, JWT, Alembic for migrations, Python environment configuration files (.env).
• Frontend: React, TypeScript, Tailwind CSS, React Query (for data fetching), Recharts (for visualizing analytics).
• Database: SQLite by default with adaptability for other SQL databases.
• Additional Data Resource: GeoLite2 for geolocation.
• Containerization: Docker for deploying the application.