How viditagrawal56/url-shortner works
Main Components
• Frontend:
• React app built with TypeScript, Vite, and TailwindCSS.
• Contains components, context providers, and pages such as Home, Login, Register, Dashboard, and Create URL.
• Backend:
• Go server with main entry point in server/cmd/main.go.
• Organized in internal packages which include:
▪ Auth: managing user authentication and JWT logic.
▪ Config: reading environment variables and configuration.
▪ DB: handling PostgreSQL connectivity and using GORM as ORM.
▪ Email: managing email notifications (SMTP service).
▪ Handlers: HTTP endpoints serving client requests.
▪ Models: defining data structures.
▪ URL Shortner: core business logic for creating and managing short URLs.
• Database:
• PostgreSQL database, set up via Docker Compose, hosting the URL shortner’s data.
• External Services:
• SMTP server for sending emails.
• (Implied) External clients/browsers that interact with the frontend.
Relationships and Interactions
• The frontend communicates with the backend through HTTP API endpoints. This is likely facilitated via the Chi router.
• The backend, after processing requests (like creating or retrieving shortened URLs, handling login, etc.), interacts with the PostgreSQL database using GORM.
• Authentication is managed through JWT tokens validated in both the frontend (possibly via protected routes) and verified on the backend.
• The email module triggers notifications via the SMTP service when certain events occur (such as a protected link being accessed).
• A configuration system (likely loaded at startup using Godotenv) ensures that both the backend and the email services function correctly with the required credentials and settings.
Architectural Patterns and Principles
• Separation of Concerns: Clear division between the frontend UI, backend business logic, and persistence (database).
• Modularization: Both frontend and backend have well-organized directory structures grouping related functionalities.
• MVC/Handler Pattern for Backend: Separate modules for models, handlers, and core logic.
• Use of Microservice Components: While this project is monolithic in terms of repository layout, internal modules (for auth, email, urlShortner) are designed to be distinct components handling different parts of the business logic.