Vertical architecture of layers (VSA) for beginning users of Cursor: Practical application

Introduction

To me very helped transition to this structure of creation of project, code is written faster, errors less, I wrote short guide for beginners.

Vertical architecture of layers (VSA) for beginning users of Cursor: Practical application

Hello, beginning user of Cursor! In this small article I will tell, how to organize code with help of vertical architecture of layers (VSA) and will show on simple example, how this to apply on practice. VSA helps to make your project understandable and convenient, especially if you only begin to work with code and tools like Cursor.

What is VSA?

VSA β€” this is way to structure code, where all, that connected with one task (for example, creation of record or its viewing), collected in one place. Instead of that to divide code on folders type β€œcontrollers”, β€œservices” and β€œrepositories”, you create separate folder for each function of application.

Why this is needed?

  • Understandability: Easier to understand in code, when all for one task β€” nearby.
  • Simplicity of changes: Need something to fix? You know, where to search.
  • Help from Cursor: AI better understands your code, if it organized by VSA.

Practical example: management of tasks

Let’s create simple application for management of tasks with two functions: creation of task and viewing of list of tasks. I will show, how to organize code and how to use Cursor for simplification of work.

Step 1: Define functions of application

For our example:

  • Creation of task.
  • Viewing of list of tasks.

Step 2: Create structure of project

Instead of classical structure:

src/
  β”œβ”€β”€ controllers/
  β”œβ”€β”€ services/
  └── repositories/

In VSA we organize so:

src/
  β”œβ”€β”€ create-task/         # All for creation of task
  β”‚   β”œβ”€β”€ api.py
  β”‚   β”œβ”€β”€ service.py
  β”‚   └── repository.py
  └── list-tasks/          # All for viewing of tasks
      β”œβ”€β”€ api.py
      β”œβ”€β”€ service.py
      └── repository.py

Step 3: Write code

Function β€œCreation of task”
  1. api.py β€” processing of request:

    from flask import request, jsonify
    from .service import create_task
    
    def create_task_handler():
        data = request.json
        task = create_task(data['title'], data['description'])
        return jsonify(task), 201
    
  2. service.py β€” logic:

    from .repository import save_task
    
    def create_task(title, description):
        task = {'title': title, 'description': description}
        save_task(task)
        return task
    
  3. repository.py β€” work with data:

    tasks = []
    
    def save_task(task):
        tasks.append(task)
    
Function β€œViewing of list of tasks”
  1. api.py β€” processing of request:

    from flask import jsonify
    from .service import get_tasks
    
    def list_tasks_handler():
        tasks = get_tasks()
        return jsonify(tasks), 200
    
  2. service.py β€” logic:

    from .repository import get_all_tasks
    
    def get_tasks():
        return get_all_tasks()
    
  3. repository.py β€” work with data:

    from .repository import tasks
    
    def get_all_tasks():
        return tasks
    

Step 4: Use Cursor

Cursor β€” your AI-helper. Here how it can help:

  1. Creation of code: Ask Cursor to generate basis for new function. For example:

    "Generate structure for function 'deletion of task' in style VSA with files api.py, service.py and repository.py"
    
  2. Improvement of code: If you have old code, ask to redo it under VSA:

    "Reorganize this code in vertical architecture with division on creation and viewing of tasks"
    
  3. Tests: Let Cursor write tests:

    "Write tests for function of creation of task in folder create-task"
    

Tips for beginners

  • Begin with simple: Try VSA on small project.
  • Ask Cursor: Ask AI to help highlight functions of your application.
  • Experiment: Not be afraid to try β€” VSA simplifies life!

Conclusion

Vertical architecture of layers β€” this is simple way to make code organized. With Cursor you will be able faster to write, improve and test code.

2 Likes