Skip to content

Architecture

ouma ouma edited this page Jul 30, 2024 · 1 revision

Architecture

Overview

The application is built using a modular architecture, separating concerns into different packages and directories. The main components include the blockchain logic, HTTP handlers, routing, and HTML rendering.

Components

blockchain/

  • Purpose: Contains the core logic for the blockchain implementation.
  • File: blockchain.go - Implements blockchain functionalities such as initialization and data loading.

internals/

  • Purpose: Houses internal packages that include handlers, renders, and routes.
  • Subdirectories:
    • handlers/: Contains HTTP handlers.
      • File: handlers.go - Defines handlers for different HTTP endpoints.
    • renders/: Manages rendering of HTML templates.
      • File: render.go - Contains logic for rendering HTML templates.
    • routes/: Registers and manages HTTP routes.
      • File: routes.go - Defines and registers application routes and middleware.

views/

  • Purpose: Holds static assets (CSS) and HTML templates.
  • Subdirectories:
    • static/: Contains CSS files for styling the web pages.
      • Files: Various CSS files like 400.css, 404.css, 500.css, etc., each providing styles for specific pages.
    • templates/: Contains HTML templates for different pages.
      • Files: Templates like 400.page.html, 404.page.html, 500.page.html, etc., each defining the structure of specific web pages.

web/

  • Purpose: Contains the main application logic and temporary files.
  • Subdirectories:
    • tmp/: Used for temporary files.
    • main.go: The entry point of the application that initializes and starts the server.

Project Root Files

  • .air.toml: Configuration file for the Air live reload tool.
  • .gitignore: Specifies which files and directories to ignore in Git.
  • data.json: JSON file containing initial data for the blockchain.
  • go.mod: Go module file that defines the module path and dependencies.
  • go.sum: Checksums for the dependencies.
  • README.md: Documentation file providing an overview of the project.

Data Flow

  1. Initialization:

    • The blockchain is initialized and data is loaded from data.json.
  2. Request Handling:

    • HTTP requests are routed to appropriate handlers defined in internals/handlers/handlers.go.
  3. Response Generation:

    • Handlers interact with the blockchain logic and render appropriate HTML templates or JSON responses.

Technologies

  • Programming Language: Go
  • Web Framework: net/http
  • Blockchain Library: Custom implementation (github.com/kh3rld/biasharaid/blockchain)

Deployment

  1. Development:

    • Local setup using Go tools and Air for live reloading.
  2. Staging:

    • Deployed on a staging server for testing.
  3. Production:

    • Deployed on a production server with load balancing and scaling mechanisms.

Scalability

  • Horizontal Scaling: Adding more instances of the application behind a load balancer.
  • Vertical Scaling: Enhancing the capabilities of the existing server.

Security

  • Authentication: Bearer token authentication for API endpoints.
  • Authorization: Role-based access control.
  • Data Protection: Encryption of sensitive data at rest and in transit.

Error Handling

  • Logging: Errors are logged with detailed stack traces.
  • Monitoring: Application performance and errors are monitored using tools like Prometheus and Grafana.

Performance

  • Optimization Techniques: Efficient data structures and algorithms ensure fast processing.
  • Benchmarking: Regular performance tests to identify and resolve bottlenecks.