How ndzuma/mywebsiteapi works
Project Type and Purpose
• This is primarily a RESTful backend API written in Go using the Echo framework, augmented by a single static admin UI (web/admin.html).
• Its purpose is to manage portfolio projects stored in a PostgreSQL database, expose CRUD endpoints under /api/projects, and serve a minimal admin panel at /admin.
File Structure
• api/main.go: Application entry-point. Sets up Echo router, middleware (Basic Auth), and route registration.
• internal/handlers/: HTTP handlers for each resource (projects.go). Contains request parsing, response formatting, error handling.
• internal/models/: Domain models/data definitions (project.go).
• internal/database/: Database connection logic (database.go). Encapsulates opening a Postgres connection via env vars.
• pkg/config.go: Configuration loader (reads env vars such as DATABASE_URL, API_USERNAME/PASSWORD, MODE, PORT).
• web/admin.html: Static HTML admin panel for project management UI.
• railway.toml, .nixpacks.toml: Deployment descriptors (Railway hosting, Nixpacks build instructions).
• go.mod, go.sum: Dependency management.
README for Additional Insights
• The README confirms routes, security (Basic Auth), environment variables, deployment on Railway using Nixpacks, and future plans (caching, JWT, rate-limiting, CI/CD).
Main Components & Their Interactions
a. Client Layer
• Browser-based Admin UI (static HTML/JS)
• CLI/Postman or any HTTP client for direct API consumption
b. API Server Layer
• Echo HTTP Server with middleware for Basic Auth and routing
• Configuration module (pkg/config.go)
• Handlers (internal/handlers) invoke business logic and database operations
c. Persistence Layer
• PostgreSQL database (hosted externally; URL injected via DATABASE_URL)
d. Deployment/Infrastructure
• Railway hosting environment
• Nixpacks build pipeline
• Environment variables store secrets and config
Interaction flow:
Client → HTTP (Basic Auth) → Echo Router → Handler → Model → Database → Handler → Response → Client
Architectural Patterns & Design Principles
• Layered Architecture:
• Presentation (static UI)
• API (handlers, routing)
• Domain Models
• Data Access (database package)
• Separation of Concerns: Config module separate from business logic; handlers contain HTTP glue, models define data, database package manages connections.
• 12-Factor App Principles: Environment-based configuration, single codebase, stateless processes.