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β
-
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
-
service.py β logic:
from .repository import save_task def create_task(title, description): task = {'title': title, 'description': description} save_task(task) return task
-
repository.py β work with data:
tasks = [] def save_task(task): tasks.append(task)
Function βViewing of list of tasksβ
-
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
-
service.py β logic:
from .repository import get_all_tasks def get_tasks(): return get_all_tasks()
-
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:
-
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"
-
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"
-
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.